@manyoars/oars 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/LICENSE +202 -0
- package/dist/api.d.ts +22 -0
- package/dist/api.js +31 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +30 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +24 -0
- package/dist/cli.d.ts +29 -0
- package/dist/cli.js +169 -0
- package/dist/commands/deploy-input.d.ts +35 -0
- package/dist/commands/deploy-input.js +107 -0
- package/dist/commands/deploy.d.ts +22 -0
- package/dist/commands/deploy.js +120 -0
- package/dist/commands/login.d.ts +10 -0
- package/dist/commands/login.js +35 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.js +17 -0
- package/dist/commands/status.d.ts +7 -0
- package/dist/commands/status.js +18 -0
- package/dist/commands/test-charge.d.ts +11 -0
- package/dist/commands/test-charge.js +34 -0
- package/dist/credentials.d.ts +28 -0
- package/dist/credentials.js +73 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.js +73 -0
- package/dist/journal.d.ts +26 -0
- package/dist/journal.js +58 -0
- package/dist/oidc.d.ts +26 -0
- package/dist/oidc.js +137 -0
- package/dist/retry.d.ts +11 -0
- package/dist/retry.js +40 -0
- package/dist/session.d.ts +12 -0
- package/dist/session.js +41 -0
- package/package.json +41 -4
- package/parity/deploy-plans/paid-api.json +34 -0
- package/parity/deploy-plans/per-task-agent.json +34 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Switchyard Software Company
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type OarsClient } from '@manyoars/oars-client';
|
|
2
|
+
import type { RunDeps } from './cli.js';
|
|
3
|
+
/** `--api-url`, else `OARS_API_URL`, else production. */
|
|
4
|
+
export declare const resolveApiUrl: (deps: RunDeps, flag?: string) => string;
|
|
5
|
+
/**
|
|
6
|
+
* The generated client with design §3.2's retries underneath it. A request that never gets an answer, even after the
|
|
7
|
+
* retries, surfaces as an exit-8 CliError; `step` names where in `--json` documents.
|
|
8
|
+
*/
|
|
9
|
+
export declare const apiClient: (deps: RunDeps, options: {
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
step: string;
|
|
12
|
+
token?: string;
|
|
13
|
+
}) => OarsClient;
|
|
14
|
+
/** What openapi-fetch returns for any call: `data` on a 2xx with a body, else `error` (the parsed body, or text). */
|
|
15
|
+
interface ApiResult<T> {
|
|
16
|
+
data?: T;
|
|
17
|
+
error?: unknown;
|
|
18
|
+
response: Response;
|
|
19
|
+
}
|
|
20
|
+
/** The body of a successful call; a non-2xx answer becomes the CliError its problem maps to. */
|
|
21
|
+
export declare const unwrap: <T>(step: string, result: ApiResult<T>) => T;
|
|
22
|
+
export {};
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createOarsClient, DEFAULT_API_URL } from '@manyoars/oars-client';
|
|
2
|
+
import { problemError, unreachableError } from './errors.js';
|
|
3
|
+
import { retryingFetch } from './retry.js';
|
|
4
|
+
/** `--api-url`, else `OARS_API_URL`, else production. */
|
|
5
|
+
export const resolveApiUrl = (deps, flag) => flag ?? (deps.env.OARS_API_URL === undefined || deps.env.OARS_API_URL === '' ? DEFAULT_API_URL : deps.env.OARS_API_URL);
|
|
6
|
+
/**
|
|
7
|
+
* The generated client with design §3.2's retries underneath it. A request that never gets an answer, even after the
|
|
8
|
+
* retries, surfaces as an exit-8 CliError; `step` names where in `--json` documents.
|
|
9
|
+
*/
|
|
10
|
+
export const apiClient = (deps, options) => {
|
|
11
|
+
const send = retryingFetch((request) => fetch(request), deps);
|
|
12
|
+
return createOarsClient({
|
|
13
|
+
version: deps.version,
|
|
14
|
+
baseUrl: options.apiUrl,
|
|
15
|
+
...(options.token === undefined ? {} : { token: options.token }),
|
|
16
|
+
fetch: async (request) => {
|
|
17
|
+
try {
|
|
18
|
+
return await send(request);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw unreachableError(options.step, error);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
/** The body of a successful call; a non-2xx answer becomes the CliError its problem maps to. */
|
|
27
|
+
export const unwrap = (step, result) => {
|
|
28
|
+
if (result.response.ok && result.data !== undefined)
|
|
29
|
+
return result.data;
|
|
30
|
+
throw problemError(step, result.response.status, result.error);
|
|
31
|
+
};
|
package/dist/bin.d.ts
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
5
|
+
import { openBrowser } from './browser.js';
|
|
6
|
+
import { run } from './cli.js';
|
|
7
|
+
import { defaultConfigDir, fileCredentialStore } from './credentials.js';
|
|
8
|
+
import { fileJournalStore } from './journal.js';
|
|
9
|
+
/** The version in this package's package.json (one folder up from dist/). */
|
|
10
|
+
const readVersion = () => {
|
|
11
|
+
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
12
|
+
const version = typeof manifest === 'object' && manifest !== null ? Reflect.get(manifest, 'version') : undefined;
|
|
13
|
+
return typeof version === 'string' ? version : '0.0.0';
|
|
14
|
+
};
|
|
15
|
+
const configDir = defaultConfigDir(process.env, process.platform, homedir());
|
|
16
|
+
// exitCode rather than process.exit(), so a piped stdout is flushed before the process ends.
|
|
17
|
+
process.exitCode = await run(process.argv.slice(2), {
|
|
18
|
+
env: process.env,
|
|
19
|
+
io: {
|
|
20
|
+
stdout: (text) => process.stdout.write(text),
|
|
21
|
+
stderr: (text) => process.stderr.write(text),
|
|
22
|
+
},
|
|
23
|
+
store: fileCredentialStore(configDir),
|
|
24
|
+
journal: fileJournalStore(configDir),
|
|
25
|
+
version: readVersion(),
|
|
26
|
+
sleep: (ms) => sleep(ms),
|
|
27
|
+
random: Math.random,
|
|
28
|
+
now: Date.now,
|
|
29
|
+
openBrowser,
|
|
30
|
+
});
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
/** The command that opens a URL in the default browser, without a shell (so a `&` in the URL stays in it). */
|
|
3
|
+
const opener = (platform, url) => {
|
|
4
|
+
if (platform === 'win32')
|
|
5
|
+
return ['rundll32', ['url.dll,FileProtocolHandler', url]];
|
|
6
|
+
if (platform === 'darwin')
|
|
7
|
+
return ['open', [url]];
|
|
8
|
+
return ['xdg-open', [url]];
|
|
9
|
+
};
|
|
10
|
+
/** Opens `url` in the default browser. Only http(s) is opened: the URL comes from the issuer's response, and other schemes can run programs. */
|
|
11
|
+
export const openBrowser = (url, platform = process.platform) => {
|
|
12
|
+
const scheme = new URL(url).protocol;
|
|
13
|
+
if (scheme !== 'https:' && scheme !== 'http:')
|
|
14
|
+
return Promise.reject(new Error(`Refusing to open a ${scheme} URL`));
|
|
15
|
+
const [command, args] = opener(platform, url);
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const child = spawn(command, args, { stdio: 'ignore', detached: true });
|
|
18
|
+
child.once('error', reject);
|
|
19
|
+
child.once('spawn', () => {
|
|
20
|
+
child.unref();
|
|
21
|
+
resolve();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CredentialStore } from './credentials.js';
|
|
2
|
+
import { ExitCode } from './errors.js';
|
|
3
|
+
import type { JournalStore } from './journal.js';
|
|
4
|
+
/** Everything the CLI takes from its process, so the tests can stand in for each. */
|
|
5
|
+
export interface RunDeps {
|
|
6
|
+
env: NodeJS.ProcessEnv;
|
|
7
|
+
io: {
|
|
8
|
+
stdout: (text: string) => void;
|
|
9
|
+
stderr: (text: string) => void;
|
|
10
|
+
};
|
|
11
|
+
store: CredentialStore;
|
|
12
|
+
/** Where `deploy` keeps its progress between a failed run and the rerun. */
|
|
13
|
+
journal: JournalStore;
|
|
14
|
+
/** Sent as `User-Agent: oars/<version>` and printed by `--version`. */
|
|
15
|
+
version: string;
|
|
16
|
+
sleep: (ms: number) => Promise<void>;
|
|
17
|
+
/** In [0, 1), for retry jitter. */
|
|
18
|
+
random: () => number;
|
|
19
|
+
/** Epoch milliseconds. */
|
|
20
|
+
now: () => number;
|
|
21
|
+
openBrowser: (url: string) => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/** What a command produced: the `--json` document, and the line a human sees instead. */
|
|
24
|
+
export interface Outcome {
|
|
25
|
+
document: object;
|
|
26
|
+
text: string;
|
|
27
|
+
}
|
|
28
|
+
/** Runs one invocation (`argv` without the node and script entries) and returns the exit code. */
|
|
29
|
+
export declare const run: (argv: string[], deps: RunDeps) => Promise<ExitCode>;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { Command, CommanderError, InvalidArgumentError } from 'commander';
|
|
3
|
+
import { resolveApiUrl } from './api.js';
|
|
4
|
+
import { deploy } from './commands/deploy.js';
|
|
5
|
+
import { login } from './commands/login.js';
|
|
6
|
+
import { logout } from './commands/logout.js';
|
|
7
|
+
import { status } from './commands/status.js';
|
|
8
|
+
import { testCharge } from './commands/test-charge.js';
|
|
9
|
+
import { CliError, ExitCode } from './errors.js';
|
|
10
|
+
const flag = (options, name) => options[name] === true;
|
|
11
|
+
const text = (options, name) => {
|
|
12
|
+
const value = options[name];
|
|
13
|
+
return typeof value === 'string' ? value : undefined;
|
|
14
|
+
};
|
|
15
|
+
const list = (options, name) => {
|
|
16
|
+
const value = options[name];
|
|
17
|
+
return Array.isArray(value) ? value.filter((entry) => typeof entry === 'string') : [];
|
|
18
|
+
};
|
|
19
|
+
const count = (options, name) => {
|
|
20
|
+
const value = options[name];
|
|
21
|
+
return typeof value === 'number' ? value : undefined;
|
|
22
|
+
};
|
|
23
|
+
/** A repeatable option's collector: each use adds one value. */
|
|
24
|
+
const collect = (value, previous) => [...(previous ?? []), value];
|
|
25
|
+
const positiveInteger = (value) => {
|
|
26
|
+
if (!/^[1-9]\d*$/.test(value))
|
|
27
|
+
throw new InvalidArgumentError('it must be a positive whole number.');
|
|
28
|
+
return Number(value);
|
|
29
|
+
};
|
|
30
|
+
const emit = (deps, json, outcome) => {
|
|
31
|
+
deps.io.stdout(`${json ? JSON.stringify(outcome.document) : outcome.text}\n`);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* `--json` prints `{ok: false, step, problem}` on stdout, plus `workloadId`, `sdkKey` and `rerun` after a deploy that stopped;
|
|
35
|
+
* otherwise the problem's title, detail and URL go to stderr, then the rerun line, and the one-time SDK key goes to stdout.
|
|
36
|
+
*/
|
|
37
|
+
const printFailure = (deps, json, error) => {
|
|
38
|
+
const { partial } = error;
|
|
39
|
+
if (json) {
|
|
40
|
+
deps.io.stdout(`${JSON.stringify({ ok: false, step: error.step, problem: error.problem, ...partial })}\n`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const { title, detail, actionUrl } = error.problem;
|
|
44
|
+
const resume = partial === undefined ? [] : [`Workload ${partial.workloadId} is registered; the deploy stopped at ${error.step}.`, `Rerun to resume: ${partial.rerun}`];
|
|
45
|
+
deps.io.stderr(`${[title ?? error.message, detail, actionUrl, ...resume].filter((line) => line !== undefined && line !== '').join('\n')}\n`);
|
|
46
|
+
if (partial?.sdkKey !== undefined)
|
|
47
|
+
deps.io.stdout(`SDK key (shown once; save it now): ${partial.sdkKey}\n`);
|
|
48
|
+
};
|
|
49
|
+
const buildProgram = (deps, argv) => {
|
|
50
|
+
const program = new Command('oars')
|
|
51
|
+
.description('Deploy an agent on Many Oars and set its prices')
|
|
52
|
+
.version(deps.version)
|
|
53
|
+
.exitOverride()
|
|
54
|
+
.configureOutput({ writeOut: deps.io.stdout, writeErr: deps.io.stderr })
|
|
55
|
+
.option('--json', 'print one JSON document on stdout instead of text')
|
|
56
|
+
.option('--api-url <url>', 'the platform API (default: OARS_API_URL, else https://api.manyoars.com)')
|
|
57
|
+
.option('--idempotency-key <key>', "the base of every step's idempotency key (default: a fresh UUID); rerun a failed command with the same key to resume");
|
|
58
|
+
program
|
|
59
|
+
.command('login')
|
|
60
|
+
.description('sign in with your browser (RFC 8628 device flow)')
|
|
61
|
+
.option('--no-browser', 'print the link and code without opening a browser')
|
|
62
|
+
.option('--issuer-url <url>', 'the Keycloak realm URL (default: OARS_ISSUER_URL)')
|
|
63
|
+
.action(async (_options, command) => {
|
|
64
|
+
const options = command.optsWithGlobals();
|
|
65
|
+
const outcome = await login(deps, {
|
|
66
|
+
apiUrl: resolveApiUrl(deps, text(options, 'apiUrl')),
|
|
67
|
+
browser: options.browser !== false,
|
|
68
|
+
...(text(options, 'issuerUrl') === undefined ? {} : { issuerUrl: text(options, 'issuerUrl') }),
|
|
69
|
+
});
|
|
70
|
+
emit(deps, flag(options, 'json'), outcome);
|
|
71
|
+
});
|
|
72
|
+
program
|
|
73
|
+
.command('logout')
|
|
74
|
+
.description('revoke the stored login and delete it')
|
|
75
|
+
.action(async (_options, command) => {
|
|
76
|
+
const options = command.optsWithGlobals();
|
|
77
|
+
emit(deps, flag(options, 'json'), await logout(deps));
|
|
78
|
+
});
|
|
79
|
+
program
|
|
80
|
+
.command('deploy')
|
|
81
|
+
.description('register a workload, create its prices and deploy it; stops at the first failed step (exit 9)')
|
|
82
|
+
.option('--template <id>', 'a starter template (not available until the public API lists them)')
|
|
83
|
+
.option('--image <ref>', 'an image pinned by digest (name@sha256:...)')
|
|
84
|
+
.option('--manifest <file>', 'a JSON workload manifest')
|
|
85
|
+
.option('--name <name>', 'the workload name (--image)')
|
|
86
|
+
.option('--port <n>', 'the service port (--image; default 8080)', positiveInteger)
|
|
87
|
+
.option('--public', 'expose the service publicly (--image)')
|
|
88
|
+
.option('--cpu-millicores <n>', 'CPU in millicores (--image; default 250)', positiveInteger)
|
|
89
|
+
.option('--memory-mib <n>', 'memory in MiB (--image; default 256)', positiveInteger)
|
|
90
|
+
.option('--always-on', 'keep the public service running instead of idling')
|
|
91
|
+
.option('--price <ref>', 'a starter price to create (--template; repeatable)', collect)
|
|
92
|
+
.option('--no-prices', 'create none of the starter prices (--template)')
|
|
93
|
+
.option('--price-file <file>', 'a JSON array of prices to create (--image, --manifest)')
|
|
94
|
+
.option('--secret <NAME=value>', 'a secret for the workload (repeatable); prefer --secret-from-env', collect)
|
|
95
|
+
.option('--secret-from-env <NAME>', 'a secret read from the environment variable NAME (repeatable)', collect)
|
|
96
|
+
.option('--no-start', 'register and price the workload without deploying it')
|
|
97
|
+
.action(async (_options, command) => {
|
|
98
|
+
const options = command.optsWithGlobals();
|
|
99
|
+
const outcome = await deploy(deps, {
|
|
100
|
+
apiUrl: resolveApiUrl(deps, text(options, 'apiUrl')),
|
|
101
|
+
argv,
|
|
102
|
+
start: options.start !== false,
|
|
103
|
+
idempotencyKey: text(options, 'idempotencyKey'),
|
|
104
|
+
template: text(options, 'template'),
|
|
105
|
+
image: text(options, 'image'),
|
|
106
|
+
manifestFile: text(options, 'manifest'),
|
|
107
|
+
name: text(options, 'name'),
|
|
108
|
+
port: count(options, 'port'),
|
|
109
|
+
public: flag(options, 'public') ? true : undefined,
|
|
110
|
+
cpuMillicores: count(options, 'cpuMillicores'),
|
|
111
|
+
memoryMib: count(options, 'memoryMib'),
|
|
112
|
+
alwaysOn: flag(options, 'alwaysOn') ? true : undefined,
|
|
113
|
+
prices: list(options, 'price'),
|
|
114
|
+
noPrices: options.prices === false,
|
|
115
|
+
priceFile: text(options, 'priceFile'),
|
|
116
|
+
secrets: list(options, 'secret'),
|
|
117
|
+
secretsFromEnv: list(options, 'secretFromEnv'),
|
|
118
|
+
});
|
|
119
|
+
emit(deps, flag(options, 'json'), outcome);
|
|
120
|
+
});
|
|
121
|
+
program
|
|
122
|
+
.command('status')
|
|
123
|
+
.description('show a workload and its billing mode')
|
|
124
|
+
.argument('<workloadId>', 'the workload id')
|
|
125
|
+
.action(async (workloadId, _options, command) => {
|
|
126
|
+
const options = command.optsWithGlobals();
|
|
127
|
+
emit(deps, flag(options, 'json'), await status(deps, { apiUrl: resolveApiUrl(deps, text(options, 'apiUrl')), workloadId }));
|
|
128
|
+
});
|
|
129
|
+
program
|
|
130
|
+
.command('test-charge')
|
|
131
|
+
.description("make a TEST-mode charge against one of a workload's prices")
|
|
132
|
+
.argument('<workloadId>', 'the workload id')
|
|
133
|
+
.option('--price <ref>', "the price to charge (default: the workload's only active price)")
|
|
134
|
+
.action(async (workloadId, _options, command) => {
|
|
135
|
+
const options = command.optsWithGlobals();
|
|
136
|
+
const outcome = await testCharge(deps, {
|
|
137
|
+
apiUrl: resolveApiUrl(deps, text(options, 'apiUrl')),
|
|
138
|
+
workloadId,
|
|
139
|
+
priceRef: text(options, 'price'),
|
|
140
|
+
idempotencyKey: text(options, 'idempotencyKey') ?? randomUUID(),
|
|
141
|
+
});
|
|
142
|
+
emit(deps, flag(options, 'json'), outcome);
|
|
143
|
+
});
|
|
144
|
+
return program;
|
|
145
|
+
};
|
|
146
|
+
const asCliError = (error) => {
|
|
147
|
+
if (error instanceof CliError)
|
|
148
|
+
return error;
|
|
149
|
+
if (error instanceof CommanderError)
|
|
150
|
+
return new CliError(error.message.replace(/^error: /, ''), ExitCode.USAGE, 'usage');
|
|
151
|
+
return new CliError(`Unexpected error: ${error instanceof Error ? error.message : String(error)}`, ExitCode.UNEXPECTED, 'unexpected');
|
|
152
|
+
};
|
|
153
|
+
/** Runs one invocation (`argv` without the node and script entries) and returns the exit code. */
|
|
154
|
+
export const run = async (argv, deps) => {
|
|
155
|
+
try {
|
|
156
|
+
await buildProgram(deps, argv).parseAsync(argv, { from: 'user' });
|
|
157
|
+
return ExitCode.OK;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
// --help and --version end the parse through exitOverride with exit code 0; commander has already printed them.
|
|
161
|
+
if (error instanceof CommanderError && error.exitCode === 0)
|
|
162
|
+
return ExitCode.OK;
|
|
163
|
+
const failure = asCliError(error);
|
|
164
|
+
// Commander wrote its own usage message to stderr; a CliError is ours to print.
|
|
165
|
+
if (!(error instanceof CommanderError) || argv.includes('--json'))
|
|
166
|
+
printFailure(deps, argv.includes('--json'), failure);
|
|
167
|
+
return failure.exitCode;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { components } from '@manyoars/oars-client';
|
|
2
|
+
type RegisterWorkloadRequest = components['schemas']['RegisterWorkloadRequest'];
|
|
3
|
+
type CreatePriceInput = components['schemas']['CreatePriceInput'];
|
|
4
|
+
/** What `oars deploy` is told to deploy, as the flags give it. A flag the developer did not pass is undefined. */
|
|
5
|
+
export interface DeployFlags {
|
|
6
|
+
template?: string;
|
|
7
|
+
image?: string;
|
|
8
|
+
manifestFile?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
port?: number;
|
|
11
|
+
public?: boolean;
|
|
12
|
+
cpuMillicores?: number;
|
|
13
|
+
memoryMib?: number;
|
|
14
|
+
alwaysOn?: boolean;
|
|
15
|
+
/** `--price`: starter prices to pick from a template. */
|
|
16
|
+
prices: string[];
|
|
17
|
+
/** `--no-prices`. */
|
|
18
|
+
noPrices: boolean;
|
|
19
|
+
priceFile?: string;
|
|
20
|
+
/** `NAME=value` entries. */
|
|
21
|
+
secrets: string[];
|
|
22
|
+
/** Names of environment variables to read. */
|
|
23
|
+
secretsFromEnv: string[];
|
|
24
|
+
}
|
|
25
|
+
/** The register body and the prices to create, validated and ready to send. */
|
|
26
|
+
export interface DeployInput {
|
|
27
|
+
request: RegisterWorkloadRequest;
|
|
28
|
+
prices: CreatePriceInput[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Turns the flags into the calls' bodies without touching the network, so a mistake costs nothing. Exactly one of
|
|
32
|
+
* `--template`, `--image`, `--manifest`; `--template` waits for the public template catalog (the `oars templates` brief).
|
|
33
|
+
*/
|
|
34
|
+
export declare const loadDeployInput: (flags: DeployFlags, env: NodeJS.ProcessEnv) => Promise<DeployInput>;
|
|
35
|
+
export {};
|