@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.
@@ -0,0 +1,445 @@
1
+ /**
2
+ * HTTP client for the display.dev API.
3
+ * Used by the stdio MCP server to proxy tool calls to the REST API.
4
+ */ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
5
+ try {
6
+ var info = gen[key](arg);
7
+ var value = info.value;
8
+ } catch (error) {
9
+ reject(error);
10
+ return;
11
+ }
12
+ if (info.done) {
13
+ resolve(value);
14
+ } else {
15
+ Promise.resolve(value).then(_next, _throw);
16
+ }
17
+ }
18
+ function _async_to_generator(fn) {
19
+ return function() {
20
+ var self = this, args = arguments;
21
+ return new Promise(function(resolve, reject) {
22
+ var gen = fn.apply(self, args);
23
+ function _next(value) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
25
+ }
26
+ function _throw(err) {
27
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
28
+ }
29
+ _next(undefined);
30
+ });
31
+ };
32
+ }
33
+ function _class_call_check(instance, Constructor) {
34
+ if (!(instance instanceof Constructor)) {
35
+ throw new TypeError("Cannot call a class as a function");
36
+ }
37
+ }
38
+ function _defineProperties(target, props) {
39
+ for(var i = 0; i < props.length; i++){
40
+ var descriptor = props[i];
41
+ descriptor.enumerable = descriptor.enumerable || false;
42
+ descriptor.configurable = true;
43
+ if ("value" in descriptor) descriptor.writable = true;
44
+ Object.defineProperty(target, descriptor.key, descriptor);
45
+ }
46
+ }
47
+ function _create_class(Constructor, protoProps, staticProps) {
48
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
49
+ if (staticProps) _defineProperties(Constructor, staticProps);
50
+ return Constructor;
51
+ }
52
+ function _define_property(obj, key, value) {
53
+ if (key in obj) {
54
+ Object.defineProperty(obj, key, {
55
+ value: value,
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true
59
+ });
60
+ } else {
61
+ obj[key] = value;
62
+ }
63
+ return obj;
64
+ }
65
+ function _instanceof(left, right) {
66
+ "@swc/helpers - instanceof";
67
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
68
+ return !!right[Symbol.hasInstance](left);
69
+ } else {
70
+ return left instanceof right;
71
+ }
72
+ }
73
+ function _object_spread(target) {
74
+ for(var i = 1; i < arguments.length; i++){
75
+ var source = arguments[i] != null ? arguments[i] : {};
76
+ var ownKeys = Object.keys(source);
77
+ if (typeof Object.getOwnPropertySymbols === "function") {
78
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
79
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
80
+ }));
81
+ }
82
+ ownKeys.forEach(function(key) {
83
+ _define_property(target, key, source[key]);
84
+ });
85
+ }
86
+ return target;
87
+ }
88
+ function _ts_generator(thisArg, body) {
89
+ var f, y, t, _ = {
90
+ label: 0,
91
+ sent: function() {
92
+ if (t[0] & 1) throw t[1];
93
+ return t[1];
94
+ },
95
+ trys: [],
96
+ ops: []
97
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
98
+ return d(g, "next", {
99
+ value: verb(0)
100
+ }), d(g, "throw", {
101
+ value: verb(1)
102
+ }), d(g, "return", {
103
+ value: verb(2)
104
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
105
+ value: function() {
106
+ return this;
107
+ }
108
+ }), g;
109
+ function verb(n) {
110
+ return function(v) {
111
+ return step([
112
+ n,
113
+ v
114
+ ]);
115
+ };
116
+ }
117
+ function step(op) {
118
+ if (f) throw new TypeError("Generator is already executing.");
119
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
120
+ 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;
121
+ if (y = 0, t) op = [
122
+ op[0] & 2,
123
+ t.value
124
+ ];
125
+ switch(op[0]){
126
+ case 0:
127
+ case 1:
128
+ t = op;
129
+ break;
130
+ case 4:
131
+ _.label++;
132
+ return {
133
+ value: op[1],
134
+ done: false
135
+ };
136
+ case 5:
137
+ _.label++;
138
+ y = op[1];
139
+ op = [
140
+ 0
141
+ ];
142
+ continue;
143
+ case 7:
144
+ op = _.ops.pop();
145
+ _.trys.pop();
146
+ continue;
147
+ default:
148
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
149
+ _ = 0;
150
+ continue;
151
+ }
152
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
153
+ _.label = op[1];
154
+ break;
155
+ }
156
+ if (op[0] === 6 && _.label < t[1]) {
157
+ _.label = t[1];
158
+ t = op;
159
+ break;
160
+ }
161
+ if (t && _.label < t[2]) {
162
+ _.label = t[2];
163
+ _.ops.push(op);
164
+ break;
165
+ }
166
+ if (t[2]) _.ops.pop();
167
+ _.trys.pop();
168
+ continue;
169
+ }
170
+ op = body.call(thisArg, _);
171
+ } catch (e) {
172
+ op = [
173
+ 6,
174
+ e
175
+ ];
176
+ y = 0;
177
+ } finally{
178
+ f = t = 0;
179
+ }
180
+ if (op[0] & 5) throw op[1];
181
+ return {
182
+ value: op[0] ? op[1] : void 0,
183
+ done: true
184
+ };
185
+ }
186
+ }
187
+ export var ApiClient = /*#__PURE__*/ function() {
188
+ "use strict";
189
+ function ApiClient(config) {
190
+ _class_call_check(this, ApiClient);
191
+ var _config_clientType;
192
+ _define_property(this, "baseUrl", void 0);
193
+ _define_property(this, "apiKey", void 0);
194
+ _define_property(this, "clientType", void 0);
195
+ this.baseUrl = config.baseUrl.replace(/\/$/, '');
196
+ this.apiKey = config.apiKey;
197
+ this.clientType = (_config_clientType = config.clientType) !== null && _config_clientType !== void 0 ? _config_clientType : 'mcp-stdio';
198
+ }
199
+ _create_class(ApiClient, [
200
+ {
201
+ key: "publish",
202
+ value: function publish(params) {
203
+ return _async_to_generator(function() {
204
+ return _ts_generator(this, function(_state) {
205
+ return [
206
+ 2,
207
+ this.request('POST', '/v1/artifacts', this.buildPublishForm(params))
208
+ ];
209
+ });
210
+ }).call(this);
211
+ }
212
+ },
213
+ {
214
+ key: "publishVersion",
215
+ value: function publishVersion(shortId, params) {
216
+ return _async_to_generator(function() {
217
+ return _ts_generator(this, function(_state) {
218
+ return [
219
+ 2,
220
+ this.request('PUT', "/v1/artifacts/".concat(shortId), this.buildPublishForm(params))
221
+ ];
222
+ });
223
+ }).call(this);
224
+ }
225
+ },
226
+ {
227
+ key: "buildPublishForm",
228
+ value: function buildPublishForm(params) {
229
+ var ext = params.format === 'md' ? '.md' : '.html';
230
+ var blob = new Blob([
231
+ params.content
232
+ ], {
233
+ type: 'application/octet-stream'
234
+ });
235
+ var form = new FormData();
236
+ form.append('file', blob, "content".concat(ext));
237
+ if (params.name) {
238
+ form.append('name', params.name);
239
+ }
240
+ if (params.theme) {
241
+ form.append('theme', params.theme);
242
+ }
243
+ if (params.visibility) {
244
+ form.append('visibility', params.visibility);
245
+ }
246
+ if (params.share) {
247
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
248
+ try {
249
+ for(var _iterator = params.share[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
250
+ var email = _step.value;
251
+ form.append('guestEmails', email);
252
+ }
253
+ } catch (err) {
254
+ _didIteratorError = true;
255
+ _iteratorError = err;
256
+ } finally{
257
+ try {
258
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
259
+ _iterator.return();
260
+ }
261
+ } finally{
262
+ if (_didIteratorError) {
263
+ throw _iteratorError;
264
+ }
265
+ }
266
+ }
267
+ }
268
+ return form;
269
+ }
270
+ },
271
+ {
272
+ key: "find",
273
+ value: function find(params) {
274
+ return _async_to_generator(function() {
275
+ var searchParams, qs;
276
+ return _ts_generator(this, function(_state) {
277
+ searchParams = new URLSearchParams();
278
+ if (params.query) {
279
+ searchParams.set('q', params.query);
280
+ }
281
+ if (params.published_by) {
282
+ searchParams.set('published_by', params.published_by);
283
+ }
284
+ if (params.since) {
285
+ searchParams.set('since', params.since);
286
+ }
287
+ if (params.limit) {
288
+ searchParams.set('limit', String(params.limit));
289
+ }
290
+ qs = searchParams.toString();
291
+ return [
292
+ 2,
293
+ this.request('GET', "/v1/artifacts".concat(qs ? "?".concat(qs) : ''))
294
+ ];
295
+ });
296
+ }).call(this);
297
+ }
298
+ },
299
+ {
300
+ key: "get",
301
+ value: function get(shortId, include) {
302
+ return _async_to_generator(function() {
303
+ var qs;
304
+ return _ts_generator(this, function(_state) {
305
+ qs = (include === null || include === void 0 ? void 0 : include.length) ? "?include=".concat(include.join(',')) : '';
306
+ return [
307
+ 2,
308
+ this.request('GET', "/v1/artifacts/".concat(shortId).concat(qs))
309
+ ];
310
+ });
311
+ }).call(this);
312
+ }
313
+ },
314
+ {
315
+ key: "delete",
316
+ value: function _delete(shortId) {
317
+ return _async_to_generator(function() {
318
+ return _ts_generator(this, function(_state) {
319
+ return [
320
+ 2,
321
+ this.request('DELETE', "/v1/artifacts/".concat(shortId))
322
+ ];
323
+ });
324
+ }).call(this);
325
+ }
326
+ },
327
+ {
328
+ key: "sendOtp",
329
+ value: function sendOtp(email) {
330
+ return _async_to_generator(function() {
331
+ return _ts_generator(this, function(_state) {
332
+ return [
333
+ 2,
334
+ this.requestNoAuth('POST', '/api/auth/email-otp/send-verification-otp', {
335
+ email: email,
336
+ type: 'sign-in'
337
+ })
338
+ ];
339
+ });
340
+ }).call(this);
341
+ }
342
+ },
343
+ {
344
+ key: "verifyOtp",
345
+ value: function verifyOtp(email, otp) {
346
+ return _async_to_generator(function() {
347
+ return _ts_generator(this, function(_state) {
348
+ return [
349
+ 2,
350
+ this.requestNoAuth('POST', '/api/auth/sign-in/email-otp', {
351
+ email: email,
352
+ otp: otp
353
+ })
354
+ ];
355
+ });
356
+ }).call(this);
357
+ }
358
+ },
359
+ {
360
+ key: "request",
361
+ value: function request(method, path, body) {
362
+ return _async_to_generator(function() {
363
+ return _ts_generator(this, function(_state) {
364
+ return [
365
+ 2,
366
+ this.doFetch(method, path, body, {
367
+ 'Authorization': "Bearer ".concat(this.apiKey),
368
+ 'X-Client-Type': this.clientType
369
+ })
370
+ ];
371
+ });
372
+ }).call(this);
373
+ }
374
+ },
375
+ {
376
+ key: "requestNoAuth",
377
+ value: function requestNoAuth(method, path, body) {
378
+ return _async_to_generator(function() {
379
+ return _ts_generator(this, function(_state) {
380
+ return [
381
+ 2,
382
+ this.doFetch(method, path, body, {
383
+ 'X-Client-Type': this.clientType
384
+ })
385
+ ];
386
+ });
387
+ }).call(this);
388
+ }
389
+ },
390
+ {
391
+ key: "doFetch",
392
+ value: function doFetch(method, path, body, headers) {
393
+ return _async_to_generator(function() {
394
+ var url, init, res, _parsed_message, text, parsed;
395
+ return _ts_generator(this, function(_state) {
396
+ switch(_state.label){
397
+ case 0:
398
+ url = "".concat(this.baseUrl).concat(path);
399
+ init = {
400
+ method: method,
401
+ headers: _object_spread({}, headers)
402
+ };
403
+ if (_instanceof(body, FormData)) {
404
+ init.body = body;
405
+ } else if (body) {
406
+ init.headers['Content-Type'] = 'application/json';
407
+ init.body = JSON.stringify(body);
408
+ }
409
+ return [
410
+ 4,
411
+ fetch(url, init)
412
+ ];
413
+ case 1:
414
+ res = _state.sent();
415
+ if (!!res.ok) return [
416
+ 3,
417
+ 3
418
+ ];
419
+ return [
420
+ 4,
421
+ res.text()
422
+ ];
423
+ case 2:
424
+ text = _state.sent();
425
+ try {
426
+ parsed = JSON.parse(text);
427
+ } catch (unused) {
428
+ parsed = {
429
+ message: text
430
+ };
431
+ }
432
+ throw new Error((_parsed_message = parsed.message) !== null && _parsed_message !== void 0 ? _parsed_message : "API error ".concat(res.status));
433
+ case 3:
434
+ return [
435
+ 2,
436
+ res.json()
437
+ ];
438
+ }
439
+ });
440
+ }).call(this);
441
+ }
442
+ }
443
+ ]);
444
+ return ApiClient;
445
+ }();