@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.
Files changed (85) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/LICENSE +201 -0
  3. package/README.md +61 -2
  4. package/dist/args.d.ts +25 -0
  5. package/dist/args.d.ts.map +1 -0
  6. package/dist/args.js +71 -0
  7. package/dist/args.js.map +1 -0
  8. package/dist/catalog.d.ts +30 -0
  9. package/dist/catalog.d.ts.map +1 -0
  10. package/dist/catalog.js +33 -0
  11. package/dist/catalog.js.map +1 -0
  12. package/dist/cli.d.ts +8 -0
  13. package/dist/cli.d.ts.map +1 -0
  14. package/dist/cli.js +15 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/commands/api.d.ts +18 -0
  17. package/dist/commands/api.d.ts.map +1 -0
  18. package/dist/commands/api.js +84 -0
  19. package/dist/commands/api.js.map +1 -0
  20. package/dist/commands/auth.d.ts +16 -0
  21. package/dist/commands/auth.d.ts.map +1 -0
  22. package/dist/commands/auth.js +173 -0
  23. package/dist/commands/auth.js.map +1 -0
  24. package/dist/commands/generated.d.ts +31 -0
  25. package/dist/commands/generated.d.ts.map +1 -0
  26. package/dist/commands/generated.js +147 -0
  27. package/dist/commands/generated.js.map +1 -0
  28. package/dist/commands/help.d.ts +34 -0
  29. package/dist/commands/help.d.ts.map +1 -0
  30. package/dist/commands/help.js +117 -0
  31. package/dist/commands/help.js.map +1 -0
  32. package/dist/commands/templates.d.ts +59 -0
  33. package/dist/commands/templates.d.ts.map +1 -0
  34. package/dist/commands/templates.js +388 -0
  35. package/dist/commands/templates.js.map +1 -0
  36. package/dist/config.d.ts +63 -0
  37. package/dist/config.d.ts.map +1 -0
  38. package/dist/config.js +104 -0
  39. package/dist/config.js.map +1 -0
  40. package/dist/confirm.d.ts +11 -0
  41. package/dist/confirm.d.ts.map +1 -0
  42. package/dist/confirm.js +21 -0
  43. package/dist/confirm.js.map +1 -0
  44. package/dist/context.d.ts +53 -0
  45. package/dist/context.d.ts.map +1 -0
  46. package/dist/context.js +129 -0
  47. package/dist/context.js.map +1 -0
  48. package/dist/credentials.d.ts +50 -0
  49. package/dist/credentials.d.ts.map +1 -0
  50. package/dist/credentials.js +148 -0
  51. package/dist/credentials.js.map +1 -0
  52. package/dist/errors.d.ts +43 -0
  53. package/dist/errors.d.ts.map +1 -0
  54. package/dist/errors.js +61 -0
  55. package/dist/errors.js.map +1 -0
  56. package/dist/fields.d.ts +49 -0
  57. package/dist/fields.d.ts.map +1 -0
  58. package/dist/fields.js +280 -0
  59. package/dist/fields.js.map +1 -0
  60. package/dist/main.d.ts +20 -0
  61. package/dist/main.d.ts.map +1 -0
  62. package/dist/main.js +189 -0
  63. package/dist/main.js.map +1 -0
  64. package/dist/oauth.d.ts +62 -0
  65. package/dist/oauth.d.ts.map +1 -0
  66. package/dist/oauth.js +156 -0
  67. package/dist/oauth.js.map +1 -0
  68. package/dist/render.d.ts +10 -0
  69. package/dist/render.d.ts.map +1 -0
  70. package/dist/render.js +46 -0
  71. package/dist/render.js.map +1 -0
  72. package/dist/session.d.ts +91 -0
  73. package/dist/session.d.ts.map +1 -0
  74. package/dist/session.js +235 -0
  75. package/dist/session.js.map +1 -0
  76. package/dist/spec.d.ts +72 -0
  77. package/dist/spec.d.ts.map +1 -0
  78. package/dist/spec.js +171 -0
  79. package/dist/spec.js.map +1 -0
  80. package/dist/version.d.ts +7 -0
  81. package/dist/version.d.ts.map +1 -0
  82. package/dist/version.js +7 -0
  83. package/dist/version.js.map +1 -0
  84. package/npm-shrinkwrap.json +3868 -0
  85. package/package.json +46 -4
@@ -0,0 +1,59 @@
1
+ /**
2
+ * moxo templates pull | plan (diff) | push | export | import: a template as a
3
+ * file in a repository.
4
+ *
5
+ * pull GET /v1/templates/{id}/file: the draft as YAML. Changes nothing.
6
+ * plan PUT /v1/templates/{id}/file without `apply`: the change list the
7
+ * file makes and every check, saving nothing (a dry run).
8
+ * push the same with `apply: true`: saves the changes to the draft. A
9
+ * file pulled before someone else changed the template is refused
10
+ * (exit 2) rather than undoing their change: pull again, make the
11
+ * change in that file, push again. --overwrite replaces the template
12
+ * with the file as it is. After a push the file is the draft as
13
+ * Moxo now has it (pulled again, with the template's id comment),
14
+ * so committing it keeps the repository and Moxo the same and the
15
+ * next push from it is not a conflict. If someone changed the
16
+ * template between the push and that pull, only the revision line
17
+ * moves, with a warning.
18
+ *
19
+ * A folder is pushed file by file: two files naming one template are refused
20
+ * before anything is sent, each file's outcome is listed, and the exit code is
21
+ * the worst of them.
22
+ * export GET /v1/templates/{id}/export: an encrypted .moxo (or, with
23
+ * --bundle, a .moxo-bundle with its AI agents) to move a template to
24
+ * another organization.
25
+ * import POST /v1/templates/import-init, upload, POST /v1/templates/import.
26
+ *
27
+ * The file format names steps, roles and fields by keys, never ids, so it
28
+ * does not say which template it is. `pull` writes that in a comment under the
29
+ * first line (`# moxo-template: <id>`), which Moxo ignores; --template names
30
+ * another, and `push --create` makes a new template from a file.
31
+ */
32
+ import type { Context, Output } from '../context.js';
33
+ import { type GlobalOptions } from '../session.js';
34
+ export declare const TEMPLATE_ID_COMMENT = "# moxo-template:";
35
+ export declare const TEMPLATES_USAGE: string;
36
+ /** The template id a file names in its comment, if any. */
37
+ export declare function templateIdOf(text: string): string | undefined;
38
+ /** The file with its comment naming the template: under the first line when that is a comment, else first. */
39
+ export declare function withTemplateId(text: string, id: string): string;
40
+ /** The file with its `revision:` line moved on, when it has one. */
41
+ export declare function withRevision(text: string, revision: number): string;
42
+ /** The template files a list of files and folders names: a folder gives every .yaml/.yml in it that is a template. */
43
+ export declare function templateFiles(cwd: string, args: readonly string[]): string[];
44
+ /** One problem the template's checks found (the API's AuthoringIssue). */
45
+ interface AuthoringIssue {
46
+ severity?: 'error' | 'warning';
47
+ code?: string;
48
+ where?: Record<string, unknown>;
49
+ problem?: string;
50
+ fix?: string;
51
+ }
52
+ /** An issue as a line: its code, what is wrong and what to do. */
53
+ export declare function describeIssue(i: AuthoringIssue): string;
54
+ /** One change as a line: what it does and to which item. */
55
+ export declare function describeChange(c: Record<string, unknown>): string;
56
+ export declare function templatesCommand(ctx: Context, out: Output, globals: GlobalOptions, sub: string, args: string[]): Promise<number>;
57
+ export declare const HAND_WRITTEN_TEMPLATE_COMMANDS: readonly ["pull", "plan", "diff", "push", "export", "import"];
58
+ export {};
59
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/commands/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAMH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAqE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEtH,eAAO,MAAM,mBAAmB,qBAAqB,CAAC;AAKtD,eAAO,MAAM,eAAe,QAMhB,CAAC;AAEb,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE7D;AAED,8GAA8G;AAC9G,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAM/D;AAED,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,sHAAsH;AACtH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAkB5E;AAiBD,0EAA0E;AAC1E,UAAU,cAAc;IACtB,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAEvD;AAWD,4DAA4D;AAC5D,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAWjE;AAuPD,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBtI;AAED,eAAO,MAAM,8BAA8B,+DAAgE,CAAC"}
@@ -0,0 +1,388 @@
1
+ /**
2
+ * moxo templates pull | plan (diff) | push | export | import: a template as a
3
+ * file in a repository.
4
+ *
5
+ * pull GET /v1/templates/{id}/file: the draft as YAML. Changes nothing.
6
+ * plan PUT /v1/templates/{id}/file without `apply`: the change list the
7
+ * file makes and every check, saving nothing (a dry run).
8
+ * push the same with `apply: true`: saves the changes to the draft. A
9
+ * file pulled before someone else changed the template is refused
10
+ * (exit 2) rather than undoing their change: pull again, make the
11
+ * change in that file, push again. --overwrite replaces the template
12
+ * with the file as it is. After a push the file is the draft as
13
+ * Moxo now has it (pulled again, with the template's id comment),
14
+ * so committing it keeps the repository and Moxo the same and the
15
+ * next push from it is not a conflict. If someone changed the
16
+ * template between the push and that pull, only the revision line
17
+ * moves, with a warning.
18
+ *
19
+ * A folder is pushed file by file: two files naming one template are refused
20
+ * before anything is sent, each file's outcome is listed, and the exit code is
21
+ * the worst of them.
22
+ * export GET /v1/templates/{id}/export: an encrypted .moxo (or, with
23
+ * --bundle, a .moxo-bundle with its AI agents) to move a template to
24
+ * another organization.
25
+ * import POST /v1/templates/import-init, upload, POST /v1/templates/import.
26
+ *
27
+ * The file format names steps, roles and fields by keys, never ids, so it
28
+ * does not say which template it is. `pull` writes that in a comment under the
29
+ * first line (`# moxo-template: <id>`), which Moxo ignores; --template names
30
+ * another, and `push --create` makes a new template from a file.
31
+ */
32
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
33
+ import { basename, dirname, join, relative, resolve } from 'node:path';
34
+ import { randomUUID } from 'node:crypto';
35
+ import { onlyFlags, parseArgs, single } from '../args.js';
36
+ import { CliError, EXIT, usageError, worstExit } from '../errors.js';
37
+ import { ApiClient, announceWrite, refusalError, refusalOf, resolveSession } from '../session.js';
38
+ export const TEMPLATE_ID_COMMENT = '# moxo-template:';
39
+ const TEMPLATE_ID_LINE = /^#\s*moxo-template:\s*(\S+)\s*$/m;
40
+ const REVISION_LINE = /^revision:[ \t]*\d+[ \t]*$/m;
41
+ const TEMPLATE_KIND_LINE = /^kind:\s*Template\s*$/m;
42
+ export const TEMPLATES_USAGE = [
43
+ 'moxo templates pull <templateId> [-o <file> | -o -]',
44
+ 'moxo templates plan <file|folder>... [--template <id>] (also: diff)',
45
+ 'moxo templates push <file|folder>... [--template <id>] [--overwrite] [--create]',
46
+ 'moxo templates export <templateId> [-o <file>] [--bundle]',
47
+ 'moxo templates import <file> [--folder <folderId>]',
48
+ ].join('\n');
49
+ /** The template id a file names in its comment, if any. */
50
+ export function templateIdOf(text) {
51
+ return TEMPLATE_ID_LINE.exec(text)?.[1];
52
+ }
53
+ /** The file with its comment naming the template: under the first line when that is a comment, else first. */
54
+ export function withTemplateId(text, id) {
55
+ const line = `${TEMPLATE_ID_COMMENT} ${id}`;
56
+ if (TEMPLATE_ID_LINE.test(text))
57
+ return text.replace(TEMPLATE_ID_LINE, line);
58
+ const nl = text.indexOf('\n');
59
+ if (text.startsWith('#') && nl >= 0)
60
+ return `${text.slice(0, nl + 1)}${line}\n${text.slice(nl + 1)}`;
61
+ return `${line}\n${text}`;
62
+ }
63
+ /** The file with its `revision:` line moved on, when it has one. */
64
+ export function withRevision(text, revision) {
65
+ return REVISION_LINE.test(text) ? text.replace(REVISION_LINE, `revision: ${revision}`) : text;
66
+ }
67
+ /** The template files a list of files and folders names: a folder gives every .yaml/.yml in it that is a template. */
68
+ export function templateFiles(cwd, args) {
69
+ const out = [];
70
+ const walk = (dir) => {
71
+ for (const name of readdirSync(dir).sort()) {
72
+ if (name === 'node_modules' || name.startsWith('.'))
73
+ continue;
74
+ const p = join(dir, name);
75
+ if (statSync(p).isDirectory())
76
+ walk(p);
77
+ else if (/\.ya?ml$/.test(name) && TEMPLATE_KIND_LINE.test(readFileSync(p, 'utf8')))
78
+ out.push(p);
79
+ }
80
+ };
81
+ for (const a of args) {
82
+ const p = resolve(cwd, a);
83
+ if (!existsSync(p))
84
+ throw usageError(`There is no file or folder ${a}.`);
85
+ if (statSync(p).isDirectory())
86
+ walk(p);
87
+ else
88
+ out.push(p);
89
+ }
90
+ if (out.length === 0)
91
+ throw usageError(`No template files in ${args.join(', ')}: a template file is a .yaml with kind: Template.`);
92
+ return out;
93
+ }
94
+ /** An issue as a line: its code, what is wrong and what to do. */
95
+ export function describeIssue(i) {
96
+ return `${i.code ? `${i.code}: ` : ''}${[i.problem, i.fix].filter(Boolean).join(' ')}`.trim();
97
+ }
98
+ /** One change as a line: what it does and to which item. */
99
+ export function describeChange(c) {
100
+ const op = String(c.op ?? 'change');
101
+ const inner = (k) => (c[k] && typeof c[k] === 'object' ? c[k] : undefined);
102
+ const item = inner('step') ?? inner('role') ?? inner('field') ?? inner('milestone') ?? inner('artifact');
103
+ // A new item is named by its handle (the file's key); an existing one by its id, the only name a change list has for it.
104
+ const target = [item?.handle, item?.key, c.stepId, c.roleId, c.fieldId, c.milestoneId, c.key]
105
+ .find((v) => typeof v === 'string' && v.length > 0);
106
+ const config = item?.config && typeof item.config === 'object' ? item.config : undefined;
107
+ const label = [config?.name, item?.name, item?.label].find((v) => typeof v === 'string' && v.length > 0);
108
+ const sign = op.startsWith('add') || op.startsWith('create') ? '+' : op.startsWith('remove') ? '-' : '~';
109
+ return [sign, op.padEnd(22), (target ?? '').padEnd(24), label ?? ''].join(' ').trimEnd();
110
+ }
111
+ async function pull(ctx, out, globals, p) {
112
+ onlyFlags(p, ['output'], TEMPLATES_USAGE);
113
+ const [id, extra] = p.positionals;
114
+ if (!id || extra)
115
+ throw usageError('Name one template: moxo templates pull <templateId>.', TEMPLATES_USAGE);
116
+ const client = new ApiClient(ctx, await resolveSession(ctx, out, globals));
117
+ const pulled = await client.data('GET', `/v1/templates/${encodeURIComponent(id)}/file`);
118
+ const text = withTemplateId(pulled.file, pulled.templateId ?? id);
119
+ const target = single(p, 'output') ?? pulled.fileName;
120
+ if (target === '-') {
121
+ ctx.stdout(text);
122
+ return EXIT.OK;
123
+ }
124
+ const path = resolve(ctx.cwd, target);
125
+ mkdirSync(dirname(path), { recursive: true });
126
+ writeFileSync(path, text);
127
+ if (globals.json)
128
+ out.json({ templateId: pulled.templateId, name: pulled.name, draftRevision: pulled.draftRevision, path: relative(ctx.cwd, path) || basename(path) });
129
+ else
130
+ out.err(`✓ Pulled ${pulled.name} · revision ${pulled.draftRevision} · ${relative(ctx.cwd, path) || basename(path)}`);
131
+ return EXIT.OK;
132
+ }
133
+ /** Writes what Moxo has after a push: the pulled draft when it is the push's revision, else the file with only its revision line moved. */
134
+ async function writeBack(client, path, text, templateId, revision) {
135
+ let pulled;
136
+ try {
137
+ pulled = await client.data('GET', `/v1/templates/${encodeURIComponent(templateId)}/file`);
138
+ }
139
+ catch {
140
+ pulled = undefined;
141
+ }
142
+ if (pulled && pulled.draftRevision === revision) {
143
+ writeFileSync(path, withTemplateId(pulled.file, templateId));
144
+ return undefined;
145
+ }
146
+ writeFileSync(path, withRevision(text, revision));
147
+ return pulled?.draftRevision;
148
+ }
149
+ /** The template's name in Moxo, to say which template a file goes to before anything is changed. */
150
+ async function templateName(client, templateId) {
151
+ try {
152
+ return (await client.data('GET', `/v1/templates/${encodeURIComponent(templateId)}`))?.name;
153
+ }
154
+ catch {
155
+ return undefined;
156
+ }
157
+ }
158
+ function printOutcome(out, o, apply, many) {
159
+ const head = many ? `${o.path}: ` : '';
160
+ if (o.error) {
161
+ out.err(`${head}✗ ${o.error.message}`);
162
+ const d = o.error.details;
163
+ for (const c of d?.changedSince ?? [])
164
+ out.err(` rev ${c.revision} · ${c.change} · ${c.at}`);
165
+ if (o.exitCode === EXIT.CHANGED_SINCE_PULL)
166
+ out.err(' moxo templates pull gets the template as it is now. push --overwrite replaces it with this file, undoing those changes.');
167
+ return;
168
+ }
169
+ const r = o.result;
170
+ if (!r.accepted) {
171
+ out.err(`${head}✗ Refused. Nothing was saved.`);
172
+ for (const i of r.issues)
173
+ out.err(` ${i.pointer || '(file)'}: ${i.problem} ${i.fix}`.trimEnd());
174
+ for (const i of r.result?.issues ?? [])
175
+ out.err(` ${describeIssue(i)}`);
176
+ return;
177
+ }
178
+ if (r.changes.length === 0) {
179
+ out.err(`${head}No change: the draft already matches this file.`);
180
+ return;
181
+ }
182
+ if (!apply)
183
+ out.err(`${head}Compared with the draft. Nothing is saved.`);
184
+ out.out(many ? `${o.path}` : 'Changes');
185
+ for (const c of r.changes)
186
+ out.out(` ${describeChange(c)}`);
187
+ const issues = r.result?.issues ?? [];
188
+ out.err(issues.length === 0 ? '✓ Checks pass · 0 issues' : `${issues.length} issue${issues.length === 1 ? '' : 's'} to fix before publishing:`);
189
+ for (const i of issues)
190
+ out.err(` ${describeIssue(i)}`);
191
+ if (apply)
192
+ out.err(`✓ ${o.created ? 'Created the template' : 'Saved to the draft'} · revision ${r.draftRevision} · ${r.changes.length} change${r.changes.length === 1 ? '' : 's'}`);
193
+ else
194
+ out.err('Run moxo templates push to save this to the draft.');
195
+ if (o.changedAgainAt !== undefined) {
196
+ out.err(`! The template changed again since this push (revision ${o.changedAgainAt}): only the file's revision line moved. Pull it to see the other change.`);
197
+ }
198
+ }
199
+ /** One line per file, after a folder: how each went. */
200
+ function printSummary(out, outcomes, apply) {
201
+ const ok = outcomes.filter((o) => o.exitCode === EXIT.OK).length;
202
+ out.err(`\n${ok} of ${outcomes.length} files ${apply ? 'saved' : 'pass'}:`);
203
+ for (const o of outcomes) {
204
+ if (o.exitCode === EXIT.OK)
205
+ out.err(` ✓ ${o.path}${o.result ? ` · revision ${o.result.draftRevision}` : ''}`);
206
+ else
207
+ out.err(` ✗ ${o.path} · ${o.error?.code ?? o.result?.result?.issues?.[0]?.code ?? o.result?.issues[0]?.code ?? 'refused'}`);
208
+ }
209
+ }
210
+ async function planOrPush(ctx, out, globals, p, apply) {
211
+ onlyFlags(p, apply ? ['template', 'overwrite', 'create'] : ['template'], TEMPLATES_USAGE);
212
+ if (p.positionals.length === 0)
213
+ throw usageError(`Name a template file or folder: moxo templates ${apply ? 'push' : 'plan'} <file>.`, TEMPLATES_USAGE);
214
+ const files = templateFiles(ctx.cwd, p.positionals);
215
+ const override = single(p, 'template');
216
+ if (override && files.length > 1)
217
+ throw usageError('--template names one template: give one file with it.', TEMPLATES_USAGE);
218
+ const create = p.switches.has('create');
219
+ if (create && override)
220
+ throw usageError('--create makes a new template: leave --template out.', TEMPLATES_USAGE);
221
+ // Two files for one template would overwrite each other: refused before anything is sent.
222
+ const byTemplate = new Map();
223
+ for (const path of files) {
224
+ const id = override ?? templateIdOf(readFileSync(path, 'utf8'));
225
+ if (!id)
226
+ continue;
227
+ const rel = relative(ctx.cwd, path) || basename(path);
228
+ const first = byTemplate.get(id);
229
+ if (first)
230
+ throw usageError(`${first} and ${rel} both name template ${id}. Keep one file per template. Nothing was sent.`);
231
+ byTemplate.set(id, rel);
232
+ }
233
+ const client = new ApiClient(ctx, await resolveSession(ctx, out, globals));
234
+ if (apply)
235
+ await announceWrite(client, out);
236
+ const outcomes = [];
237
+ for (const path of files) {
238
+ const rel = relative(ctx.cwd, path) || basename(path);
239
+ const text = readFileSync(path, 'utf8');
240
+ const templateId = override ?? templateIdOf(text);
241
+ try {
242
+ if (!templateId) {
243
+ if (!(apply && create)) {
244
+ throw usageError(`${rel} does not say which template it is. Pull it with moxo templates pull <templateId> -o ${rel}, give --template <templateId>, or push --create to make a new template from it.`);
245
+ }
246
+ // The answer is a change list's (TemplateAuthoringResult): the new template is `draft.templateId`.
247
+ const made = await client.data('POST', '/v1/templates', { body: { file: text } });
248
+ const id = made.draft?.templateId;
249
+ if (!id)
250
+ throw new CliError('Moxo made the template but did not say its id. Find it with moxo templates list.');
251
+ // The file becomes the new template's own: its id comment and its revision (the copied file's revision line was another template's).
252
+ const pulled = await client.data('GET', `/v1/templates/${encodeURIComponent(id)}/file`);
253
+ writeFileSync(path, withTemplateId(pulled.file, id));
254
+ outcomes.push({ path: rel, templateId: id, exitCode: EXIT.OK, created: true, result: { applied: true, accepted: true, changes: [{ op: 'create_template', key: pulled.name }], issues: [], draftRevision: pulled.draftRevision, result: null } });
255
+ continue;
256
+ }
257
+ if (!globals.json) {
258
+ const name = await templateName(client, templateId);
259
+ out.err(`${rel} → ${name ? `${name} (${templateId})` : templateId}`);
260
+ }
261
+ const body = { file: text, ...(apply ? { apply: true } : {}), ...(apply && p.switches.has('overwrite') ? { overwrite: true } : {}) };
262
+ const res = await client.request('PUT', `/v1/templates/${encodeURIComponent(templateId)}/file`, { body });
263
+ const json = res.json;
264
+ if (res.status === 422 && json?.data) {
265
+ outcomes.push({ path: rel, templateId, exitCode: EXIT.FAILED, result: json.data });
266
+ continue;
267
+ }
268
+ if (res.status >= 400)
269
+ throw refusalError(refusalOf(res));
270
+ const result = json.data;
271
+ const changedAgainAt = apply && result.applied ? await writeBack(client, path, text, templateId, result.draftRevision) : undefined;
272
+ outcomes.push({ path: rel, templateId, exitCode: result.accepted ? EXIT.OK : EXIT.FAILED, result, ...(changedAgainAt !== undefined ? { changedAgainAt } : {}) });
273
+ }
274
+ catch (err) {
275
+ if (!(err instanceof CliError))
276
+ throw err;
277
+ if (err.exitCode === EXIT.SIGN_IN)
278
+ throw err;
279
+ outcomes.push({ path: rel, ...(templateId ? { templateId } : {}), exitCode: err.exitCode, error: { ...(err.code ? { code: err.code } : {}), message: err.message, ...(err.details !== undefined ? { details: err.details } : {}) } });
280
+ }
281
+ }
282
+ if (globals.json) {
283
+ out.json({
284
+ applied: apply,
285
+ files: outcomes.map((o) => ({
286
+ path: o.path,
287
+ templateId: o.templateId,
288
+ exitCode: o.exitCode,
289
+ ...(o.created ? { created: true } : {}),
290
+ ...(o.changedAgainAt !== undefined ? { changedAgainAt: o.changedAgainAt } : {}),
291
+ ...(o.result ? { accepted: o.result.accepted, applied: o.result.applied, draftRevision: o.result.draftRevision, changes: o.result.changes, fileIssues: o.result.issues, issues: o.result.result?.issues ?? [] } : {}),
292
+ ...(o.error ? { error: o.error } : {}),
293
+ })),
294
+ });
295
+ }
296
+ else {
297
+ for (const o of outcomes)
298
+ printOutcome(out, o, apply, outcomes.length > 1);
299
+ if (outcomes.length > 1)
300
+ printSummary(out, outcomes, apply);
301
+ if (apply && outcomes.some((o) => o.result?.applied && !o.created))
302
+ out.err('The file now matches the draft in Moxo, at its new revision: commit it with your change.');
303
+ }
304
+ return worstExit(outcomes.map((o) => o.exitCode));
305
+ }
306
+ async function exportTemplate(ctx, out, globals, p) {
307
+ onlyFlags(p, ['output', 'bundle'], TEMPLATES_USAGE);
308
+ const [id, extra] = p.positionals;
309
+ if (!id || extra)
310
+ throw usageError('Name one template: moxo templates export <templateId>.', TEMPLATES_USAGE);
311
+ const client = new ApiClient(ctx, await resolveSession(ctx, out, globals));
312
+ const bundle = p.switches.has('bundle');
313
+ const res = await client.call('GET', `/v1/templates/${encodeURIComponent(id)}/export`, { accept: 'application/octet-stream', ...(bundle ? { query: { bundle: 'true' } } : {}) });
314
+ const named = /filename="?([^";]+)"?/.exec(res.headers.get('content-disposition') ?? '')?.[1];
315
+ const path = resolve(ctx.cwd, single(p, 'output') ?? basename(named ?? `${id}${bundle ? '.moxo-bundle' : '.moxo'}`));
316
+ writeFileSync(path, res.bytes ?? Buffer.alloc(0));
317
+ if (globals.json)
318
+ out.json({ templateId: id, path: relative(ctx.cwd, path), bytes: res.bytes?.length ?? 0 });
319
+ else
320
+ out.err(`✓ Exported to ${relative(ctx.cwd, path)}. Import it in another organization with moxo templates import ${relative(ctx.cwd, path)}.`);
321
+ return EXIT.OK;
322
+ }
323
+ async function importTemplate(ctx, out, globals, p) {
324
+ onlyFlags(p, ['folder'], TEMPLATES_USAGE);
325
+ const [file, extra] = p.positionals;
326
+ if (!file || extra)
327
+ throw usageError('Name one exported file: moxo templates import <file.moxo>.', TEMPLATES_USAGE);
328
+ const path = resolve(ctx.cwd, file);
329
+ if (!existsSync(path))
330
+ throw usageError(`There is no file ${file}.`);
331
+ const bytes = readFileSync(path);
332
+ const client = new ApiClient(ctx, await resolveSession(ctx, out, globals));
333
+ await announceWrite(client, out);
334
+ const upload = await client.data('POST', '/v1/templates/import-init', {
335
+ body: { fileName: basename(path), fileSize: bytes.length, mimeType: 'application/octet-stream' },
336
+ });
337
+ // The upload address carries its own signature: it gets the file's bytes and
338
+ // the headers Moxo named, never the token.
339
+ let put;
340
+ try {
341
+ put = await ctx.fetch(upload.uploadUrl, { method: 'PUT', headers: upload.requiredHeaders ?? {}, body: bytes });
342
+ }
343
+ catch {
344
+ throw new CliError('Couldn\'t upload the file. Check your connection and run the import again.');
345
+ }
346
+ if (!put.ok)
347
+ throw new CliError(`The upload was refused (${put.status}). Run the import again for a fresh upload address.`);
348
+ if (upload.completionUrl) {
349
+ const url = new URL(upload.completionUrl, client.session.host);
350
+ if (url.origin === new URL(client.session.host).origin)
351
+ await client.call('POST', `${url.pathname}${url.search}`, { body: {} });
352
+ else
353
+ await ctx.fetch(url.toString(), { method: 'POST' });
354
+ }
355
+ const folderId = single(p, 'folder');
356
+ const made = await client.data('POST', '/v1/templates/import', {
357
+ body: { fileId: upload.fileId, ...(folderId ? { folderId } : {}) },
358
+ headers: { 'idempotency-key': randomUUID() },
359
+ });
360
+ if (globals.json) {
361
+ out.json(made);
362
+ return EXIT.OK;
363
+ }
364
+ out.err(`✓ Imported as a draft: ${made.name ?? ''}${made.id ? ` (${made.id})` : ''}`.replace(': (', ': ('));
365
+ for (const w of made.configWarnings ?? [])
366
+ out.err(` Before publishing: ${typeof w === 'string' ? w : (w.message ?? JSON.stringify(w))}`);
367
+ return EXIT.OK;
368
+ }
369
+ export async function templatesCommand(ctx, out, globals, sub, args) {
370
+ const p = parseArgs(args, { switches: ['overwrite', 'create', 'bundle'], aliases: { o: 'output' } });
371
+ switch (sub) {
372
+ case 'pull':
373
+ return pull(ctx, out, globals, p);
374
+ case 'plan':
375
+ case 'diff':
376
+ return planOrPush(ctx, out, globals, p, false);
377
+ case 'push':
378
+ return planOrPush(ctx, out, globals, p, true);
379
+ case 'export':
380
+ return exportTemplate(ctx, out, globals, p);
381
+ case 'import':
382
+ return importTemplate(ctx, out, globals, p);
383
+ default:
384
+ throw usageError(`Unknown command: moxo templates ${sub}.`, TEMPLATES_USAGE);
385
+ }
386
+ }
387
+ export const HAND_WRITTEN_TEMPLATE_COMMANDS = ['pull', 'plan', 'diff', 'push', 'export', 'import'];
388
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/commands/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAe,MAAM,YAAY,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,E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CAAC,CAAC;QAChD,KAAK,QAAQ;YACX,OAAO,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QAC9C,KAAK,QAAQ;YACX,OAAO,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QAC9C;YACE,MAAM,UAAU,CAAC,mCAAmC,GAAG,GAAG,EAAE,eAAe,CAAC,CAAC;IACjF,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Profiles: one sign-in each, to one organization. The file holds no token
3
+ * (credentials.ts keeps those), only where each profile signs in and who it
4
+ * is, so `whoami` and the line before a write can name the organization.
5
+ *
6
+ * ~/.config/moxo/config.json (MOXO_CONFIG_DIR; %APPDATA%\moxo on Windows)
7
+ * ~/.cache/moxo/ (MOXO_CACHE_DIR; the API description)
8
+ */
9
+ import type { Context } from './context.js';
10
+ export declare const DEFAULT_HOST = "https://api.moxo.com";
11
+ /**
12
+ * Each region's API host, which is also its sign-in issuer. The same list as
13
+ * infra/cells.json (`key` → `https://<healthHost>`); a test holds them equal.
14
+ */
15
+ export declare const REGION_HOSTS: Readonly<Record<string, string>>;
16
+ /** The host a run names (--host, --region, then MOXO_HOST), or undefined when it names none. */
17
+ export declare function requestedHost(flags: {
18
+ host?: string;
19
+ region?: string;
20
+ }, env: Readonly<Record<string, string | undefined>>): string | undefined;
21
+ /** The host a run names, or the default. */
22
+ export declare function hostFor(flags: {
23
+ host?: string;
24
+ region?: string;
25
+ }, env: Readonly<Record<string, string | undefined>>): string;
26
+ export declare const DEFAULT_PROFILE = "default";
27
+ export type CredentialKind = 'oauth' | 'personal_access_token';
28
+ export type StoreKind = 'keychain' | 'file';
29
+ export interface Profile {
30
+ host: string;
31
+ credential: CredentialKind;
32
+ store: StoreKind;
33
+ user?: {
34
+ id?: string;
35
+ email?: string;
36
+ name?: string;
37
+ };
38
+ organization?: {
39
+ id?: string;
40
+ name?: string;
41
+ };
42
+ /** From the server's sign-in description, for renewing and revoking an OAuth sign-in. */
43
+ tokenEndpoint?: string;
44
+ revocationEndpoint?: string;
45
+ clientId?: string;
46
+ }
47
+ export interface Config {
48
+ defaultProfile?: string;
49
+ profiles: Record<string, Profile>;
50
+ }
51
+ export declare function configDir(ctx: Pick<Context, 'env' | 'platform'>): string;
52
+ export declare function cacheDir(ctx: Pick<Context, 'env' | 'platform'>): string;
53
+ /** Makes the folder, readable only by its owner (and makes it so if it was not). */
54
+ export declare function privateDir(dir: string): void;
55
+ /** Writes a file whole or not at all, readable only by its owner. */
56
+ export declare function writePrivateFile(path: string, text: string): void;
57
+ export declare function loadConfig(ctx: Pick<Context, 'env' | 'platform'>): Config;
58
+ export declare function saveConfig(ctx: Pick<Context, 'env' | 'platform'>, config: Config): void;
59
+ /** The profile this run uses: --profile, then MOXO_PROFILE, then the default one. */
60
+ export declare function profileName(ctx: Pick<Context, 'env'>, flag: string | undefined, config: Config): string;
61
+ /** A host as the CLI keeps it: https (http only for this machine), no path, no trailing slash. */
62
+ export declare function normalizeHost(raw: string): string;
63
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,eAAO,MAAM,YAAY,yBAAyB,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKzD,CAAC;AAEF,gGAAgG;AAChG,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAA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