@moxo/cli 0.0.0-stage → 0.1.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/CHANGELOG.md +19 -0
- package/LICENSE +201 -0
- package/README.md +61 -2
- package/dist/args.d.ts +25 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +71 -0
- package/dist/args.js.map +1 -0
- package/dist/catalog.d.ts +30 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +33 -0
- package/dist/catalog.js.map +1 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/api.d.ts +18 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +84 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/auth.d.ts +16 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +173 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/generated.d.ts +31 -0
- package/dist/commands/generated.d.ts.map +1 -0
- package/dist/commands/generated.js +147 -0
- package/dist/commands/generated.js.map +1 -0
- package/dist/commands/help.d.ts +34 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +117 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/templates.d.ts +59 -0
- package/dist/commands/templates.d.ts.map +1 -0
- package/dist/commands/templates.js +388 -0
- package/dist/commands/templates.js.map +1 -0
- package/dist/config.d.ts +63 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +104 -0
- package/dist/config.js.map +1 -0
- package/dist/confirm.d.ts +11 -0
- package/dist/confirm.d.ts.map +1 -0
- package/dist/confirm.js +21 -0
- package/dist/confirm.js.map +1 -0
- package/dist/context.d.ts +53 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +129 -0
- package/dist/context.js.map +1 -0
- package/dist/credentials.d.ts +50 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +148 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +61 -0
- package/dist/errors.js.map +1 -0
- package/dist/fields.d.ts +49 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +280 -0
- package/dist/fields.js.map +1 -0
- package/dist/main.d.ts +20 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +189 -0
- package/dist/main.js.map +1 -0
- package/dist/oauth.d.ts +62 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +156 -0
- package/dist/oauth.js.map +1 -0
- package/dist/render.d.ts +10 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +46 -0
- package/dist/render.js.map +1 -0
- package/dist/session.d.ts +91 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +235 -0
- package/dist/session.js.map +1 -0
- package/dist/spec.d.ts +72 -0
- package/dist/spec.d.ts.map +1 -0
- package/dist/spec.js +171 -0
- package/dist/spec.js.map +1 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/npm-shrinkwrap.json +3868 -0
- package/package.json +46 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@moxo/cli` are documented here.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
7
|
+
once it reaches `1.0.0`. Pre-1.0 releases can introduce breaking changes
|
|
8
|
+
between any minor version. Commands built from the API description change
|
|
9
|
+
with the API; see the API changelog for those.
|
|
10
|
+
|
|
11
|
+
## [0.1.0] — Unreleased
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `moxo login` (browser sign-in with a one-time code, or `--token` on standard input), `logout`, `whoami`, `--profile` for one sign-in per organization, and `--region us|eu|au|sg`. `MOXO_TOKEN` and `MOXO_HOST` for CI. A saved sign-in is used only on the host it was made for.
|
|
16
|
+
- `moxo templates pull | plan | push | export | import`: a template as a YAML file in a repository. A push from a stale file is refused with exit code 2; after a push the file is the draft as Moxo now has it, to commit back. A folder is pushed file by file with a line for each.
|
|
17
|
+
- Every other public API operation as a command, built from the API description at run time and cached for offline use. A call that sends messages to people asks first, or needs `--yes`. `--field key=value` builds a request body, `--role vendor=pat@acme.example` puts a person on a role when a flow starts, and `--form name=@file` uploads a file.
|
|
18
|
+
- `moxo api`, `moxo search`, `moxo help --json`, and `--json` on every command.
|
|
19
|
+
- Exit codes: 0 done, 1 refused (including a call that needs `--yes`), 2 changed since you pulled, 3 sign in again.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, license, patent, trademark,
|
|
102
|
+
and attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may accept and charge a fee for,
|
|
167
|
+
acceptance of support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However, in
|
|
169
|
+
accepting such obligations, You may act only on Your own behalf and
|
|
170
|
+
on Your sole responsibility, not on behalf of any other Contributor,
|
|
171
|
+
and only if You agree to indemnify, defend, and hold each Contributor
|
|
172
|
+
harmless for any liability incurred by, or claims asserted against,
|
|
173
|
+
such Contributor by reason of your accepting any such warranty or
|
|
174
|
+
additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Moxo Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @moxo/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Moxo command line. Keep templates as YAML files in your repository: pull them, see what an edit changes, and push them from your terminal or CI. Every other Moxo API operation is a command too.
|
|
4
|
+
|
|
5
|
+
Full guide: https://developers.moxo.com/docs/guides/moxo-cli
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Node.js 20 or later.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install -g @moxo/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or run it with `npx @moxo/cli <command>`.
|
|
16
|
+
|
|
17
|
+
## Sign in
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
moxo login # in the browser, with a one-time code
|
|
21
|
+
moxo login --region eu # your region's Moxo: us (default), eu, au or sg
|
|
22
|
+
moxo login --token < token.txt # with a personal access token
|
|
23
|
+
moxo whoami
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
In CI, set `MOXO_TOKEN` to a personal access token saved as a secret. The CLI never takes a token on the command line, never prints one, and sends a saved one only to the Moxo it was made for.
|
|
27
|
+
|
|
28
|
+
## The template loop
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
moxo templates pull tpl_123 # the draft as vendor_onboarding.template.yaml
|
|
32
|
+
moxo templates plan vendor_onboarding.template.yaml # what it changes, every check, nothing saved
|
|
33
|
+
moxo templates push vendor_onboarding.template.yaml # save to the draft
|
|
34
|
+
moxo templates publish tpl_123
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
After a push the file is the draft as Moxo now has it, at the new revision: commit it (in CI, commit it back to `main`). A push from a file pulled before someone else changed the template is refused with exit code 2: pull again, make your change in that file, then push.
|
|
38
|
+
|
|
39
|
+
## Everything else
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
moxo search "start a flow"
|
|
43
|
+
moxo flows start tpl_123 --role vendor=pat@acme.example --field name=Acme --yes
|
|
44
|
+
moxo steps mine --json
|
|
45
|
+
moxo api GET /v1/flows --field status=active
|
|
46
|
+
moxo help --json
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
These commands are built from Moxo's API description each time the CLI runs, so a new API feature is a command the day it ships. A call that sends messages to people asks first; with no terminal, it needs `--yes`.
|
|
50
|
+
|
|
51
|
+
## Exit codes
|
|
52
|
+
|
|
53
|
+
| Code | Meaning |
|
|
54
|
+
|---|---|
|
|
55
|
+
| 0 | Done. |
|
|
56
|
+
| 1 | Refused: Moxo refused the call, a check failed, the command was wrong, or a call that sends messages to people had no yes (pass `--yes`). The message says which. |
|
|
57
|
+
| 2 | Changed since you pulled: pull again, make your change, then push. |
|
|
58
|
+
| 3 | Sign in again: run `moxo login`, or set `MOXO_TOKEN`. |
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
Apache-2.0
|
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a command line: `--name value`, `--name=value`, `-o value`, a flag
|
|
3
|
+
* given more than once (`--field a=1 --field b=2`), and `--` to stop reading
|
|
4
|
+
* flags. Which flags take no value is said by the command, since generated
|
|
5
|
+
* commands learn their flags from the API description.
|
|
6
|
+
*/
|
|
7
|
+
export interface Parsed {
|
|
8
|
+
positionals: string[];
|
|
9
|
+
/** Every value of every flag that takes one, in order. */
|
|
10
|
+
values: Map<string, string[]>;
|
|
11
|
+
/** The flags that take no value and were given. */
|
|
12
|
+
switches: Set<string>;
|
|
13
|
+
}
|
|
14
|
+
export interface FlagSpec {
|
|
15
|
+
/** Flags that take no value. */
|
|
16
|
+
switches?: readonly string[];
|
|
17
|
+
/** Short names: `o` → `output`. */
|
|
18
|
+
aliases?: Readonly<Record<string, string>>;
|
|
19
|
+
}
|
|
20
|
+
export declare function parseArgs(tokens: readonly string[], spec?: FlagSpec): Parsed;
|
|
21
|
+
/** The one value of a flag, or undefined; a flag given twice is a mistake. */
|
|
22
|
+
export declare function single(p: Parsed, name: string): string | undefined;
|
|
23
|
+
/** Refuses a flag the command does not take, naming the ones it does. */
|
|
24
|
+
export declare function onlyFlags(p: Parsed, allowed: readonly string[], usage: string): void;
|
|
25
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,MAAM;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,0DAA0D;IAC1D,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9B,mDAAmD;IACnD,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACvB,gCAAgC;IAChC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,mCAAmC;IACnC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC5C;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,GAAE,QAAa,GAAG,MAAM,CAwChF;AAED,8EAA8E;AAC9E,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKlE;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAKpF"}
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a command line: `--name value`, `--name=value`, `-o value`, a flag
|
|
3
|
+
* given more than once (`--field a=1 --field b=2`), and `--` to stop reading
|
|
4
|
+
* flags. Which flags take no value is said by the command, since generated
|
|
5
|
+
* commands learn their flags from the API description.
|
|
6
|
+
*/
|
|
7
|
+
import { usageError } from './errors.js';
|
|
8
|
+
export function parseArgs(tokens, spec = {}) {
|
|
9
|
+
const switches = new Set(spec.switches ?? []);
|
|
10
|
+
const out = { positionals: [], values: new Map(), switches: new Set() };
|
|
11
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
12
|
+
const t = tokens[i];
|
|
13
|
+
if (t === '--') {
|
|
14
|
+
out.positionals.push(...tokens.slice(i + 1));
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
if (!t.startsWith('-') || t === '-') {
|
|
18
|
+
out.positionals.push(t);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const long = t.startsWith('--');
|
|
22
|
+
const body = long ? t.slice(2) : t.slice(1);
|
|
23
|
+
const eq = body.indexOf('=');
|
|
24
|
+
const rawName = eq >= 0 ? body.slice(0, eq) : body;
|
|
25
|
+
const name = long ? rawName : (spec.aliases?.[rawName] ?? rawName);
|
|
26
|
+
if (name.length === 0)
|
|
27
|
+
throw usageError(`"${t}" is not a flag.`);
|
|
28
|
+
if (switches.has(name)) {
|
|
29
|
+
if (eq >= 0) {
|
|
30
|
+
const v = body.slice(eq + 1);
|
|
31
|
+
if (v === 'false')
|
|
32
|
+
continue;
|
|
33
|
+
if (v !== 'true')
|
|
34
|
+
throw usageError(`--${name} takes no value.`);
|
|
35
|
+
}
|
|
36
|
+
out.switches.add(name);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
let value;
|
|
40
|
+
if (eq >= 0)
|
|
41
|
+
value = body.slice(eq + 1);
|
|
42
|
+
else {
|
|
43
|
+
value = tokens[i + 1];
|
|
44
|
+
if (value === undefined)
|
|
45
|
+
throw usageError(`--${name} needs a value.`);
|
|
46
|
+
i++;
|
|
47
|
+
}
|
|
48
|
+
const list = out.values.get(name) ?? [];
|
|
49
|
+
list.push(value);
|
|
50
|
+
out.values.set(name, list);
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
/** The one value of a flag, or undefined; a flag given twice is a mistake. */
|
|
55
|
+
export function single(p, name) {
|
|
56
|
+
const v = p.values.get(name);
|
|
57
|
+
if (!v)
|
|
58
|
+
return undefined;
|
|
59
|
+
if (v.length > 1)
|
|
60
|
+
throw usageError(`--${name} is given more than once.`);
|
|
61
|
+
return v[0];
|
|
62
|
+
}
|
|
63
|
+
/** Refuses a flag the command does not take, naming the ones it does. */
|
|
64
|
+
export function onlyFlags(p, allowed, usage) {
|
|
65
|
+
const ok = new Set(allowed);
|
|
66
|
+
for (const name of [...p.values.keys(), ...p.switches]) {
|
|
67
|
+
if (!ok.has(name))
|
|
68
|
+
throw usageError(`Unknown flag --${name}.`, usage);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=args.js.map
|
package/dist/args.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAiBzC,MAAM,UAAU,SAAS,CAAC,MAAyB,EAAE,OAAiB,EAAE;IACtE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IAC9C,MAAM,GAAG,GAAW,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;IAChF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAE,CAAC;QACrB,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACf,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC7C,MAAM;QACR,CAAC;QACD,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;YACpC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACxB,SAAS;QACX,CAAC;QACD,MAAM,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,IAAI,GAAG,IAAI,CAA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AK,IAAI,iBAAiB,CAAC,CAAC;YACtE,CAAC,EAAE,CAAC;QACN,CAAC;QACD,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,IAAY;IAC5C,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,UAAU,CAAC,KAAK,IAAI,2BAA2B,CAAC,CAAC;IACzE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AACd,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,SAAS,CAAC,CAAS,EAAE,OAA0B,EAAE,KAAa;IAC5E,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvD,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,UAAU,CAAC,kBAAkB,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;IACxE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hand-written commands, as help, search and `help --json` list them.
|
|
3
|
+
* Everything else is generated from the API description (commands/generated.ts).
|
|
4
|
+
*/
|
|
5
|
+
export interface HandWritten {
|
|
6
|
+
words: string[];
|
|
7
|
+
usage: string;
|
|
8
|
+
summary: string;
|
|
9
|
+
/** The API operations it runs, as `METHOD /v1/path`. */
|
|
10
|
+
runs?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* The operations this is THE command for, and how it is written with its
|
|
13
|
+
* argument (MCP results name it). Held, with the generated commands, to the
|
|
14
|
+
* backend's golden list (backend/tests/api-docs/operation-ids-cli-commands.golden.json).
|
|
15
|
+
*/
|
|
16
|
+
commandFor?: {
|
|
17
|
+
operations: string[];
|
|
18
|
+
command: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare const HAND_WRITTEN: readonly HandWritten[];
|
|
22
|
+
export declare const GLOBAL_FLAGS: ReadonlyArray<{
|
|
23
|
+
flag: string;
|
|
24
|
+
summary: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const EXIT_CODES: ReadonlyArray<{
|
|
27
|
+
code: number;
|
|
28
|
+
meaning: string;
|
|
29
|
+
}>;
|
|
30
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACxD;AAED,eAAO,MAAM,YAAY,EAAE,SAAS,WAAW,EAY9C,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAMzE,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAKvE,CAAC"}
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hand-written commands, as help, search and `help --json` list them.
|
|
3
|
+
* Everything else is generated from the API description (commands/generated.ts).
|
|
4
|
+
*/
|
|
5
|
+
import { API_USAGE } from './commands/api.js';
|
|
6
|
+
import { LOGIN_USAGE } from './commands/auth.js';
|
|
7
|
+
export const HAND_WRITTEN = [
|
|
8
|
+
{ words: ['login'], usage: LOGIN_USAGE, summary: 'Sign in: in the browser with a one-time code, or with a personal access token on standard input.' },
|
|
9
|
+
{ words: ['logout'], usage: 'moxo logout [--profile <name>]', summary: 'Sign out of a profile and delete its token from this machine.' },
|
|
10
|
+
{ words: ['whoami'], usage: 'moxo whoami [--profile <name>]', summary: 'Who you are signed in as, in which organization, and where the token comes from.', runs: ['GET /v1/users/me', 'GET /v1/organization'] },
|
|
11
|
+
{ words: ['templates', 'pull'], usage: 'moxo templates pull <templateId> [-o <file> | -o -]', summary: 'Save a template\'s draft as a YAML file. Changes nothing in Moxo.', runs: ['GET /v1/templates/{id}/file'], commandFor: { operations: ['GET /v1/templates/{id}/file'], command: 'moxo templates pull <id>' } },
|
|
12
|
+
{ words: ['templates', 'plan'], usage: 'moxo templates plan <file|folder>... [--template <id>]', summary: 'Show the changes a file makes to the draft and run every check, saving nothing. Also: templates diff.', runs: ['PUT /v1/templates/{id}/file'] },
|
|
13
|
+
{ words: ['templates', 'push'], usage: 'moxo templates push <file|folder>... [--template <id>] [--overwrite] [--create]', summary: 'Save a file\'s changes to the template\'s draft. Refused (exit 2) when the template changed since the file was pulled.', runs: ['PUT /v1/templates/{id}/file', 'POST /v1/templates'], commandFor: { operations: ['PUT /v1/templates/{id}/file'], command: 'moxo templates push <file>' } },
|
|
14
|
+
{ words: ['templates', 'export'], usage: 'moxo templates export <templateId> [-o <file>] [--bundle]', summary: 'Download a template as an encrypted .moxo file (--bundle: a .moxo-bundle with its AI agents) to move it to another organization.', runs: ['GET /v1/templates/{id}/export'], commandFor: { operations: ['GET /v1/templates/{id}/export'], command: 'moxo templates export <id>' } },
|
|
15
|
+
{ words: ['templates', 'import'], usage: 'moxo templates import <file> [--folder <folderId>]', summary: 'Make a new draft template from an exported .moxo or .moxo-bundle file.', runs: ['POST /v1/templates/import-init', 'POST /v1/templates/import'], commandFor: { operations: ['POST /v1/templates/import'], command: 'moxo templates import <file>' } },
|
|
16
|
+
{ words: ['api'], usage: API_USAGE, summary: 'Make any /v1 call and print Moxo\'s answer as it is.' },
|
|
17
|
+
{ words: ['search'], usage: 'moxo search <what you want to do>', summary: 'Find the command for a task among every API operation.' },
|
|
18
|
+
{ words: ['help'], usage: 'moxo help [<command>] [--json]', summary: 'Every command, or one command\'s arguments. --json lists them for an agent.' },
|
|
19
|
+
];
|
|
20
|
+
export const GLOBAL_FLAGS = [
|
|
21
|
+
{ flag: '--json', summary: 'Print the answer as JSON on standard output, and nothing else there.' },
|
|
22
|
+
{ flag: '--profile <name>', summary: 'Use another sign-in (one organization each). Also MOXO_PROFILE.' },
|
|
23
|
+
{ flag: '--yes', summary: 'Go ahead with a call that sends messages to people without asking.' },
|
|
24
|
+
{ flag: '--region <us|eu|au|sg>', summary: 'Sign in to a region\'s Moxo (default us, https://api.moxo.com).' },
|
|
25
|
+
{ flag: '--host <address>', summary: 'The Moxo API address, instead of --region. Also MOXO_HOST. A saved sign-in is used only on the host it was made for.' },
|
|
26
|
+
];
|
|
27
|
+
export const EXIT_CODES = [
|
|
28
|
+
{ code: 0, meaning: 'Done.' },
|
|
29
|
+
{ code: 1, meaning: 'Refused: Moxo refused the call, a check failed, the command was wrong, or a call that sends messages to people had no yes (pass --yes). The message says which.' },
|
|
30
|
+
{ code: 2, meaning: 'Changed since you pulled: pull again, make your change in that file, then push.' },
|
|
31
|
+
{ code: 3, meaning: 'Sign in again: run moxo login, or set MOXO_TOKEN.' },
|
|
32
|
+
];
|
|
33
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAgBjD,MAAM,CAAC,MAAM,YAAY,GAA2B;IAClD,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,kGAAkG,EAAE;IACrJ,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,gCAAgC,EAAE,OAAO,EAAE,+DAA+D,EAAE;IACxI,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,gCAAgC,EAAE,OAAO,EAAE,kFAAkF,EAAE,IAAI,EAAE,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,EAAE;IAC/M,EAAE,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,qDAAqD,EAAE,OAAO,EAAE,mEAAmE,EAAE,IAAI,EAAE,CAAC,6BAA6B,CAAC,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,6BAA6B,CAAC,EAAE,OAAO,EAAE,0BAA0B,EAAE,EAAE;IACrT,EAAE,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,wDAAwD,EAAE,OAAO,EAAE,uGAAuG,EAAE,IAAI,EAAE,CAAC,6BAA6B,CAAC,EAAE;IAC1P,EAAE,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,iFAAiF,EAAE,OAAO,EAAE,wHAAwH,EAAE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O,EAAE,iEAAiE,EAAE;IAC9G,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,sHAAsH,EAAE;CAC9J,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAqD;IAC1E,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;IAC7B,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,iKAAiK,EAAE;IACvL,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,iFAAiF,EAAE;IACvG,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,mDAAmD,EAAE;CAC1E,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;GAIG"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @moxo/cli: the `moxo` command.
|
|
4
|
+
*
|
|
5
|
+
* Node 20 or later: the CLI uses Node's own fetch and nothing else at run time.
|
|
6
|
+
*/
|
|
7
|
+
import { main } from './main.js';
|
|
8
|
+
import { processContext } from './context.js';
|
|
9
|
+
const major = Number(process.versions.node.split('.')[0]);
|
|
10
|
+
if (major < 20) {
|
|
11
|
+
process.stderr.write(`moxo needs Node.js 20 or later; this is ${process.versions.node}.\n`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
process.exitCode = await main(process.argv.slice(2), processContext());
|
|
15
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;IACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2CAA2C,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC;IAC5F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* moxo api <METHOD> <path>: any /v1 call, as `gh api` makes any GitHub call.
|
|
3
|
+
*
|
|
4
|
+
* moxo api GET /v1/flows --field status=active --field limit=5
|
|
5
|
+
* moxo api POST /v1/templates/tpl_1/check
|
|
6
|
+
* moxo api PUT /v1/templates/tpl_1/file --input push.json
|
|
7
|
+
*
|
|
8
|
+
* On a GET, and on a DELETE that takes no body, --field adds query
|
|
9
|
+
* parameters; otherwise it builds the JSON body (the API description says
|
|
10
|
+
* which). --form sends a file upload (multipart). The answer is printed as
|
|
11
|
+
* Moxo sent it. A call the API description marks as sending messages to
|
|
12
|
+
* people asks first, as its generated command does.
|
|
13
|
+
*/
|
|
14
|
+
import type { Context, Output } from '../context.js';
|
|
15
|
+
import { type GlobalOptions } from '../session.js';
|
|
16
|
+
export declare const API_USAGE = "moxo api <GET|POST|PUT|PATCH|DELETE> </v1/path> [--field key=value]... [--input <file>|-] [--form name=value|name=@file]... [-o <file>] [--yes]";
|
|
17
|
+
export declare function apiCommand(ctx: Context, out: Output, globals: GlobalOptions, args: string[]): Promise<number>;
|
|
18
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/commands/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,EAA4C,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAG7F,eAAO,MAAM,SAAS,oJAAoJ,CAAC;AAI3K,wBAAsB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAgDnH"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* moxo api <METHOD> <path>: any /v1 call, as `gh api` makes any GitHub call.
|
|
3
|
+
*
|
|
4
|
+
* moxo api GET /v1/flows --field status=active --field limit=5
|
|
5
|
+
* moxo api POST /v1/templates/tpl_1/check
|
|
6
|
+
* moxo api PUT /v1/templates/tpl_1/file --input push.json
|
|
7
|
+
*
|
|
8
|
+
* On a GET, and on a DELETE that takes no body, --field adds query
|
|
9
|
+
* parameters; otherwise it builds the JSON body (the API description says
|
|
10
|
+
* which). --form sends a file upload (multipart). The answer is printed as
|
|
11
|
+
* Moxo sent it. A call the API description marks as sending messages to
|
|
12
|
+
* people asks first, as its generated command does.
|
|
13
|
+
*/
|
|
14
|
+
import { writeFileSync } from 'node:fs';
|
|
15
|
+
import { resolve } from 'node:path';
|
|
16
|
+
import { onlyFlags, parseArgs, single } from '../args.js';
|
|
17
|
+
import { confirmSending } from '../confirm.js';
|
|
18
|
+
import { EXIT, exitForRefusal, usageError } from '../errors.js';
|
|
19
|
+
import { buildBody, buildForm, fieldsAsQuery } from '../fields.js';
|
|
20
|
+
import { ApiClient, announceWrite, resolveSession } from '../session.js';
|
|
21
|
+
import { loadDocument, operationForRequest, operationsOf } from '../spec.js';
|
|
22
|
+
export const API_USAGE = 'moxo api <GET|POST|PUT|PATCH|DELETE> </v1/path> [--field key=value]... [--input <file>|-] [--form name=value|name=@file]... [-o <file>] [--yes]';
|
|
23
|
+
const METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
|
|
24
|
+
export async function apiCommand(ctx, out, globals, args) {
|
|
25
|
+
const p = parseArgs(args, { aliases: { o: 'output' } });
|
|
26
|
+
onlyFlags(p, ['field', 'input', 'output', 'form'], API_USAGE);
|
|
27
|
+
const [rawMethod, rawPath, extra] = p.positionals;
|
|
28
|
+
if (!rawMethod || !rawPath || extra)
|
|
29
|
+
throw usageError('Give a method and a path.', API_USAGE);
|
|
30
|
+
const method = rawMethod.toUpperCase();
|
|
31
|
+
if (!METHODS.has(method))
|
|
32
|
+
throw usageError(`${rawMethod} is not one of GET, POST, PUT, PATCH, DELETE.`, API_USAGE);
|
|
33
|
+
const path = rawPath.startsWith('/v1/') ? rawPath : `/v1/${rawPath.replace(/^\/+/, '')}`;
|
|
34
|
+
if (/^[a-z]+:\/\//i.test(rawPath))
|
|
35
|
+
throw usageError('Give the path only (/v1/...): the host comes from your sign-in.', API_USAGE);
|
|
36
|
+
const fields = p.values.get('field') ?? [];
|
|
37
|
+
const forms = p.values.get('form');
|
|
38
|
+
if (method === 'GET' && (p.values.has('input') || forms))
|
|
39
|
+
throw usageError('A GET takes no body: use --field for its query parameters.', API_USAGE);
|
|
40
|
+
if (forms && (p.values.has('input') || fields.length > 0))
|
|
41
|
+
throw usageError('Give --form or --field, not both.', API_USAGE);
|
|
42
|
+
const session = await resolveSession(ctx, out, globals);
|
|
43
|
+
const client = new ApiClient(ctx, session);
|
|
44
|
+
let body;
|
|
45
|
+
let form;
|
|
46
|
+
// A DELETE takes a JSON body only where its operation says so (deleting a persona names who takes over).
|
|
47
|
+
let asQuery = method === 'GET';
|
|
48
|
+
if (method !== 'GET') {
|
|
49
|
+
const { document } = await loadDocument(ctx, session.host);
|
|
50
|
+
const op = operationForRequest(operationsOf(document), method, path);
|
|
51
|
+
asQuery = method === 'DELETE' && !op?.jsonBody && !forms;
|
|
52
|
+
if (asQuery && p.values.has('input'))
|
|
53
|
+
throw usageError('This DELETE takes no body: use --field for its query parameters.', API_USAGE);
|
|
54
|
+
if (forms)
|
|
55
|
+
form = buildForm(forms, ctx.cwd);
|
|
56
|
+
else if (!asQuery)
|
|
57
|
+
body = await buildBody(document, op?.jsonBody, { fields, input: single(p, 'input'), readStdin: () => ctx.terminal.readAll(), cwd: ctx.cwd });
|
|
58
|
+
if (op?.sendsMessages)
|
|
59
|
+
await confirmSending(ctx, out, `${op.summary}: ${method} ${path}.`, globals.yes);
|
|
60
|
+
await announceWrite(client, out);
|
|
61
|
+
}
|
|
62
|
+
const res = await client.request(method, path, {
|
|
63
|
+
...(asQuery ? { query: fieldsAsQuery(fields) } : {}),
|
|
64
|
+
...(form ? { form } : body !== undefined ? { body } : method !== 'GET' && !asQuery ? { body: {} } : {}),
|
|
65
|
+
});
|
|
66
|
+
if (res.bytes !== undefined) {
|
|
67
|
+
const target = single(p, 'output');
|
|
68
|
+
if (target && target !== '-')
|
|
69
|
+
writeFileSync(resolve(ctx.cwd, target), res.bytes);
|
|
70
|
+
else
|
|
71
|
+
ctx.stdout(res.bytes);
|
|
72
|
+
}
|
|
73
|
+
else if (res.json !== undefined) {
|
|
74
|
+
out.json(res.json);
|
|
75
|
+
}
|
|
76
|
+
if (res.status >= 400) {
|
|
77
|
+
const code = res.json?.error?.code;
|
|
78
|
+
if (!globals.json)
|
|
79
|
+
out.err(`Moxo answered ${res.status}${code ? ` ${code}` : ''}.`);
|
|
80
|
+
return exitForRefusal(res.status, code);
|
|
81
|
+
}
|
|
82
|
+
return EXIT.OK;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/commands/api.ts"],"names":[],"m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