@edhspace/api 0.0.0-stage → 0.2.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 +14 -0
- package/README.md +43 -2
- package/dist/chunk-4STXB3BK.js +160 -0
- package/dist/chunk-F72S63D3.cjs +160 -0
- package/dist/chunk-HL56LR6P.cjs +311 -0
- package/dist/chunk-LBLXK5J2.js +311 -0
- package/dist/client-CSAi6AFj.d.ts +136 -0
- package/dist/client-DKX6ZfiJ.d.cts +136 -0
- package/dist/contracts-r8d4RACz.d.cts +474 -0
- package/dist/contracts-r8d4RACz.d.ts +474 -0
- package/dist/host.cjs +356 -0
- package/dist/host.d.cts +57 -0
- package/dist/host.d.ts +57 -0
- package/dist/host.js +356 -0
- package/dist/index.cjs +85 -0
- package/dist/index.d.cts +148 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.js +85 -0
- package/dist/math.cjs +107 -0
- package/dist/math.d.cts +70 -0
- package/dist/math.d.ts +70 -0
- package/dist/math.js +107 -0
- package/dist/react.cjs +69 -0
- package/dist/react.d.cts +177 -0
- package/dist/react.d.ts +177 -0
- package/dist/react.js +69 -0
- package/dist/sideload.cjs +213 -0
- package/dist/sideload.d.cts +290 -0
- package/dist/sideload.d.ts +290 -0
- package/dist/sideload.js +213 -0
- package/package.json +81 -5
package/dist/host.js
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ExtensionError,
|
|
3
|
+
apiVersion,
|
|
4
|
+
extensionManifestSchema,
|
|
5
|
+
maxRequestBytes,
|
|
6
|
+
maxResponseBytes,
|
|
7
|
+
messageBytes,
|
|
8
|
+
methodPermissions,
|
|
9
|
+
networkRequestSchema,
|
|
10
|
+
parseResult,
|
|
11
|
+
protocol,
|
|
12
|
+
requestSchema
|
|
13
|
+
} from "./chunk-LBLXK5J2.js";
|
|
14
|
+
|
|
15
|
+
// src/network.ts
|
|
16
|
+
var sent = /* @__PURE__ */ new Map();
|
|
17
|
+
function abortable(operation, signal) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const abort = () => reject(signal.reason);
|
|
20
|
+
if (signal.aborted) {
|
|
21
|
+
abort();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
25
|
+
operation.then(
|
|
26
|
+
(value) => {
|
|
27
|
+
signal.removeEventListener("abort", abort);
|
|
28
|
+
resolve(value);
|
|
29
|
+
},
|
|
30
|
+
(error) => {
|
|
31
|
+
signal.removeEventListener("abort", abort);
|
|
32
|
+
reject(error);
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function createNetworkHandler(manifest, options) {
|
|
38
|
+
const endpoints = extensionManifestSchema.parse(structuredClone(manifest)).network;
|
|
39
|
+
return async (input, lifetime) => {
|
|
40
|
+
const parsed = networkRequestSchema.safeParse(input);
|
|
41
|
+
if (!parsed.success) throw new ExtensionError("The API request is invalid.", "invalid");
|
|
42
|
+
const request = parsed.data;
|
|
43
|
+
if (messageBytes(request) > maxRequestBytes)
|
|
44
|
+
throw new ExtensionError("The API request exceeds its size limit.", "invalid");
|
|
45
|
+
const endpoint = endpoints.find((entry) => entry.id === request.endpoint);
|
|
46
|
+
if (!endpoint || !endpoint.methods.includes(request.method))
|
|
47
|
+
throw new ExtensionError("This API endpoint or method is not approved.", "denied");
|
|
48
|
+
const url = new URL(request.path, endpoint.url);
|
|
49
|
+
for (const [key, value] of Object.entries(request.query)) url.searchParams.set(key, value);
|
|
50
|
+
const deadline = new AbortController();
|
|
51
|
+
const signal = AbortSignal.any([lifetime, deadline.signal]);
|
|
52
|
+
const approvalTimer = setTimeout(
|
|
53
|
+
() => deadline.abort(new ExtensionError("API request approval timed out.", "timeout")),
|
|
54
|
+
6e4
|
|
55
|
+
);
|
|
56
|
+
let networkTimer;
|
|
57
|
+
try {
|
|
58
|
+
signal.throwIfAborted();
|
|
59
|
+
const allowed = await abortable(
|
|
60
|
+
options.approve(
|
|
61
|
+
structuredClone({
|
|
62
|
+
endpoint: structuredClone(endpoint),
|
|
63
|
+
url: url.href,
|
|
64
|
+
method: request.method,
|
|
65
|
+
query: request.query,
|
|
66
|
+
...request.body !== void 0 ? { body: request.body } : {}
|
|
67
|
+
}),
|
|
68
|
+
signal
|
|
69
|
+
),
|
|
70
|
+
signal
|
|
71
|
+
);
|
|
72
|
+
signal.throwIfAborted();
|
|
73
|
+
clearTimeout(approvalTimer);
|
|
74
|
+
if (!allowed) throw new ExtensionError("The API request was cancelled.", "denied");
|
|
75
|
+
if (!options.fetch && typeof window === "undefined")
|
|
76
|
+
throw new ExtensionError(
|
|
77
|
+
"This host needs a server-safe API transport.",
|
|
78
|
+
"unavailable"
|
|
79
|
+
);
|
|
80
|
+
const now = Date.now();
|
|
81
|
+
for (const [origin, times2] of sent)
|
|
82
|
+
if (times2.every((time) => now - time >= 1e3)) sent.delete(origin);
|
|
83
|
+
const times = sent.get(url.origin) ?? [];
|
|
84
|
+
const recent = times.filter((time) => now - time < 1e3);
|
|
85
|
+
if (recent.length >= 5)
|
|
86
|
+
throw new ExtensionError(
|
|
87
|
+
"This API is receiving too many requests. Try again shortly.",
|
|
88
|
+
"rate-limited"
|
|
89
|
+
);
|
|
90
|
+
sent.set(url.origin, [...recent, now]);
|
|
91
|
+
networkTimer = setTimeout(
|
|
92
|
+
() => deadline.abort(
|
|
93
|
+
new ExtensionError("The external API request timed out.", "timeout")
|
|
94
|
+
),
|
|
95
|
+
1e4
|
|
96
|
+
);
|
|
97
|
+
const response = await abortable(
|
|
98
|
+
(options.fetch ?? fetch)(url.href, {
|
|
99
|
+
method: request.method,
|
|
100
|
+
credentials: "omit",
|
|
101
|
+
redirect: "error",
|
|
102
|
+
referrerPolicy: "no-referrer",
|
|
103
|
+
cache: "no-store",
|
|
104
|
+
headers: request.body === void 0 ? { Accept: "application/json" } : { Accept: "application/json", "Content-Type": "application/json" },
|
|
105
|
+
...request.body !== void 0 ? { body: JSON.stringify(request.body) } : {},
|
|
106
|
+
signal
|
|
107
|
+
}),
|
|
108
|
+
signal
|
|
109
|
+
);
|
|
110
|
+
signal.throwIfAborted();
|
|
111
|
+
if (!response.ok)
|
|
112
|
+
throw new ExtensionError(
|
|
113
|
+
`External API returned HTTP ${response.status}.`,
|
|
114
|
+
response.status === 429 ? "rate-limited" : "unavailable"
|
|
115
|
+
);
|
|
116
|
+
if (!/^(?:application\/json|[^;]+\+json)(?:;|$)/i.test(
|
|
117
|
+
response.headers.get("content-type") ?? ""
|
|
118
|
+
))
|
|
119
|
+
throw new ExtensionError("The external API must return JSON.", "invalid");
|
|
120
|
+
if (!response.body)
|
|
121
|
+
throw new ExtensionError("The external API returned no data.", "invalid");
|
|
122
|
+
const reader = response.body.getReader();
|
|
123
|
+
const chunks = [];
|
|
124
|
+
let bytes = 0;
|
|
125
|
+
try {
|
|
126
|
+
while (true) {
|
|
127
|
+
const chunk = await abortable(reader.read(), signal);
|
|
128
|
+
signal.throwIfAborted();
|
|
129
|
+
if (chunk.done) break;
|
|
130
|
+
bytes += chunk.value.byteLength;
|
|
131
|
+
if (bytes > 131072)
|
|
132
|
+
throw new ExtensionError(
|
|
133
|
+
"The external API response exceeds 128 KiB.",
|
|
134
|
+
"invalid"
|
|
135
|
+
);
|
|
136
|
+
chunks.push(chunk.value);
|
|
137
|
+
}
|
|
138
|
+
} finally {
|
|
139
|
+
try {
|
|
140
|
+
await abortable(reader.cancel(), signal);
|
|
141
|
+
} finally {
|
|
142
|
+
reader.releaseLock();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const buffer = new Uint8Array(bytes);
|
|
146
|
+
let offset = 0;
|
|
147
|
+
for (const chunk of chunks) {
|
|
148
|
+
buffer.set(chunk, offset);
|
|
149
|
+
offset += chunk.byteLength;
|
|
150
|
+
}
|
|
151
|
+
let data;
|
|
152
|
+
try {
|
|
153
|
+
data = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(buffer));
|
|
154
|
+
} catch {
|
|
155
|
+
throw new ExtensionError("The external API returned invalid JSON.", "invalid");
|
|
156
|
+
}
|
|
157
|
+
return parseResult("network.request", { status: response.status, data });
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (lifetime.aborted)
|
|
160
|
+
throw new ExtensionError("Extension access was revoked.", "revoked");
|
|
161
|
+
if (deadline.signal.aborted) throw deadline.signal.reason;
|
|
162
|
+
if (error instanceof ExtensionError) throw error;
|
|
163
|
+
console.error("External API transport failed.", {
|
|
164
|
+
endpoint: endpoint.id,
|
|
165
|
+
method: request.method
|
|
166
|
+
});
|
|
167
|
+
throw new ExtensionError(
|
|
168
|
+
"The API request failed. Check the service and its CORS policy.",
|
|
169
|
+
"unavailable"
|
|
170
|
+
);
|
|
171
|
+
} finally {
|
|
172
|
+
clearTimeout(approvalTimer);
|
|
173
|
+
clearTimeout(networkTimer);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
var NetworkApprovalQueue = class {
|
|
178
|
+
prompts = [];
|
|
179
|
+
listeners = /* @__PURE__ */ new Set();
|
|
180
|
+
remembered = /* @__PURE__ */ new Set();
|
|
181
|
+
pending = /* @__PURE__ */ new Map();
|
|
182
|
+
closed = false;
|
|
183
|
+
subscribe = (listener) => {
|
|
184
|
+
this.listeners.add(listener);
|
|
185
|
+
return () => {
|
|
186
|
+
this.listeners.delete(listener);
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
getSnapshot = () => this.prompts;
|
|
190
|
+
publish() {
|
|
191
|
+
for (const listener of this.listeners) listener();
|
|
192
|
+
}
|
|
193
|
+
approve = (request, signal) => {
|
|
194
|
+
if (this.closed || signal.aborted)
|
|
195
|
+
return Promise.reject(new ExtensionError("API access was revoked.", "revoked"));
|
|
196
|
+
if (request.method === "GET" && this.remembered.has(request.endpoint.url))
|
|
197
|
+
return Promise.resolve(true);
|
|
198
|
+
return new Promise((resolve, reject) => {
|
|
199
|
+
const id = crypto.randomUUID();
|
|
200
|
+
const abort = () => {
|
|
201
|
+
this.remove(id);
|
|
202
|
+
reject(
|
|
203
|
+
signal.reason instanceof ExtensionError ? signal.reason : new ExtensionError("API access was revoked.", "revoked")
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
207
|
+
this.pending.set(id, {
|
|
208
|
+
resolve,
|
|
209
|
+
reject,
|
|
210
|
+
cleanup: () => signal.removeEventListener("abort", abort)
|
|
211
|
+
});
|
|
212
|
+
this.prompts = [...this.prompts, { id, request: structuredClone(request) }];
|
|
213
|
+
this.publish();
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
remove(id) {
|
|
217
|
+
const pending = this.pending.get(id);
|
|
218
|
+
pending?.cleanup();
|
|
219
|
+
this.pending.delete(id);
|
|
220
|
+
this.prompts = this.prompts.filter((prompt) => prompt.id !== id);
|
|
221
|
+
this.publish();
|
|
222
|
+
return pending;
|
|
223
|
+
}
|
|
224
|
+
answer(id, allowed, remember = false) {
|
|
225
|
+
const prompt = this.prompts.find((item) => item.id === id);
|
|
226
|
+
if (allowed && remember && prompt?.request.method === "GET")
|
|
227
|
+
this.remembered.add(prompt.request.endpoint.url);
|
|
228
|
+
this.remove(id)?.resolve(allowed);
|
|
229
|
+
}
|
|
230
|
+
dispose() {
|
|
231
|
+
this.closed = true;
|
|
232
|
+
this.remembered.clear();
|
|
233
|
+
for (const id of [...this.pending.keys()])
|
|
234
|
+
this.remove(id)?.reject(new ExtensionError("API access was revoked.", "revoked"));
|
|
235
|
+
this.listeners.clear();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// src/host.ts
|
|
240
|
+
var ExtensionSession = class {
|
|
241
|
+
constructor(manifest, sessionId, approved, isCurrentResource, handlers, now = Date.now) {
|
|
242
|
+
this.sessionId = sessionId;
|
|
243
|
+
this.isCurrentResource = isCurrentResource;
|
|
244
|
+
this.handlers = handlers;
|
|
245
|
+
this.now = now;
|
|
246
|
+
this.manifest = extensionManifestSchema.parse(structuredClone(manifest));
|
|
247
|
+
if (approved.some((permission) => !this.manifest.permissions.includes(permission)))
|
|
248
|
+
throw new ExtensionError("Cannot grant an undeclared permission.", "denied");
|
|
249
|
+
this.permissions = new Set(approved);
|
|
250
|
+
}
|
|
251
|
+
manifest;
|
|
252
|
+
permissions;
|
|
253
|
+
lifetime = new AbortController();
|
|
254
|
+
seen = /* @__PURE__ */ new Set();
|
|
255
|
+
inFlight = 0;
|
|
256
|
+
windowStart = 0;
|
|
257
|
+
windowRequests = 0;
|
|
258
|
+
revoke() {
|
|
259
|
+
this.lifetime.abort();
|
|
260
|
+
}
|
|
261
|
+
assertCurrent() {
|
|
262
|
+
if (this.lifetime.signal.aborted || !this.isCurrentResource())
|
|
263
|
+
throw new ExtensionError(
|
|
264
|
+
"Extension access has been revoked. Approve access again.",
|
|
265
|
+
"revoked"
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
async execute(raw) {
|
|
269
|
+
const now = this.now();
|
|
270
|
+
if (now - this.windowStart >= 6e4) {
|
|
271
|
+
this.windowStart = now;
|
|
272
|
+
this.windowRequests = 0;
|
|
273
|
+
}
|
|
274
|
+
if (++this.windowRequests > 30)
|
|
275
|
+
throw new ExtensionError("The extension request limit was reached.", "rate-limited");
|
|
276
|
+
if (messageBytes(raw) > maxRequestBytes)
|
|
277
|
+
throw new ExtensionError("The extension request is too large.", "invalid");
|
|
278
|
+
const parsed = requestSchema.safeParse(raw);
|
|
279
|
+
if (!parsed.success)
|
|
280
|
+
throw new ExtensionError("The extension request is invalid.", "invalid");
|
|
281
|
+
const request = parsed.data;
|
|
282
|
+
const base = {
|
|
283
|
+
protocol,
|
|
284
|
+
apiVersion,
|
|
285
|
+
type: "response",
|
|
286
|
+
sessionId: this.sessionId,
|
|
287
|
+
id: request.id
|
|
288
|
+
};
|
|
289
|
+
let running = false;
|
|
290
|
+
try {
|
|
291
|
+
this.assertCurrent();
|
|
292
|
+
if (request.sessionId !== this.sessionId)
|
|
293
|
+
throw new ExtensionError(
|
|
294
|
+
"The request belongs to another extension session.",
|
|
295
|
+
"denied"
|
|
296
|
+
);
|
|
297
|
+
if (this.seen.size >= 256 || this.inFlight >= 4)
|
|
298
|
+
throw new ExtensionError(
|
|
299
|
+
"The extension request limit was reached.",
|
|
300
|
+
"rate-limited"
|
|
301
|
+
);
|
|
302
|
+
if (this.seen.has(request.id))
|
|
303
|
+
throw new ExtensionError(
|
|
304
|
+
"This extension request has already been processed.",
|
|
305
|
+
"replayed"
|
|
306
|
+
);
|
|
307
|
+
this.seen.add(request.id);
|
|
308
|
+
const permission = methodPermissions[request.method];
|
|
309
|
+
if (!this.permissions.has(permission))
|
|
310
|
+
throw new ExtensionError(`Permission required: ${permission}.`, "denied");
|
|
311
|
+
this.inFlight++;
|
|
312
|
+
running = true;
|
|
313
|
+
const result = await this.invoke(request.method, request.params);
|
|
314
|
+
this.assertCurrent();
|
|
315
|
+
const response = {
|
|
316
|
+
...base,
|
|
317
|
+
ok: true,
|
|
318
|
+
result: parseResult(request.method, result)
|
|
319
|
+
};
|
|
320
|
+
if (messageBytes(response) > maxResponseBytes)
|
|
321
|
+
throw new ExtensionError("The extension result exceeds its size limit.", "invalid");
|
|
322
|
+
return response;
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (this.lifetime.signal.aborted)
|
|
325
|
+
error = new ExtensionError(
|
|
326
|
+
"Extension access has been revoked. Approve access again.",
|
|
327
|
+
"revoked"
|
|
328
|
+
);
|
|
329
|
+
if (!(error instanceof ExtensionError)) {
|
|
330
|
+
console.error(`Extension operation failed: ${request.method}.`, error);
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
...base,
|
|
334
|
+
ok: false,
|
|
335
|
+
error: error instanceof ExtensionError ? { code: error.code, message: error.message.slice(0, 300) } : {
|
|
336
|
+
code: "unavailable",
|
|
337
|
+
message: "The extension operation failed. Try again."
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
} finally {
|
|
341
|
+
if (running) this.inFlight--;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async invoke(method, args) {
|
|
345
|
+
const handler = this.handlers[method];
|
|
346
|
+
if (!handler)
|
|
347
|
+
throw new ExtensionError(`This host has not enabled ${method}.`, "unavailable");
|
|
348
|
+
return handler(args, this.lifetime.signal);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
export {
|
|
352
|
+
ExtensionSession,
|
|
353
|
+
NetworkApprovalQueue,
|
|
354
|
+
createNetworkHandler,
|
|
355
|
+
extensionManifestSchema
|
|
356
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkF72S63D3cjs = require('./chunk-F72S63D3.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkHL56LR6Pcjs = require('./chunk-HL56LR6P.cjs');
|
|
12
|
+
|
|
13
|
+
// src/manifest.ts
|
|
14
|
+
var _zod = require('zod');
|
|
15
|
+
var label = _zod.z.string().trim().min(1).max(300);
|
|
16
|
+
var relativeFile = _zod.z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._/-]*$/).refine(
|
|
17
|
+
(value) => !value.includes("..") && !value.includes("//"),
|
|
18
|
+
"Paths must stay inside the extension."
|
|
19
|
+
);
|
|
20
|
+
var panel = _zod.z.strictObject({
|
|
21
|
+
id: _zod.z.string().regex(/^[a-z0-9][a-z0-9-]{0,49}$/),
|
|
22
|
+
title: label,
|
|
23
|
+
entry: relativeFile.refine((value) => value.endsWith(".tsx")),
|
|
24
|
+
location: _zod.z.enum(["workspace", "sidebar"]).default("workspace")
|
|
25
|
+
});
|
|
26
|
+
var extensionPackageSchema = _zod.z.object({
|
|
27
|
+
name: _zod.z.string().regex(/^@edhspace-extension\/[a-z0-9][a-z0-9-]{0,49}$/),
|
|
28
|
+
version: _zod.z.string().regex(/^\d+\.\d+\.\d+$/),
|
|
29
|
+
type: _zod.z.literal("module"),
|
|
30
|
+
title: label,
|
|
31
|
+
description: _zod.z.string().min(1).max(1e3),
|
|
32
|
+
author: label,
|
|
33
|
+
icon: relativeFile.refine((value) => /\.(svg|png)$/.test(value)),
|
|
34
|
+
apiVersion: _zod.z.literal(_chunkHL56LR6Pcjs.apiVersion),
|
|
35
|
+
permissions: _zod.z.array(_chunkHL56LR6Pcjs.permissionSchema),
|
|
36
|
+
panels: _zod.z.array(panel).min(1).max(6),
|
|
37
|
+
commands: _zod.z.array(
|
|
38
|
+
_zod.z.strictObject({
|
|
39
|
+
id: panel.shape.id,
|
|
40
|
+
title: label,
|
|
41
|
+
entry: relativeFile.refine((value) => value.endsWith(".ts"))
|
|
42
|
+
})
|
|
43
|
+
).max(6).default([]),
|
|
44
|
+
preferences: _zod.z.array(_chunkHL56LR6Pcjs.preferenceSchema).max(20).default([]),
|
|
45
|
+
network: _zod.z.array(_chunkHL56LR6Pcjs.networkEndpointSchema).max(8).default([]),
|
|
46
|
+
dependencies: _zod.z.record(_zod.z.string(), _zod.z.string()).default({}),
|
|
47
|
+
peerDependencies: _zod.z.record(_zod.z.string(), _zod.z.string()).default({}),
|
|
48
|
+
devDependencies: _zod.z.record(_zod.z.string(), _zod.z.string()).default({}),
|
|
49
|
+
scripts: _zod.z.record(_zod.z.string(), _zod.z.string()).default({}),
|
|
50
|
+
bin: _zod.z.undefined({ error: "Executable bins are not allowed in extensions." }).optional(),
|
|
51
|
+
exports: _zod.z.strictObject({
|
|
52
|
+
".": _zod.z.strictObject({ types: _zod.z.literal("./dist/index.d.ts"), import: _zod.z.string() }),
|
|
53
|
+
"./package.json": _zod.z.literal("./package.json")
|
|
54
|
+
})
|
|
55
|
+
}).refine(
|
|
56
|
+
(pkg) => pkg.panels[0].entry === "src/index.tsx" && pkg.exports["."].import === `./dist/${pkg.panels[0].id}.js`,
|
|
57
|
+
"The primary panel must use src/index.tsx and export its generated dist artifact."
|
|
58
|
+
).refine((pkg) => {
|
|
59
|
+
const ids = [...pkg.panels, ...pkg.commands].map((entry) => entry.id);
|
|
60
|
+
return new Set(ids).size === ids.length;
|
|
61
|
+
}, "Panel and command IDs must be unique.");
|
|
62
|
+
function toExtensionManifest(value) {
|
|
63
|
+
const pkg = extensionPackageSchema.parse(value);
|
|
64
|
+
return _chunkHL56LR6Pcjs.extensionManifestSchema.parse({
|
|
65
|
+
id: pkg.name.slice(1).replace("/", "."),
|
|
66
|
+
apiVersion: pkg.apiVersion,
|
|
67
|
+
version: pkg.version,
|
|
68
|
+
title: pkg.title,
|
|
69
|
+
description: pkg.description,
|
|
70
|
+
author: pkg.author,
|
|
71
|
+
permissions: pkg.permissions,
|
|
72
|
+
preferences: pkg.preferences,
|
|
73
|
+
panels: pkg.panels.map(({ id, title, location }) => ({ id, title, location })),
|
|
74
|
+
commands: pkg.commands.map(({ id, title }) => ({ id, title })),
|
|
75
|
+
network: pkg.network
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
exports.ExtensionError = _chunkHL56LR6Pcjs.ExtensionError; exports.apiVersion = _chunkHL56LR6Pcjs.apiVersion; exports.createExtensionClient = _chunkF72S63D3cjs.createExtensionClient; exports.extensionManifestSchema = _chunkHL56LR6Pcjs.extensionManifestSchema; exports.extensionPackageSchema = extensionPackageSchema; exports.toExtensionManifest = toExtensionManifest;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
export { E as ExtensionClient, c as createExtensionClient } from './client-DKX6ZfiJ.cjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export { D as DeckOperation, a as ExtensionArguments, j as ExtensionCard, k as ExtensionDeck, i as ExtensionError, l as ExtensionErrorCode, n as ExtensionInvoker, E as ExtensionManifest, c as ExtensionMethod, d as ExtensionPermission, m as ExtensionRequest, e as ExtensionResponse, b as ExtensionResults, g as ExtensionTheme, N as NetworkEndpoint, o as NetworkRequest, P as ProposalReceipt, h as apiVersion, f as extensionManifestSchema } from './contracts-r8d4RACz.cjs';
|
|
4
|
+
|
|
5
|
+
declare const extensionPackageSchema: z.ZodObject<{
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
version: z.ZodString;
|
|
8
|
+
type: z.ZodLiteral<"module">;
|
|
9
|
+
title: z.ZodString;
|
|
10
|
+
description: z.ZodString;
|
|
11
|
+
author: z.ZodString;
|
|
12
|
+
icon: z.ZodString;
|
|
13
|
+
apiVersion: z.ZodLiteral<1>;
|
|
14
|
+
permissions: z.ZodArray<z.ZodEnum<{
|
|
15
|
+
"deck.read": "deck.read";
|
|
16
|
+
"selection.read": "selection.read";
|
|
17
|
+
"deck.propose": "deck.propose";
|
|
18
|
+
"cards.inspect": "cards.inspect";
|
|
19
|
+
"cards.search": "cards.search";
|
|
20
|
+
"workspace.open": "workspace.open";
|
|
21
|
+
"notifications.show": "notifications.show";
|
|
22
|
+
"storage.read": "storage.read";
|
|
23
|
+
"storage.write": "storage.write";
|
|
24
|
+
"preferences.read": "preferences.read";
|
|
25
|
+
"preferences.write": "preferences.write";
|
|
26
|
+
"network.request": "network.request";
|
|
27
|
+
}>>;
|
|
28
|
+
panels: z.ZodArray<z.ZodObject<{
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
title: z.ZodString;
|
|
31
|
+
entry: z.ZodString;
|
|
32
|
+
location: z.ZodDefault<z.ZodEnum<{
|
|
33
|
+
workspace: "workspace";
|
|
34
|
+
sidebar: "sidebar";
|
|
35
|
+
}>>;
|
|
36
|
+
}, z.core.$strict>>;
|
|
37
|
+
commands: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
title: z.ZodString;
|
|
40
|
+
entry: z.ZodString;
|
|
41
|
+
}, z.core.$strict>>>;
|
|
42
|
+
preferences: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
title: z.ZodString;
|
|
45
|
+
description: z.ZodOptional<z.ZodString>;
|
|
46
|
+
type: z.ZodLiteral<"text">;
|
|
47
|
+
default: z.ZodString;
|
|
48
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
49
|
+
id: z.ZodString;
|
|
50
|
+
title: z.ZodString;
|
|
51
|
+
description: z.ZodOptional<z.ZodString>;
|
|
52
|
+
type: z.ZodLiteral<"boolean">;
|
|
53
|
+
default: z.ZodBoolean;
|
|
54
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
55
|
+
id: z.ZodString;
|
|
56
|
+
title: z.ZodString;
|
|
57
|
+
description: z.ZodOptional<z.ZodString>;
|
|
58
|
+
type: z.ZodLiteral<"number">;
|
|
59
|
+
default: z.ZodNumber;
|
|
60
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
61
|
+
id: z.ZodString;
|
|
62
|
+
title: z.ZodString;
|
|
63
|
+
description: z.ZodOptional<z.ZodString>;
|
|
64
|
+
type: z.ZodLiteral<"select">;
|
|
65
|
+
default: z.ZodString;
|
|
66
|
+
options: z.ZodArray<z.ZodObject<{
|
|
67
|
+
value: z.ZodString;
|
|
68
|
+
label: z.ZodString;
|
|
69
|
+
}, z.core.$strict>>;
|
|
70
|
+
}, z.core.$strict>], "type">>>;
|
|
71
|
+
network: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
72
|
+
id: z.ZodString;
|
|
73
|
+
title: z.ZodString;
|
|
74
|
+
url: z.ZodString;
|
|
75
|
+
methods: z.ZodArray<z.ZodEnum<{
|
|
76
|
+
GET: "GET";
|
|
77
|
+
POST: "POST";
|
|
78
|
+
}>>;
|
|
79
|
+
}, z.core.$strict>>>;
|
|
80
|
+
dependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
81
|
+
peerDependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
82
|
+
devDependencies: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
83
|
+
scripts: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
84
|
+
bin: z.ZodOptional<z.ZodUndefined>;
|
|
85
|
+
exports: z.ZodObject<{
|
|
86
|
+
".": z.ZodObject<{
|
|
87
|
+
types: z.ZodLiteral<"./dist/index.d.ts">;
|
|
88
|
+
import: z.ZodString;
|
|
89
|
+
}, z.core.$strict>;
|
|
90
|
+
"./package.json": z.ZodLiteral<"./package.json">;
|
|
91
|
+
}, z.core.$strict>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
type ExtensionPackage = z.infer<typeof extensionPackageSchema>;
|
|
94
|
+
declare function toExtensionManifest(value: unknown): {
|
|
95
|
+
id: string;
|
|
96
|
+
apiVersion: 1;
|
|
97
|
+
version: string;
|
|
98
|
+
title: string;
|
|
99
|
+
description: string;
|
|
100
|
+
author: string;
|
|
101
|
+
permissions: ("deck.read" | "selection.read" | "deck.propose" | "cards.inspect" | "cards.search" | "workspace.open" | "notifications.show" | "storage.read" | "storage.write" | "preferences.read" | "preferences.write" | "network.request")[];
|
|
102
|
+
panels: {
|
|
103
|
+
id: string;
|
|
104
|
+
title: string;
|
|
105
|
+
location?: "workspace" | "sidebar" | undefined;
|
|
106
|
+
}[];
|
|
107
|
+
commands: {
|
|
108
|
+
id: string;
|
|
109
|
+
title: string;
|
|
110
|
+
}[];
|
|
111
|
+
preferences: ({
|
|
112
|
+
id: string;
|
|
113
|
+
title: string;
|
|
114
|
+
type: "text";
|
|
115
|
+
default: string;
|
|
116
|
+
description?: string | undefined;
|
|
117
|
+
} | {
|
|
118
|
+
id: string;
|
|
119
|
+
title: string;
|
|
120
|
+
type: "boolean";
|
|
121
|
+
default: boolean;
|
|
122
|
+
description?: string | undefined;
|
|
123
|
+
} | {
|
|
124
|
+
id: string;
|
|
125
|
+
title: string;
|
|
126
|
+
type: "number";
|
|
127
|
+
default: number;
|
|
128
|
+
description?: string | undefined;
|
|
129
|
+
} | {
|
|
130
|
+
id: string;
|
|
131
|
+
title: string;
|
|
132
|
+
type: "select";
|
|
133
|
+
default: string;
|
|
134
|
+
options: {
|
|
135
|
+
value: string;
|
|
136
|
+
label: string;
|
|
137
|
+
}[];
|
|
138
|
+
description?: string | undefined;
|
|
139
|
+
})[];
|
|
140
|
+
network: {
|
|
141
|
+
id: string;
|
|
142
|
+
title: string;
|
|
143
|
+
url: string;
|
|
144
|
+
methods: ("GET" | "POST")[];
|
|
145
|
+
}[];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export { type ExtensionPackage, extensionPackageSchema, toExtensionManifest };
|