@wji.ai/cli 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/index.js +7162 -76
- package/package.json +6 -9
- package/dist/commands/agent.js +0 -294
- package/dist/commands/asset.js +0 -241
- package/dist/commands/auth.js +0 -216
- package/dist/commands/backreel-enquiry.js +0 -171
- package/dist/commands/backreel-episode.js +0 -243
- package/dist/commands/backreel-fund.js +0 -299
- package/dist/commands/backreel.js +0 -443
- package/dist/commands/canvas.js +0 -1706
- package/dist/commands/class.js +0 -395
- package/dist/commands/config.js +0 -113
- package/dist/commands/crew.js +0 -205
- package/dist/commands/fsnode.js +0 -288
- package/dist/commands/gen.js +0 -356
- package/dist/commands/model.js +0 -136
- package/dist/commands/npc-album.js +0 -201
- package/dist/commands/npc-live.js +0 -316
- package/dist/commands/npc.js +0 -437
- package/dist/commands/org.js +0 -85
- package/dist/commands/preset.js +0 -176
- package/dist/commands/profile.js +0 -129
- package/dist/commands/skill.js +0 -272
- package/dist/commands/workspace.js +0 -470
- package/dist/core/archive.js +0 -95
- package/dist/core/backreel.js +0 -23
- package/dist/core/client.js +0 -269
- package/dist/core/config.js +0 -95
- package/dist/core/crew.js +0 -546
- package/dist/core/image.js +0 -106
- package/dist/core/members.js +0 -54
- package/dist/core/npc.js +0 -108
- package/dist/core/output.js +0 -174
- package/dist/core/prompt.js +0 -118
- package/dist/core/vod.js +0 -149
- package/dist/core/zip.js +0 -87
package/dist/commands/npc.js
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import { writeFile } from 'node:fs/promises';
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import { isObjectId, WjiClient } from '../core/client.js';
|
|
4
|
-
import { confirm, parseKeyValues, readJson, readValue } from '../core/prompt.js';
|
|
5
|
-
import { color, detail, info, isJsonMode, printJson, render, relativeTime, success, table, truncate, warn } from '../core/output.js';
|
|
6
|
-
import { NPC_JOB_TYPES, NPC_STATUSES, NPC_VISIBILITIES, RESIDENTS, npcLabel, parseJob, parsePositions, resolveNpc, updateJobs, } from '../core/npc.js';
|
|
7
|
-
import { memoryCommand, readinessCommand, replaceMemories, stageCommand } from './npc-live.js';
|
|
8
|
-
import { albumCommand } from './npc-album.js';
|
|
9
|
-
const TRANSFERS = '/npc-city/transfers';
|
|
10
|
-
export function npcCommand(globals) {
|
|
11
|
-
const npc = new Command('npc')
|
|
12
|
-
.aliases(['npc-city'])
|
|
13
|
-
.description('Manage your NPC City residents (NPCs): profile, jobs, soul, character doc, transfers');
|
|
14
|
-
// ── residents ──────────────────────────────────────────────────────────
|
|
15
|
-
npc
|
|
16
|
-
.command('list', { isDefault: true })
|
|
17
|
-
.description('Your NPCs (org NPCs with --org); --public for the public directory')
|
|
18
|
-
.option('--public', 'list the public directory instead of yours')
|
|
19
|
-
.option('-k, --keyword <text>', 'search text')
|
|
20
|
-
.option('--status <status>', NPC_STATUSES.join(' | '))
|
|
21
|
-
.option('--visibility <v>', NPC_VISIBILITIES.join(' | '))
|
|
22
|
-
.option('--page <n>', 'page number', '1')
|
|
23
|
-
.option('--limit <n>', 'page size', '20')
|
|
24
|
-
.action(async (opts) => {
|
|
25
|
-
const client = new WjiClient(globals());
|
|
26
|
-
const result = await client.get(opts.public ? RESIDENTS : `${RESIDENTS}/mine`, {
|
|
27
|
-
keyword: opts.keyword,
|
|
28
|
-
status: opts.status,
|
|
29
|
-
visibility: opts.visibility,
|
|
30
|
-
page: Number(opts.page),
|
|
31
|
-
limit: Number(opts.limit),
|
|
32
|
-
});
|
|
33
|
-
render(result, (r) => {
|
|
34
|
-
table(r?.data || [], [
|
|
35
|
-
{ header: 'id', value: (n) => n.id },
|
|
36
|
-
{ header: 'name', value: (n) => truncate(n.name, 20) },
|
|
37
|
-
{ header: 'handle', value: (n) => n.handle },
|
|
38
|
-
{ header: 'role', value: (n) => truncate(n.role, 16) },
|
|
39
|
-
{ header: 'genre', value: (n) => truncate(n.genre, 16) },
|
|
40
|
-
{ header: 'status', value: (n) => n.status },
|
|
41
|
-
{ header: 'vis', value: (n) => n.visibility },
|
|
42
|
-
{ header: 'jobs', value: (n) => (n.jobs || []).length },
|
|
43
|
-
{ header: 'updated', value: (n) => relativeTime(n.updatedAt) },
|
|
44
|
-
]);
|
|
45
|
-
pageFooter(r);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
npc
|
|
49
|
-
.command('get <npc>')
|
|
50
|
-
.description('Show an NPC and its jobs (id, @handle or name)')
|
|
51
|
-
.action(async (token) => {
|
|
52
|
-
const client = new WjiClient(globals());
|
|
53
|
-
const r = await resolveNpc(client, token);
|
|
54
|
-
render(r, () => printNpc(r));
|
|
55
|
-
});
|
|
56
|
-
residentOptions(npc
|
|
57
|
-
.command('create <name>')
|
|
58
|
-
.description('Create an NPC (private until you publish it). Needs NPC City spawn permission.')
|
|
59
|
-
.requiredOption('--role <role>', 'role, e.g. Singer')
|
|
60
|
-
.requiredOption('--genre <genre>', 'genre, e.g. City pop')).action(async (name, opts) => {
|
|
61
|
-
const client = new WjiClient(globals());
|
|
62
|
-
const body = await residentBody(client, opts);
|
|
63
|
-
if (body.handle)
|
|
64
|
-
await assertHandle(client, body.handle);
|
|
65
|
-
const created = await client.post(RESIDENTS, { name, ...body });
|
|
66
|
-
render(created, (r) => success(`Created ${npcLabel(r)} — ${r.id} (${r.visibility})`));
|
|
67
|
-
});
|
|
68
|
-
residentOptions(npc
|
|
69
|
-
.command('set <npc>')
|
|
70
|
-
.description('Update NPC fields; only the flags you pass change')
|
|
71
|
-
.option('-n, --name <name>', 'rename')
|
|
72
|
-
.option('--role <role>', 'role')
|
|
73
|
-
.option('--genre <genre>', 'genre')).action(async (token, opts) => {
|
|
74
|
-
const client = new WjiClient(globals());
|
|
75
|
-
const current = await resolveNpc(client, token);
|
|
76
|
-
const body = await residentBody(client, opts, current);
|
|
77
|
-
if (opts.name)
|
|
78
|
-
body.name = opts.name;
|
|
79
|
-
if (!Object.keys(body).length)
|
|
80
|
-
throw new Error('Nothing to change — pass at least one field flag');
|
|
81
|
-
if (body.handle)
|
|
82
|
-
await assertHandle(client, body.handle, current.id);
|
|
83
|
-
const updated = await client.patch(`${RESIDENTS}/${current.id}`, body);
|
|
84
|
-
render(updated, (r) => success(`Updated ${npcLabel(r)}: ${Object.keys(body).join(', ')}`));
|
|
85
|
-
});
|
|
86
|
-
for (const [cmd, visibility] of [['publish', 'public'], ['unpublish', 'private']]) {
|
|
87
|
-
npc
|
|
88
|
-
.command(`${cmd} <npc>`)
|
|
89
|
-
.description(`Make an NPC ${visibility}`)
|
|
90
|
-
.action(async (token) => {
|
|
91
|
-
const client = new WjiClient(globals());
|
|
92
|
-
const r = await resolveNpc(client, token);
|
|
93
|
-
const updated = await client.patch(`${RESIDENTS}/${r.id}`, { visibility });
|
|
94
|
-
render(updated, (u) => success(`${npcLabel(u)} is now ${u.visibility}`));
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
npc
|
|
98
|
-
.command('rm <npc>')
|
|
99
|
-
.description('Delete an NPC')
|
|
100
|
-
.option('-y, --yes', 'skip confirmation')
|
|
101
|
-
.action(async (token, opts) => {
|
|
102
|
-
const client = new WjiClient(globals());
|
|
103
|
-
const r = await resolveNpc(client, token);
|
|
104
|
-
if (!(await confirm(`Delete NPC ${npcLabel(r)} (${r.id})?`, opts.yes)))
|
|
105
|
-
return info('Aborted');
|
|
106
|
-
const result = await client.delete(`${RESIDENTS}/${r.id}`);
|
|
107
|
-
render(result, () => success(`Deleted ${npcLabel(r)}`));
|
|
108
|
-
});
|
|
109
|
-
npc
|
|
110
|
-
.command('handle <handle>')
|
|
111
|
-
.description('Check whether a @handle is free')
|
|
112
|
-
.option('--exclude <npc>', "ignore this NPC's own handle")
|
|
113
|
-
.action(async (handle, opts) => {
|
|
114
|
-
const client = new WjiClient(globals());
|
|
115
|
-
const excludeId = opts.exclude ? (await resolveNpc(client, opts.exclude)).id : undefined;
|
|
116
|
-
const result = await client.get(`${RESIDENTS}/handle-available`, { handle, excludeId });
|
|
117
|
-
render(result, (r) => r.available ? success(`${r.handle} is available`) : warn(`${r.handle} is not available (${r.reason})`));
|
|
118
|
-
});
|
|
119
|
-
// ── jobs (work history) ────────────────────────────────────────────────
|
|
120
|
-
const job = npc.command('job').aliases(['jobs']).description("An NPC's work history: concerts, releases, ads…");
|
|
121
|
-
job
|
|
122
|
-
.command('list <npc>', { isDefault: true })
|
|
123
|
-
.description('Numbered work history')
|
|
124
|
-
.action(async (token) => {
|
|
125
|
-
const client = new WjiClient(globals());
|
|
126
|
-
const r = await resolveNpc(client, token);
|
|
127
|
-
render(r.jobs || [], (jobs) => printJobs(jobs));
|
|
128
|
-
});
|
|
129
|
-
jobOptions(job
|
|
130
|
-
.command('add <npc>')
|
|
131
|
-
.description('Add a job')
|
|
132
|
-
.requiredOption('-t, --type <type>', NPC_JOB_TYPES.join(' | '))
|
|
133
|
-
.requiredOption('--title <text>', 'title')
|
|
134
|
-
.requiredOption('--date <YYYY-MM-DD>', 'date')).action(async (token, opts) => {
|
|
135
|
-
const client = new WjiClient(globals());
|
|
136
|
-
const r = await resolveNpc(client, token);
|
|
137
|
-
const entry = parseJob(opts);
|
|
138
|
-
const updated = await updateJobs(client, r.id, (jobs) => [...jobs, entry]);
|
|
139
|
-
render(updated.jobs, () => success(`Added "${entry.title}" to ${npcLabel(r)} (#${updated.jobs.length})`));
|
|
140
|
-
});
|
|
141
|
-
jobOptions(job
|
|
142
|
-
.command('set <npc> <n>')
|
|
143
|
-
.description('Change job #n (see `npc job list`)')
|
|
144
|
-
.option('-t, --type <type>', NPC_JOB_TYPES.join(' | '))
|
|
145
|
-
.option('--title <text>', 'title')
|
|
146
|
-
.option('--date <YYYY-MM-DD>', 'date')).action(async (token, n, opts) => {
|
|
147
|
-
const client = new WjiClient(globals());
|
|
148
|
-
const r = await resolveNpc(client, token);
|
|
149
|
-
const updated = await updateJobs(client, r.id, (jobs) => {
|
|
150
|
-
const [i] = parsePositions([n], jobs.length);
|
|
151
|
-
jobs[i] = parseJob(opts, jobs[i]);
|
|
152
|
-
return jobs;
|
|
153
|
-
});
|
|
154
|
-
render(updated.jobs, () => success(`Updated job #${n} of ${npcLabel(r)}`));
|
|
155
|
-
});
|
|
156
|
-
job
|
|
157
|
-
.command('rm <npc> <n...>')
|
|
158
|
-
.description('Remove jobs by number')
|
|
159
|
-
.option('-y, --yes', 'skip confirmation')
|
|
160
|
-
.action(async (token, ns, opts) => {
|
|
161
|
-
const client = new WjiClient(globals());
|
|
162
|
-
const r = await resolveNpc(client, token);
|
|
163
|
-
const positions = parsePositions(ns, (r.jobs || []).length);
|
|
164
|
-
const titles = positions.map((i) => `#${i + 1} ${r.jobs[i].title}`).join(', ');
|
|
165
|
-
if (!(await confirm(`Remove ${titles} from ${npcLabel(r)}?`, opts.yes)))
|
|
166
|
-
return info('Aborted');
|
|
167
|
-
// Re-check against a fresh read so a concurrent edit can't shift the numbers.
|
|
168
|
-
const updated = await updateJobs(client, r.id, (jobs) => {
|
|
169
|
-
if (JSON.stringify(jobs) !== JSON.stringify(r.jobs)) {
|
|
170
|
-
throw new Error('The job list changed since it was read — list it again and retry');
|
|
171
|
-
}
|
|
172
|
-
return jobs.filter((_, i) => !positions.includes(i));
|
|
173
|
-
});
|
|
174
|
-
render(updated.jobs, () => success(`Removed ${positions.length} job(s); ${updated.jobs.length} left`));
|
|
175
|
-
});
|
|
176
|
-
// ── soul ───────────────────────────────────────────────────────────────
|
|
177
|
-
const soul = npc.command('soul').description("An NPC's soul config (persona, protocols, voice, assets)");
|
|
178
|
-
soul
|
|
179
|
-
.command('get <npc>', { isDefault: true })
|
|
180
|
-
.description('Print the soul config as JSON')
|
|
181
|
-
.action(async (token) => {
|
|
182
|
-
const client = new WjiClient(globals());
|
|
183
|
-
const r = await resolveNpc(client, token);
|
|
184
|
-
printJson(await client.getFresh(`${RESIDENTS}/${r.id}/soul`));
|
|
185
|
-
});
|
|
186
|
-
soul
|
|
187
|
-
.command('set <npc> <json>')
|
|
188
|
-
.description('Merge top-level soul keys (inline JSON, @file or -); nested objects are replaced whole')
|
|
189
|
-
.action(async (token, json) => {
|
|
190
|
-
const client = new WjiClient(globals());
|
|
191
|
-
const r = await resolveNpc(client, token);
|
|
192
|
-
const soulConfig = await readJson(json);
|
|
193
|
-
if (!soulConfig || typeof soulConfig !== 'object' || Array.isArray(soulConfig)) {
|
|
194
|
-
throw new Error('Soul config must be a JSON object');
|
|
195
|
-
}
|
|
196
|
-
const updated = await client.patch(`${RESIDENTS}/${r.id}/soul`, { soulConfig });
|
|
197
|
-
render(updated, () => success(`Updated soul of ${npcLabel(r)}: ${Object.keys(soulConfig).join(', ')}`));
|
|
198
|
-
});
|
|
199
|
-
// ── character document ────────────────────────────────────────────────
|
|
200
|
-
const doc = npc.command('doc').description('Export / apply the character document (profile + soul in one file)');
|
|
201
|
-
doc
|
|
202
|
-
.command('export <npc>')
|
|
203
|
-
.description('Print or save the character document')
|
|
204
|
-
.option('--format <format>', 'md | json', 'md')
|
|
205
|
-
.option('-o, --out <file>', 'write to a file instead of stdout')
|
|
206
|
-
.action(async (token, opts) => {
|
|
207
|
-
const client = new WjiClient(globals());
|
|
208
|
-
const r = await resolveNpc(client, token);
|
|
209
|
-
const result = await client.getFresh(`${RESIDENTS}/${r.id}/document`, { format: opts.format });
|
|
210
|
-
if (opts.out) {
|
|
211
|
-
await writeFile(opts.out, result.text);
|
|
212
|
-
return render({ file: opts.out, format: result.format }, () => success(`Wrote ${opts.out}`));
|
|
213
|
-
}
|
|
214
|
-
render(result, () => process.stdout.write(result.text.endsWith('\n') ? result.text : `${result.text}\n`));
|
|
215
|
-
});
|
|
216
|
-
doc
|
|
217
|
-
.command('apply <npc> <text>')
|
|
218
|
-
.description('Preview the changes a document makes (@file or -), confirm, then apply')
|
|
219
|
-
.option('--dry-run', 'only show the changes')
|
|
220
|
-
.option('--sync-memories', "replace the NPC's memories with the document's ## Memories (the document route itself ignores them)")
|
|
221
|
-
.option('-y, --yes', 'skip confirmation')
|
|
222
|
-
.action(async (token, source, opts) => {
|
|
223
|
-
const client = new WjiClient(globals());
|
|
224
|
-
const r = await resolveNpc(client, token);
|
|
225
|
-
const text = await readValue(source);
|
|
226
|
-
const base = `${RESIDENTS}/${r.id}/document`;
|
|
227
|
-
const preview = await client.post(`${base}/preview`, { text });
|
|
228
|
-
// The document route reports memory changes but never saves them (updateSoul drops
|
|
229
|
-
// `memories`); they live in their own table. Pull them out and route them there.
|
|
230
|
-
const docMemories = Array.isArray(preview.doc?.memories) ? preview.doc.memories : [];
|
|
231
|
-
const changes = (preview.changes || []).filter((c) => !String(c.path).startsWith('memories'));
|
|
232
|
-
if (docMemories.length && !opts.syncMemories) {
|
|
233
|
-
warn(`The document has ${docMemories.length} memory(ies); they are not saved by this route — add --sync-memories, or use \`wji npc memory add\``);
|
|
234
|
-
}
|
|
235
|
-
if (opts.syncMemories && !opts.dryRun) {
|
|
236
|
-
if (!docMemories.length)
|
|
237
|
-
throw new Error('--sync-memories: the document has no ## Memories section');
|
|
238
|
-
if (await confirm(`Replace ${npcLabel(r)}'s memories with the ${docMemories.length} in the document?`, opts.yes)) {
|
|
239
|
-
const created = await replaceMemories(client, r.id, docMemories);
|
|
240
|
-
success(`Memories replaced: ${created.length}`);
|
|
241
|
-
if (!changes.length)
|
|
242
|
-
return render({ memories: created }, () => info('No other changes'));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (opts.dryRun || !changes.length) {
|
|
246
|
-
return render(preview, () => {
|
|
247
|
-
printChanges(changes, preview.warnings);
|
|
248
|
-
if (!changes.length)
|
|
249
|
-
info('Nothing to apply');
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
if (!isJsonMode())
|
|
253
|
-
printChanges(changes, preview.warnings);
|
|
254
|
-
if (!(await confirm(`Apply ${changes.length} change(s) to ${npcLabel(r)}?`, opts.yes)))
|
|
255
|
-
return info('Aborted');
|
|
256
|
-
const applied = await client.post(base, { text });
|
|
257
|
-
render(applied, (a) => {
|
|
258
|
-
for (const w of a.warnings || [])
|
|
259
|
-
warn(w);
|
|
260
|
-
success(`Applied ${(a.applied || []).length} change(s) to ${npcLabel(r)}`);
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
// ── transfers ─────────────────────────────────────────────────────────
|
|
264
|
-
npc.addCommand(memoryCommand(globals));
|
|
265
|
-
npc.addCommand(readinessCommand(globals));
|
|
266
|
-
npc.addCommand(stageCommand(globals));
|
|
267
|
-
npc.addCommand(albumCommand(globals));
|
|
268
|
-
const transfer = npc
|
|
269
|
-
.command('transfer')
|
|
270
|
-
.description('Hand an NPC to another user; they accept within 7 days');
|
|
271
|
-
transfer
|
|
272
|
-
.command('send <npc>')
|
|
273
|
-
.description('Offer an NPC to another user')
|
|
274
|
-
.requiredOption('--to <user>', 'recipient email or user id')
|
|
275
|
-
.option('-y, --yes', 'skip confirmation')
|
|
276
|
-
.action(async (token, opts) => {
|
|
277
|
-
const client = new WjiClient(globals());
|
|
278
|
-
const r = await resolveNpc(client, token);
|
|
279
|
-
if (!(await confirm(`Offer ${npcLabel(r)} to ${opts.to}? You lose it once they accept.`, opts.yes))) {
|
|
280
|
-
return info('Aborted');
|
|
281
|
-
}
|
|
282
|
-
const target = isObjectId(opts.to) ? { toUserId: opts.to } : { email: opts.to };
|
|
283
|
-
const result = await client.post(`${RESIDENTS}/${r.id}/transfer`, target);
|
|
284
|
-
render(result, (t) => success(`Transfer ${t.id} to ${t.toOwner?.name || opts.to} pending until ${t.expiresAt}`));
|
|
285
|
-
});
|
|
286
|
-
transfer
|
|
287
|
-
.command('list', { isDefault: true })
|
|
288
|
-
.description('Pending transfers, incoming and outgoing')
|
|
289
|
-
.action(async () => {
|
|
290
|
-
const client = new WjiClient(globals());
|
|
291
|
-
const [incoming, outgoing] = await Promise.all([
|
|
292
|
-
client.getFresh(`${TRANSFERS}/incoming`),
|
|
293
|
-
client.getFresh(`${TRANSFERS}/outgoing`),
|
|
294
|
-
]);
|
|
295
|
-
const rows = [
|
|
296
|
-
...(incoming || []).map((t) => ({ ...t, direction: 'in' })),
|
|
297
|
-
...(outgoing || []).map((t) => ({ ...t, direction: 'out' })),
|
|
298
|
-
];
|
|
299
|
-
render(rows, () => table(rows, [
|
|
300
|
-
{ header: 'id', value: (t) => t.id },
|
|
301
|
-
{ header: 'dir', value: (t) => t.direction },
|
|
302
|
-
{ header: 'npc', value: (t) => (t.resident ? npcLabel(t.resident) : null) },
|
|
303
|
-
{ header: 'from', value: (t) => t.fromOwner?.name },
|
|
304
|
-
{ header: 'to', value: (t) => t.toOwner?.name },
|
|
305
|
-
{ header: 'expires', value: (t) => relativeTime(t.expiresAt) },
|
|
306
|
-
]));
|
|
307
|
-
});
|
|
308
|
-
for (const action of ['accept', 'reject', 'cancel']) {
|
|
309
|
-
transfer
|
|
310
|
-
.command(`${action} <transferId>`)
|
|
311
|
-
.description(action === 'cancel' ? 'Withdraw a transfer you sent' : `${action[0].toUpperCase()}${action.slice(1)} a transfer sent to you`)
|
|
312
|
-
.action(async (id) => {
|
|
313
|
-
const client = new WjiClient(globals());
|
|
314
|
-
const result = await client.post(`${TRANSFERS}/${id}/${action}`);
|
|
315
|
-
render(result, (t) => success(`Transfer ${id}: ${t.status}${t.resident ? ` (${npcLabel(t.resident)})` : ''}`));
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
return npc;
|
|
319
|
-
}
|
|
320
|
-
// ── helpers ──────────────────────────────────────────────────────────────
|
|
321
|
-
function residentOptions(cmd) {
|
|
322
|
-
return cmd
|
|
323
|
-
.option('--handle <handle>', '@handle (a-z 0-9 . _ -, 2–32)')
|
|
324
|
-
.option('--tagline <text>', 'one-line tagline')
|
|
325
|
-
.option('--bio <text>', 'bio (@file / - supported)')
|
|
326
|
-
.option('--image <url|assetId>', 'avatar image')
|
|
327
|
-
.option('--hero-image <url|assetId>', 'hero image')
|
|
328
|
-
.option('--color <hex>', 'accent color')
|
|
329
|
-
.option('--status <status>', NPC_STATUSES.join(' | '))
|
|
330
|
-
.option('--visibility <v>', NPC_VISIBILITIES.join(' | '))
|
|
331
|
-
.option('--social <key=url...>', 'ig / yt / tw / web')
|
|
332
|
-
.option('--tag <key=value...>', 'card tags: rating, type, role, gender, tier, language…')
|
|
333
|
-
.option('--set <key=value...>', 'any other field, e.g. liveEnabled=true');
|
|
334
|
-
}
|
|
335
|
-
function jobOptions(cmd) {
|
|
336
|
-
return cmd
|
|
337
|
-
// Not --detail: that is the global output-level flag and would swallow the value.
|
|
338
|
-
.option('--about <text>', 'what happened (the job\'s detail line)')
|
|
339
|
-
.option('--location <text>', 'where')
|
|
340
|
-
.option('--url <url>', 'link');
|
|
341
|
-
}
|
|
342
|
-
/** The resident fields a create / set carries, from flags. `current` merges socials / tags. */
|
|
343
|
-
async function residentBody(client, opts, current) {
|
|
344
|
-
const body = {};
|
|
345
|
-
if (opts.role)
|
|
346
|
-
body.role = opts.role;
|
|
347
|
-
if (opts.genre)
|
|
348
|
-
body.genre = opts.genre;
|
|
349
|
-
if (opts.handle)
|
|
350
|
-
body.handle = opts.handle;
|
|
351
|
-
if (opts.tagline !== undefined)
|
|
352
|
-
body.tagline = opts.tagline;
|
|
353
|
-
if (opts.bio !== undefined)
|
|
354
|
-
body.bio = await readValue(opts.bio);
|
|
355
|
-
if (opts.image)
|
|
356
|
-
body.image = await imageUrl(client, opts.image);
|
|
357
|
-
if (opts.heroImage)
|
|
358
|
-
body.heroImage = await imageUrl(client, opts.heroImage);
|
|
359
|
-
if (opts.color)
|
|
360
|
-
body.color = opts.color;
|
|
361
|
-
if (opts.status)
|
|
362
|
-
body.status = oneOf(opts.status, NPC_STATUSES, '--status');
|
|
363
|
-
if (opts.visibility)
|
|
364
|
-
body.visibility = oneOf(opts.visibility, NPC_VISIBILITIES, '--visibility');
|
|
365
|
-
if (opts.social)
|
|
366
|
-
body.socials = { ...(current?.socials || {}), ...parseKeyValues(opts.social) };
|
|
367
|
-
if (opts.tag)
|
|
368
|
-
body.tags = { ...(current?.tags || {}), ...parseKeyValues(opts.tag) };
|
|
369
|
-
Object.assign(body, parseKeyValues(opts.set));
|
|
370
|
-
return body;
|
|
371
|
-
}
|
|
372
|
-
/** Residents store image URLs; an asset id is swapped for its ready URL. */
|
|
373
|
-
async function imageUrl(client, value) {
|
|
374
|
-
if (!isObjectId(value))
|
|
375
|
-
return value;
|
|
376
|
-
const [asset] = await client.checkAssetStatus([value]);
|
|
377
|
-
if (!asset?.url)
|
|
378
|
-
throw new Error(`Asset ${value} has no URL yet (missing, not yours, or still pending)`);
|
|
379
|
-
return asset.url;
|
|
380
|
-
}
|
|
381
|
-
async function assertHandle(client, handle, excludeId) {
|
|
382
|
-
const r = await client.get(`${RESIDENTS}/handle-available`, { handle, excludeId });
|
|
383
|
-
if (!r.available)
|
|
384
|
-
throw new Error(`Handle ${r.handle || handle} is not available (${r.reason})`);
|
|
385
|
-
}
|
|
386
|
-
function oneOf(value, allowed, flag) {
|
|
387
|
-
if (!allowed.includes(value))
|
|
388
|
-
throw new Error(`${flag} must be one of ${allowed.join(', ')}`);
|
|
389
|
-
return value;
|
|
390
|
-
}
|
|
391
|
-
function pageFooter(r) {
|
|
392
|
-
const p = r?.pagination;
|
|
393
|
-
if (!p)
|
|
394
|
-
return;
|
|
395
|
-
info(color.dim(`${p.total} total · page ${p.page}${p.hasNext ? ` · more: --page ${p.page + 1}` : ''}`));
|
|
396
|
-
}
|
|
397
|
-
function printNpc(r) {
|
|
398
|
-
detail([
|
|
399
|
-
['id', r.id],
|
|
400
|
-
['name', r.name],
|
|
401
|
-
['handle', r.handle],
|
|
402
|
-
['role', r.role],
|
|
403
|
-
['genre', r.genre],
|
|
404
|
-
['status', r.status],
|
|
405
|
-
['visibility', r.visibility],
|
|
406
|
-
['tagline', r.tagline],
|
|
407
|
-
['bio', truncate(r.bio, 120)],
|
|
408
|
-
['image', r.image],
|
|
409
|
-
['owner', r.owner?.name || r.owner],
|
|
410
|
-
['organization', r.organization?.name || r.organization],
|
|
411
|
-
['tags', r.tags && Object.keys(r.tags).length ? r.tags : null],
|
|
412
|
-
['socials', r.socials && Object.keys(r.socials).length ? r.socials : null],
|
|
413
|
-
['live', r.liveEnabled ? (r.livePublic ? 'enabled, public' : 'enabled') : null],
|
|
414
|
-
['updated', relativeTime(r.updatedAt)],
|
|
415
|
-
]);
|
|
416
|
-
process.stdout.write('\n');
|
|
417
|
-
printJobs(r.jobs || []);
|
|
418
|
-
}
|
|
419
|
-
function printJobs(jobs) {
|
|
420
|
-
table(jobs.map((j, i) => ({ ...j, n: i + 1 })), [
|
|
421
|
-
{ header: '#', value: (j) => j.n },
|
|
422
|
-
{ header: 'date', value: (j) => j.date },
|
|
423
|
-
{ header: 'type', value: (j) => j.type },
|
|
424
|
-
{ header: 'title', value: (j) => truncate(j.title, 32) },
|
|
425
|
-
{ header: 'detail', value: (j) => truncate(j.detail, 32) },
|
|
426
|
-
{ header: 'location', value: (j) => truncate(j.location, 20) },
|
|
427
|
-
]);
|
|
428
|
-
}
|
|
429
|
-
function printChanges(changes, warnings = []) {
|
|
430
|
-
for (const w of warnings)
|
|
431
|
-
warn(w);
|
|
432
|
-
table(changes, [
|
|
433
|
-
{ header: 'path', value: (c) => c.path },
|
|
434
|
-
{ header: 'from', value: (c) => truncate(JSON.stringify(c.from ?? null), 40) },
|
|
435
|
-
{ header: 'to', value: (c) => truncate(JSON.stringify(c.to ?? null), 40) },
|
|
436
|
-
]);
|
|
437
|
-
}
|
package/dist/commands/org.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { WjiClient } from '../core/client.js';
|
|
3
|
-
import { updateProfile } from '../core/config.js';
|
|
4
|
-
import { color, detail, info, render, success, table } from '../core/output.js';
|
|
5
|
-
/**
|
|
6
|
-
* Organization context is a request header (X-Org-Id), not a login. Selecting
|
|
7
|
-
* one here just stores it in the profile; every later call carries it.
|
|
8
|
-
*/
|
|
9
|
-
export function orgCommand(globals) {
|
|
10
|
-
const org = new Command('org').description('Switch organization context (X-Org-Id)');
|
|
11
|
-
org
|
|
12
|
-
.command('list', { isDefault: true })
|
|
13
|
-
.description('List organizations you belong to')
|
|
14
|
-
.action(async () => {
|
|
15
|
-
const client = new WjiClient(globals());
|
|
16
|
-
const memberships = await client.get('/organization/mine');
|
|
17
|
-
render(memberships, (rows) => table(rows || [], [
|
|
18
|
-
{
|
|
19
|
-
header: '',
|
|
20
|
-
value: (m) => m.organization?.id === client.orgId ? color.green('*') : ' ',
|
|
21
|
-
},
|
|
22
|
-
{ header: 'id', value: (m) => m.organization?.id },
|
|
23
|
-
{ header: 'name', value: (m) => m.organization?.name },
|
|
24
|
-
{ header: 'role', value: (m) => m.role },
|
|
25
|
-
{ header: 'status', value: (m) => m.status },
|
|
26
|
-
{ header: 'org status', value: (m) => m.organization?.status },
|
|
27
|
-
]));
|
|
28
|
-
});
|
|
29
|
-
org
|
|
30
|
-
.command('use <orgId>')
|
|
31
|
-
.description('Make this organization the default context')
|
|
32
|
-
.action(async (orgId) => {
|
|
33
|
-
updateProfile(globals().profile, { orgId });
|
|
34
|
-
success(`Org context set to ${orgId}`);
|
|
35
|
-
info(color.dim('Use `wji org personal` to go back to your personal context.'));
|
|
36
|
-
});
|
|
37
|
-
org
|
|
38
|
-
.command('personal')
|
|
39
|
-
.description('Clear the organization context')
|
|
40
|
-
.action(() => {
|
|
41
|
-
updateProfile(globals().profile, { orgId: null });
|
|
42
|
-
success('Switched to personal context');
|
|
43
|
-
});
|
|
44
|
-
org
|
|
45
|
-
.command('current')
|
|
46
|
-
.description('Show the member record for the active org context')
|
|
47
|
-
.action(async () => {
|
|
48
|
-
const client = new WjiClient(globals());
|
|
49
|
-
if (!client.orgId)
|
|
50
|
-
return info('Personal context (no organization)');
|
|
51
|
-
const me = await client.get('/organization/me');
|
|
52
|
-
render(me, (m) => detail([
|
|
53
|
-
['org', m.organization?.name],
|
|
54
|
-
['orgId', m.organization?.id],
|
|
55
|
-
['role', m.role],
|
|
56
|
-
['status', m.status],
|
|
57
|
-
['monthlyLimit', m.monthlyLimit],
|
|
58
|
-
['permanentLimit', m.permanentLimit],
|
|
59
|
-
]));
|
|
60
|
-
});
|
|
61
|
-
org
|
|
62
|
-
.command('members')
|
|
63
|
-
.description('List members of the active org context')
|
|
64
|
-
.action(async () => {
|
|
65
|
-
const client = new WjiClient(globals());
|
|
66
|
-
const members = await client.get('/organization/members');
|
|
67
|
-
render(members, (rows) => table(rows || [], [
|
|
68
|
-
{ header: 'id', value: (m) => m.id },
|
|
69
|
-
{ header: 'user', value: (m) => m.user?.id },
|
|
70
|
-
{ header: 'name', value: (m) => m.user?.name },
|
|
71
|
-
{ header: 'email', value: (m) => m.user?.email },
|
|
72
|
-
{ header: 'role', value: (m) => m.role },
|
|
73
|
-
{ header: 'status', value: (m) => m.status },
|
|
74
|
-
]));
|
|
75
|
-
});
|
|
76
|
-
org
|
|
77
|
-
.command('create <name>')
|
|
78
|
-
.description('Create an organization')
|
|
79
|
-
.action(async (name) => {
|
|
80
|
-
const client = new WjiClient(globals());
|
|
81
|
-
const created = await client.post('/organization/create', { name });
|
|
82
|
-
render(created, (o) => success(`Created organization ${o.name} (${o.id})`));
|
|
83
|
-
});
|
|
84
|
-
return org;
|
|
85
|
-
}
|