@displaydev/cli 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/dist/main.js ADDED
@@ -0,0 +1,572 @@
1
+ #!/usr/bin/env node
2
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3
+ try {
4
+ var info = gen[key](arg);
5
+ var value = info.value;
6
+ } catch (error) {
7
+ reject(error);
8
+ return;
9
+ }
10
+ if (info.done) {
11
+ resolve(value);
12
+ } else {
13
+ Promise.resolve(value).then(_next, _throw);
14
+ }
15
+ }
16
+ function _async_to_generator(fn) {
17
+ return function() {
18
+ var self = this, args = arguments;
19
+ return new Promise(function(resolve, reject) {
20
+ var gen = fn.apply(self, args);
21
+ function _next(value) {
22
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
+ }
24
+ function _throw(err) {
25
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
26
+ }
27
+ _next(undefined);
28
+ });
29
+ };
30
+ }
31
+ function _ts_generator(thisArg, body) {
32
+ var f, y, t, _ = {
33
+ label: 0,
34
+ sent: function() {
35
+ if (t[0] & 1) throw t[1];
36
+ return t[1];
37
+ },
38
+ trys: [],
39
+ ops: []
40
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
41
+ return d(g, "next", {
42
+ value: verb(0)
43
+ }), d(g, "throw", {
44
+ value: verb(1)
45
+ }), d(g, "return", {
46
+ value: verb(2)
47
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
48
+ value: function() {
49
+ return this;
50
+ }
51
+ }), g;
52
+ function verb(n) {
53
+ return function(v) {
54
+ return step([
55
+ n,
56
+ v
57
+ ]);
58
+ };
59
+ }
60
+ function step(op) {
61
+ if (f) throw new TypeError("Generator is already executing.");
62
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
63
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
+ if (y = 0, t) op = [
65
+ op[0] & 2,
66
+ t.value
67
+ ];
68
+ switch(op[0]){
69
+ case 0:
70
+ case 1:
71
+ t = op;
72
+ break;
73
+ case 4:
74
+ _.label++;
75
+ return {
76
+ value: op[1],
77
+ done: false
78
+ };
79
+ case 5:
80
+ _.label++;
81
+ y = op[1];
82
+ op = [
83
+ 0
84
+ ];
85
+ continue;
86
+ case 7:
87
+ op = _.ops.pop();
88
+ _.trys.pop();
89
+ continue;
90
+ default:
91
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
92
+ _ = 0;
93
+ continue;
94
+ }
95
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
96
+ _.label = op[1];
97
+ break;
98
+ }
99
+ if (op[0] === 6 && _.label < t[1]) {
100
+ _.label = t[1];
101
+ t = op;
102
+ break;
103
+ }
104
+ if (t && _.label < t[2]) {
105
+ _.label = t[2];
106
+ _.ops.push(op);
107
+ break;
108
+ }
109
+ if (t[2]) _.ops.pop();
110
+ _.trys.pop();
111
+ continue;
112
+ }
113
+ op = body.call(thisArg, _);
114
+ } catch (e) {
115
+ op = [
116
+ 6,
117
+ e
118
+ ];
119
+ y = 0;
120
+ } finally{
121
+ f = t = 0;
122
+ }
123
+ if (op[0] & 5) throw op[1];
124
+ return {
125
+ value: op[0] ? op[1] : void 0,
126
+ done: true
127
+ };
128
+ }
129
+ }
130
+ import { readFile, mkdir, writeFile, rename, chmod } from 'node:fs/promises';
131
+ import { createInterface } from 'node:readline/promises';
132
+ import { homedir } from 'node:os';
133
+ import { join, extname } from 'node:path';
134
+ import { Command } from 'commander';
135
+ import { ApiClient } from './api-client.js';
136
+ import { startMcpServer } from './mcp-server.js';
137
+ var DEFAULT_API_URL = 'https://api.display.dev';
138
+ var CONFIG_DIR = join(homedir(), '.display');
139
+ var CONFIG_PATH = join(CONFIG_DIR, 'config.json');
140
+ function loadConfig() {
141
+ return _async_to_generator(function() {
142
+ var raw, unused;
143
+ return _ts_generator(this, function(_state) {
144
+ switch(_state.label){
145
+ case 0:
146
+ _state.trys.push([
147
+ 0,
148
+ 2,
149
+ ,
150
+ 3
151
+ ]);
152
+ return [
153
+ 4,
154
+ readFile(CONFIG_PATH, 'utf-8')
155
+ ];
156
+ case 1:
157
+ raw = _state.sent();
158
+ return [
159
+ 2,
160
+ JSON.parse(raw)
161
+ ];
162
+ case 2:
163
+ unused = _state.sent();
164
+ return [
165
+ 2,
166
+ null
167
+ ];
168
+ case 3:
169
+ return [
170
+ 2
171
+ ];
172
+ }
173
+ });
174
+ })();
175
+ }
176
+ function saveConfig(config) {
177
+ return _async_to_generator(function() {
178
+ var tmpPath;
179
+ return _ts_generator(this, function(_state) {
180
+ switch(_state.label){
181
+ case 0:
182
+ return [
183
+ 4,
184
+ mkdir(CONFIG_DIR, {
185
+ recursive: true
186
+ })
187
+ ];
188
+ case 1:
189
+ _state.sent();
190
+ tmpPath = "".concat(CONFIG_PATH, ".tmp");
191
+ return [
192
+ 4,
193
+ writeFile(tmpPath, "".concat(JSON.stringify(config, null, 2), "\n"), {
194
+ mode: 384
195
+ })
196
+ ];
197
+ case 2:
198
+ _state.sent();
199
+ return [
200
+ 4,
201
+ rename(tmpPath, CONFIG_PATH)
202
+ ];
203
+ case 3:
204
+ _state.sent();
205
+ return [
206
+ 4,
207
+ chmod(CONFIG_PATH, 384)
208
+ ];
209
+ case 4:
210
+ _state.sent();
211
+ return [
212
+ 2
213
+ ];
214
+ }
215
+ });
216
+ })();
217
+ }
218
+ function resolveAuth() {
219
+ var apiKey = process.env.DISPLAY_API_KEY;
220
+ if (apiKey) {
221
+ var _process_env_DISPLAY_API_URL;
222
+ return {
223
+ apiKey: apiKey,
224
+ apiUrl: (_process_env_DISPLAY_API_URL = process.env.DISPLAY_API_URL) !== null && _process_env_DISPLAY_API_URL !== void 0 ? _process_env_DISPLAY_API_URL : DEFAULT_API_URL
225
+ };
226
+ }
227
+ return null;
228
+ }
229
+ function resolveAuthOrConfig() {
230
+ return _async_to_generator(function() {
231
+ var env, config, _config_apiUrl;
232
+ return _ts_generator(this, function(_state) {
233
+ switch(_state.label){
234
+ case 0:
235
+ env = resolveAuth();
236
+ if (env) {
237
+ return [
238
+ 2,
239
+ env
240
+ ];
241
+ }
242
+ return [
243
+ 4,
244
+ loadConfig()
245
+ ];
246
+ case 1:
247
+ config = _state.sent();
248
+ if (config === null || config === void 0 ? void 0 : config.token) {
249
+ ;
250
+ return [
251
+ 2,
252
+ {
253
+ apiKey: config.token,
254
+ apiUrl: (_config_apiUrl = config.apiUrl) !== null && _config_apiUrl !== void 0 ? _config_apiUrl : DEFAULT_API_URL
255
+ }
256
+ ];
257
+ }
258
+ console.error('Not authenticated. Set DISPLAY_API_KEY or run: dsp login');
259
+ process.exit(1);
260
+ return [
261
+ 2
262
+ ];
263
+ }
264
+ });
265
+ })();
266
+ }
267
+ function createClient(auth) {
268
+ return new ApiClient({
269
+ baseUrl: auth.apiUrl,
270
+ apiKey: auth.apiKey,
271
+ clientType: 'cli'
272
+ });
273
+ }
274
+ var program = new Command().name('dsp').description('display.dev CLI — publish artifacts behind company auth').version('0.0.0');
275
+ function collectEmails(value, prev) {
276
+ return prev.concat(value);
277
+ }
278
+ // --- publish ---
279
+ program.command('publish <path>').description('Publish an HTML or Markdown file').option('--name <name>', 'Artifact display name').option('--id <shortId>', 'Update existing artifact (new version)').option('--public', 'Make artifact publicly accessible').option('--share <email>', 'Share with guest email (repeatable)', collectEmails, []).option('--theme <theme>', 'Markdown theme (default: github)').action(function(filePath, opts) {
280
+ return _async_to_generator(function() {
281
+ var auth, client, ext, content, format, visibility, share, result, verb;
282
+ return _ts_generator(this, function(_state) {
283
+ switch(_state.label){
284
+ case 0:
285
+ if (!opts.id && !opts.name) {
286
+ console.error('--name is required for new artifacts. Use --id to update an existing one.');
287
+ process.exit(1);
288
+ }
289
+ return [
290
+ 4,
291
+ resolveAuthOrConfig()
292
+ ];
293
+ case 1:
294
+ auth = _state.sent();
295
+ client = createClient(auth);
296
+ ext = extname(filePath).toLowerCase();
297
+ if (ext !== '.html' && ext !== '.md') {
298
+ console.error("Unsupported file type: ".concat(ext, " (expected .html or .md)"));
299
+ process.exit(1);
300
+ }
301
+ return [
302
+ 4,
303
+ readFile(filePath, 'utf-8')
304
+ ];
305
+ case 2:
306
+ content = _state.sent();
307
+ format = ext === '.md' ? 'md' : 'html';
308
+ visibility = opts.public ? 'public' : undefined;
309
+ share = opts.share.length > 0 ? opts.share : undefined;
310
+ if (!opts.id) return [
311
+ 3,
312
+ 4
313
+ ];
314
+ return [
315
+ 4,
316
+ client.publishVersion(opts.id, {
317
+ content: content,
318
+ format: format,
319
+ name: opts.name,
320
+ theme: opts.theme,
321
+ share: share,
322
+ visibility: visibility
323
+ })
324
+ ];
325
+ case 3:
326
+ result = _state.sent();
327
+ return [
328
+ 3,
329
+ 6
330
+ ];
331
+ case 4:
332
+ return [
333
+ 4,
334
+ client.publish({
335
+ content: content,
336
+ name: opts.name,
337
+ format: format,
338
+ theme: opts.theme,
339
+ share: share,
340
+ visibility: visibility
341
+ })
342
+ ];
343
+ case 5:
344
+ result = _state.sent();
345
+ _state.label = 6;
346
+ case 6:
347
+ console.log(result.url);
348
+ verb = opts.id ? 'Updated' : 'Published';
349
+ console.log("".concat(verb, " ").concat(result.name, " (").concat(result.shortId, ") v").concat(result.version));
350
+ return [
351
+ 2
352
+ ];
353
+ }
354
+ });
355
+ })();
356
+ });
357
+ // --- find ---
358
+ program.command('find [query]').description('Search for artifacts').option('--by <email>', 'Filter by publisher email').option('--since <date>', 'Filter by date (ISO format)').action(function(query, opts) {
359
+ return _async_to_generator(function() {
360
+ var auth, client, results, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, a;
361
+ return _ts_generator(this, function(_state) {
362
+ switch(_state.label){
363
+ case 0:
364
+ return [
365
+ 4,
366
+ resolveAuthOrConfig()
367
+ ];
368
+ case 1:
369
+ auth = _state.sent();
370
+ client = createClient(auth);
371
+ return [
372
+ 4,
373
+ client.find({
374
+ query: query,
375
+ published_by: opts.by,
376
+ since: opts.since
377
+ })
378
+ ];
379
+ case 2:
380
+ results = _state.sent();
381
+ if (results.length === 0) {
382
+ console.log('No artifacts found.');
383
+ return [
384
+ 2
385
+ ];
386
+ }
387
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
388
+ try {
389
+ for(_iterator = results[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
390
+ a = _step.value;
391
+ console.log("".concat(a.shortId, " v").concat(a.currentVersion, " ").concat(a.name, " ").concat(a.url));
392
+ }
393
+ } catch (err) {
394
+ _didIteratorError = true;
395
+ _iteratorError = err;
396
+ } finally{
397
+ try {
398
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
399
+ _iterator.return();
400
+ }
401
+ } finally{
402
+ if (_didIteratorError) {
403
+ throw _iteratorError;
404
+ }
405
+ }
406
+ }
407
+ return [
408
+ 2
409
+ ];
410
+ }
411
+ });
412
+ })();
413
+ });
414
+ // --- get ---
415
+ program.command('get <shortId>').description('Get artifact details').option('--include <field>', 'Include additional data (repeatable, e.g. versions)', collectEmails, []).action(function(shortId, opts) {
416
+ return _async_to_generator(function() {
417
+ var auth, client, result;
418
+ return _ts_generator(this, function(_state) {
419
+ switch(_state.label){
420
+ case 0:
421
+ return [
422
+ 4,
423
+ resolveAuthOrConfig()
424
+ ];
425
+ case 1:
426
+ auth = _state.sent();
427
+ client = createClient(auth);
428
+ return [
429
+ 4,
430
+ client.get(shortId, opts.include.length > 0 ? opts.include : undefined)
431
+ ];
432
+ case 2:
433
+ result = _state.sent();
434
+ console.log(JSON.stringify(result, null, 2));
435
+ return [
436
+ 2
437
+ ];
438
+ }
439
+ });
440
+ })();
441
+ });
442
+ // --- delete ---
443
+ program.command('delete <shortId>').description('Delete an artifact permanently').option('--confirm', 'Confirm deletion').action(function(shortId, opts) {
444
+ return _async_to_generator(function() {
445
+ var auth, client, result;
446
+ return _ts_generator(this, function(_state) {
447
+ switch(_state.label){
448
+ case 0:
449
+ if (!opts.confirm) {
450
+ console.error('Pass --confirm to delete permanently.');
451
+ process.exit(1);
452
+ }
453
+ return [
454
+ 4,
455
+ resolveAuthOrConfig()
456
+ ];
457
+ case 1:
458
+ auth = _state.sent();
459
+ client = createClient(auth);
460
+ return [
461
+ 4,
462
+ client.delete(shortId)
463
+ ];
464
+ case 2:
465
+ result = _state.sent();
466
+ console.log("Deleted ".concat(result.name, " (").concat(result.shortId, ")"));
467
+ return [
468
+ 2
469
+ ];
470
+ }
471
+ });
472
+ })();
473
+ });
474
+ // --- login ---
475
+ program.command('login').description('Authenticate with display.dev via email OTP').option('--email <email>', 'Email address').action(function(opts) {
476
+ return _async_to_generator(function() {
477
+ var _process_env_DISPLAY_API_URL, apiUrl, client, rl, email, code, result;
478
+ return _ts_generator(this, function(_state) {
479
+ switch(_state.label){
480
+ case 0:
481
+ apiUrl = (_process_env_DISPLAY_API_URL = process.env.DISPLAY_API_URL) !== null && _process_env_DISPLAY_API_URL !== void 0 ? _process_env_DISPLAY_API_URL : DEFAULT_API_URL;
482
+ client = new ApiClient({
483
+ baseUrl: apiUrl,
484
+ apiKey: '',
485
+ clientType: 'cli'
486
+ });
487
+ rl = createInterface({
488
+ input: process.stdin,
489
+ output: process.stdout
490
+ });
491
+ email = opts.email;
492
+ if (!!email) return [
493
+ 3,
494
+ 2
495
+ ];
496
+ return [
497
+ 4,
498
+ rl.question('Email: ')
499
+ ];
500
+ case 1:
501
+ email = _state.sent();
502
+ _state.label = 2;
503
+ case 2:
504
+ return [
505
+ 4,
506
+ client.sendOtp(email)
507
+ ];
508
+ case 3:
509
+ _state.sent();
510
+ console.log("Code sent to ".concat(email));
511
+ return [
512
+ 4,
513
+ rl.question('Enter the 6-digit code: ')
514
+ ];
515
+ case 4:
516
+ code = _state.sent();
517
+ rl.close();
518
+ return [
519
+ 4,
520
+ client.verifyOtp(email, code.trim())
521
+ ];
522
+ case 5:
523
+ result = _state.sent();
524
+ return [
525
+ 4,
526
+ saveConfig({
527
+ token: result.token,
528
+ apiUrl: apiUrl
529
+ })
530
+ ];
531
+ case 6:
532
+ _state.sent();
533
+ console.log("Logged in as ".concat(email));
534
+ return [
535
+ 2
536
+ ];
537
+ }
538
+ });
539
+ })();
540
+ });
541
+ // --- mcp ---
542
+ program.command('mcp').description('Start MCP server over stdin/stdout').action(function() {
543
+ return _async_to_generator(function() {
544
+ var auth, client;
545
+ return _ts_generator(this, function(_state) {
546
+ switch(_state.label){
547
+ case 0:
548
+ return [
549
+ 4,
550
+ resolveAuthOrConfig()
551
+ ];
552
+ case 1:
553
+ auth = _state.sent();
554
+ client = new ApiClient({
555
+ baseUrl: auth.apiUrl,
556
+ apiKey: auth.apiKey,
557
+ clientType: 'mcp-stdio'
558
+ });
559
+ return [
560
+ 4,
561
+ startMcpServer(client)
562
+ ];
563
+ case 2:
564
+ _state.sent();
565
+ return [
566
+ 2
567
+ ];
568
+ }
569
+ });
570
+ })();
571
+ });
572
+ program.parse();