@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.cjs
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkHL56LR6Pcjs = require('./chunk-HL56LR6P.cjs');
|
|
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 = _chunkHL56LR6Pcjs.extensionManifestSchema.parse(structuredClone(manifest)).network;
|
|
39
|
+
return async (input, lifetime) => {
|
|
40
|
+
const parsed = _chunkHL56LR6Pcjs.networkRequestSchema.safeParse(input);
|
|
41
|
+
if (!parsed.success) throw new (0, _chunkHL56LR6Pcjs.ExtensionError)("The API request is invalid.", "invalid");
|
|
42
|
+
const request = parsed.data;
|
|
43
|
+
if (_chunkHL56LR6Pcjs.messageBytes.call(void 0, request) > _chunkHL56LR6Pcjs.maxRequestBytes)
|
|
44
|
+
throw new (0, _chunkHL56LR6Pcjs.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 (0, _chunkHL56LR6Pcjs.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 (0, _chunkHL56LR6Pcjs.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 (0, _chunkHL56LR6Pcjs.ExtensionError)("The API request was cancelled.", "denied");
|
|
75
|
+
if (!options.fetch && typeof window === "undefined")
|
|
76
|
+
throw new (0, _chunkHL56LR6Pcjs.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 = _nullishCoalesce(sent.get(url.origin), () => ( []));
|
|
84
|
+
const recent = times.filter((time) => now - time < 1e3);
|
|
85
|
+
if (recent.length >= 5)
|
|
86
|
+
throw new (0, _chunkHL56LR6Pcjs.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 (0, _chunkHL56LR6Pcjs.ExtensionError)("The external API request timed out.", "timeout")
|
|
94
|
+
),
|
|
95
|
+
1e4
|
|
96
|
+
);
|
|
97
|
+
const response = await abortable(
|
|
98
|
+
(_nullishCoalesce(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 (0, _chunkHL56LR6Pcjs.ExtensionError)(
|
|
113
|
+
`External API returned HTTP ${response.status}.`,
|
|
114
|
+
response.status === 429 ? "rate-limited" : "unavailable"
|
|
115
|
+
);
|
|
116
|
+
if (!/^(?:application\/json|[^;]+\+json)(?:;|$)/i.test(
|
|
117
|
+
_nullishCoalesce(response.headers.get("content-type"), () => ( ""))
|
|
118
|
+
))
|
|
119
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)("The external API must return JSON.", "invalid");
|
|
120
|
+
if (!response.body)
|
|
121
|
+
throw new (0, _chunkHL56LR6Pcjs.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 (0, _chunkHL56LR6Pcjs.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 (e) {
|
|
155
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)("The external API returned invalid JSON.", "invalid");
|
|
156
|
+
}
|
|
157
|
+
return _chunkHL56LR6Pcjs.parseResult.call(void 0, "network.request", { status: response.status, data });
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (lifetime.aborted)
|
|
160
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)("Extension access was revoked.", "revoked");
|
|
161
|
+
if (deadline.signal.aborted) throw deadline.signal.reason;
|
|
162
|
+
if (error instanceof _chunkHL56LR6Pcjs.ExtensionError) throw error;
|
|
163
|
+
console.error("External API transport failed.", {
|
|
164
|
+
endpoint: endpoint.id,
|
|
165
|
+
method: request.method
|
|
166
|
+
});
|
|
167
|
+
throw new (0, _chunkHL56LR6Pcjs.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 = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this); }
|
|
178
|
+
__init() {this.prompts = []}
|
|
179
|
+
__init2() {this.listeners = /* @__PURE__ */ new Set()}
|
|
180
|
+
__init3() {this.remembered = /* @__PURE__ */ new Set()}
|
|
181
|
+
__init4() {this.pending = /* @__PURE__ */ new Map()}
|
|
182
|
+
__init5() {this.closed = false}
|
|
183
|
+
__init6() {this.subscribe = (listener) => {
|
|
184
|
+
this.listeners.add(listener);
|
|
185
|
+
return () => {
|
|
186
|
+
this.listeners.delete(listener);
|
|
187
|
+
};
|
|
188
|
+
}}
|
|
189
|
+
__init7() {this.getSnapshot = () => this.prompts}
|
|
190
|
+
publish() {
|
|
191
|
+
for (const listener of this.listeners) listener();
|
|
192
|
+
}
|
|
193
|
+
__init8() {this.approve = (request, signal) => {
|
|
194
|
+
if (this.closed || signal.aborted)
|
|
195
|
+
return Promise.reject(new (0, _chunkHL56LR6Pcjs.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 _chunkHL56LR6Pcjs.ExtensionError ? signal.reason : new (0, _chunkHL56LR6Pcjs.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
|
+
_optionalChain([pending, 'optionalAccess', _ => _.cleanup, 'call', _2 => _2()]);
|
|
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 && _optionalChain([prompt, 'optionalAccess', _3 => _3.request, 'access', _4 => _4.method]) === "GET")
|
|
227
|
+
this.remembered.add(prompt.request.endpoint.url);
|
|
228
|
+
_optionalChain([this, 'access', _5 => _5.remove, 'call', _6 => _6(id), 'optionalAccess', _7 => _7.resolve, 'call', _8 => _8(allowed)]);
|
|
229
|
+
}
|
|
230
|
+
dispose() {
|
|
231
|
+
this.closed = true;
|
|
232
|
+
this.remembered.clear();
|
|
233
|
+
for (const id of [...this.pending.keys()])
|
|
234
|
+
_optionalChain([this, 'access', _9 => _9.remove, 'call', _10 => _10(id), 'optionalAccess', _11 => _11.reject, 'call', _12 => _12(new (0, _chunkHL56LR6Pcjs.ExtensionError)("API access was revoked.", "revoked"))]);
|
|
235
|
+
this.listeners.clear();
|
|
236
|
+
}
|
|
237
|
+
}, _class);
|
|
238
|
+
|
|
239
|
+
// src/host.ts
|
|
240
|
+
var ExtensionSession = (_class2 = class {
|
|
241
|
+
constructor(manifest, sessionId, approved, isCurrentResource, handlers, now = Date.now) {;_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this);_class2.prototype.__init12.call(this);_class2.prototype.__init13.call(this);
|
|
242
|
+
this.sessionId = sessionId;
|
|
243
|
+
this.isCurrentResource = isCurrentResource;
|
|
244
|
+
this.handlers = handlers;
|
|
245
|
+
this.now = now;
|
|
246
|
+
this.manifest = _chunkHL56LR6Pcjs.extensionManifestSchema.parse(structuredClone(manifest));
|
|
247
|
+
if (approved.some((permission) => !this.manifest.permissions.includes(permission)))
|
|
248
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)("Cannot grant an undeclared permission.", "denied");
|
|
249
|
+
this.permissions = new Set(approved);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
__init9() {this.lifetime = new AbortController()}
|
|
254
|
+
__init10() {this.seen = /* @__PURE__ */ new Set()}
|
|
255
|
+
__init11() {this.inFlight = 0}
|
|
256
|
+
__init12() {this.windowStart = 0}
|
|
257
|
+
__init13() {this.windowRequests = 0}
|
|
258
|
+
revoke() {
|
|
259
|
+
this.lifetime.abort();
|
|
260
|
+
}
|
|
261
|
+
assertCurrent() {
|
|
262
|
+
if (this.lifetime.signal.aborted || !this.isCurrentResource())
|
|
263
|
+
throw new (0, _chunkHL56LR6Pcjs.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 (0, _chunkHL56LR6Pcjs.ExtensionError)("The extension request limit was reached.", "rate-limited");
|
|
276
|
+
if (_chunkHL56LR6Pcjs.messageBytes.call(void 0, raw) > _chunkHL56LR6Pcjs.maxRequestBytes)
|
|
277
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)("The extension request is too large.", "invalid");
|
|
278
|
+
const parsed = _chunkHL56LR6Pcjs.requestSchema.safeParse(raw);
|
|
279
|
+
if (!parsed.success)
|
|
280
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)("The extension request is invalid.", "invalid");
|
|
281
|
+
const request = parsed.data;
|
|
282
|
+
const base = {
|
|
283
|
+
protocol: _chunkHL56LR6Pcjs.protocol,
|
|
284
|
+
apiVersion: _chunkHL56LR6Pcjs.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 (0, _chunkHL56LR6Pcjs.ExtensionError)(
|
|
294
|
+
"The request belongs to another extension session.",
|
|
295
|
+
"denied"
|
|
296
|
+
);
|
|
297
|
+
if (this.seen.size >= 256 || this.inFlight >= 4)
|
|
298
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)(
|
|
299
|
+
"The extension request limit was reached.",
|
|
300
|
+
"rate-limited"
|
|
301
|
+
);
|
|
302
|
+
if (this.seen.has(request.id))
|
|
303
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)(
|
|
304
|
+
"This extension request has already been processed.",
|
|
305
|
+
"replayed"
|
|
306
|
+
);
|
|
307
|
+
this.seen.add(request.id);
|
|
308
|
+
const permission = _chunkHL56LR6Pcjs.methodPermissions[request.method];
|
|
309
|
+
if (!this.permissions.has(permission))
|
|
310
|
+
throw new (0, _chunkHL56LR6Pcjs.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: _chunkHL56LR6Pcjs.parseResult.call(void 0, request.method, result)
|
|
319
|
+
};
|
|
320
|
+
if (_chunkHL56LR6Pcjs.messageBytes.call(void 0, response) > _chunkHL56LR6Pcjs.maxResponseBytes)
|
|
321
|
+
throw new (0, _chunkHL56LR6Pcjs.ExtensionError)("The extension result exceeds its size limit.", "invalid");
|
|
322
|
+
return response;
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (this.lifetime.signal.aborted)
|
|
325
|
+
error = new (0, _chunkHL56LR6Pcjs.ExtensionError)(
|
|
326
|
+
"Extension access has been revoked. Approve access again.",
|
|
327
|
+
"revoked"
|
|
328
|
+
);
|
|
329
|
+
if (!(error instanceof _chunkHL56LR6Pcjs.ExtensionError)) {
|
|
330
|
+
console.error(`Extension operation failed: ${request.method}.`, error);
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
...base,
|
|
334
|
+
ok: false,
|
|
335
|
+
error: error instanceof _chunkHL56LR6Pcjs.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 (0, _chunkHL56LR6Pcjs.ExtensionError)(`This host has not enabled ${method}.`, "unavailable");
|
|
348
|
+
return handler(args, this.lifetime.signal);
|
|
349
|
+
}
|
|
350
|
+
}, _class2);
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
exports.ExtensionSession = ExtensionSession; exports.NetworkApprovalQueue = NetworkApprovalQueue; exports.createNetworkHandler = createNetworkHandler; exports.extensionManifestSchema = _chunkHL56LR6Pcjs.extensionManifestSchema;
|
package/dist/host.d.cts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { E as ExtensionManifest, N as NetworkEndpoint, a as ExtensionArguments, b as ExtensionResults, c as ExtensionMethod, d as ExtensionPermission, e as ExtensionResponse } from './contracts-r8d4RACz.cjs';
|
|
2
|
+
export { g as ExtensionTheme, f as extensionManifestSchema } from './contracts-r8d4RACz.cjs';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
type NetworkApproval = {
|
|
6
|
+
endpoint: NetworkEndpoint;
|
|
7
|
+
url: string;
|
|
8
|
+
method: "GET" | "POST";
|
|
9
|
+
query: ExtensionArguments["network.request"]["query"];
|
|
10
|
+
body?: ExtensionArguments["network.request"]["body"];
|
|
11
|
+
};
|
|
12
|
+
declare function createNetworkHandler(manifest: ExtensionManifest, options: {
|
|
13
|
+
approve(request: NetworkApproval, signal: AbortSignal): Promise<boolean>;
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
}): (input: ExtensionArguments["network.request"], lifetime: AbortSignal) => Promise<ExtensionResults["network.request"]>;
|
|
16
|
+
type NetworkApprovalPrompt = {
|
|
17
|
+
id: string;
|
|
18
|
+
request: NetworkApproval;
|
|
19
|
+
};
|
|
20
|
+
declare class NetworkApprovalQueue {
|
|
21
|
+
private prompts;
|
|
22
|
+
private listeners;
|
|
23
|
+
private remembered;
|
|
24
|
+
private pending;
|
|
25
|
+
private closed;
|
|
26
|
+
subscribe: (listener: () => void) => () => void;
|
|
27
|
+
getSnapshot: () => readonly NetworkApprovalPrompt[];
|
|
28
|
+
private publish;
|
|
29
|
+
approve: (request: NetworkApproval, signal: AbortSignal) => Promise<boolean>;
|
|
30
|
+
private remove;
|
|
31
|
+
answer(id: string, allowed: boolean, remember?: boolean): void;
|
|
32
|
+
dispose(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type ExtensionHandlers = {
|
|
36
|
+
[K in ExtensionMethod]: (args: ExtensionArguments[K], signal: AbortSignal) => Promise<ExtensionResults[K]>;
|
|
37
|
+
};
|
|
38
|
+
declare class ExtensionSession {
|
|
39
|
+
readonly sessionId: string;
|
|
40
|
+
private readonly isCurrentResource;
|
|
41
|
+
private readonly handlers;
|
|
42
|
+
private readonly now;
|
|
43
|
+
readonly manifest: ExtensionManifest;
|
|
44
|
+
private readonly permissions;
|
|
45
|
+
private readonly lifetime;
|
|
46
|
+
private readonly seen;
|
|
47
|
+
private inFlight;
|
|
48
|
+
private windowStart;
|
|
49
|
+
private windowRequests;
|
|
50
|
+
constructor(manifest: ExtensionManifest, sessionId: string, approved: readonly ExtensionPermission[], isCurrentResource: () => boolean, handlers: Partial<ExtensionHandlers>, now?: () => number);
|
|
51
|
+
revoke(): void;
|
|
52
|
+
private assertCurrent;
|
|
53
|
+
execute(raw: unknown): Promise<ExtensionResponse>;
|
|
54
|
+
private invoke;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { type ExtensionHandlers, ExtensionManifest, ExtensionPermission, ExtensionSession, type NetworkApproval, type NetworkApprovalPrompt, NetworkApprovalQueue, createNetworkHandler };
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { E as ExtensionManifest, N as NetworkEndpoint, a as ExtensionArguments, b as ExtensionResults, c as ExtensionMethod, d as ExtensionPermission, e as ExtensionResponse } from './contracts-r8d4RACz.js';
|
|
2
|
+
export { g as ExtensionTheme, f as extensionManifestSchema } from './contracts-r8d4RACz.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
type NetworkApproval = {
|
|
6
|
+
endpoint: NetworkEndpoint;
|
|
7
|
+
url: string;
|
|
8
|
+
method: "GET" | "POST";
|
|
9
|
+
query: ExtensionArguments["network.request"]["query"];
|
|
10
|
+
body?: ExtensionArguments["network.request"]["body"];
|
|
11
|
+
};
|
|
12
|
+
declare function createNetworkHandler(manifest: ExtensionManifest, options: {
|
|
13
|
+
approve(request: NetworkApproval, signal: AbortSignal): Promise<boolean>;
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
}): (input: ExtensionArguments["network.request"], lifetime: AbortSignal) => Promise<ExtensionResults["network.request"]>;
|
|
16
|
+
type NetworkApprovalPrompt = {
|
|
17
|
+
id: string;
|
|
18
|
+
request: NetworkApproval;
|
|
19
|
+
};
|
|
20
|
+
declare class NetworkApprovalQueue {
|
|
21
|
+
private prompts;
|
|
22
|
+
private listeners;
|
|
23
|
+
private remembered;
|
|
24
|
+
private pending;
|
|
25
|
+
private closed;
|
|
26
|
+
subscribe: (listener: () => void) => () => void;
|
|
27
|
+
getSnapshot: () => readonly NetworkApprovalPrompt[];
|
|
28
|
+
private publish;
|
|
29
|
+
approve: (request: NetworkApproval, signal: AbortSignal) => Promise<boolean>;
|
|
30
|
+
private remove;
|
|
31
|
+
answer(id: string, allowed: boolean, remember?: boolean): void;
|
|
32
|
+
dispose(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type ExtensionHandlers = {
|
|
36
|
+
[K in ExtensionMethod]: (args: ExtensionArguments[K], signal: AbortSignal) => Promise<ExtensionResults[K]>;
|
|
37
|
+
};
|
|
38
|
+
declare class ExtensionSession {
|
|
39
|
+
readonly sessionId: string;
|
|
40
|
+
private readonly isCurrentResource;
|
|
41
|
+
private readonly handlers;
|
|
42
|
+
private readonly now;
|
|
43
|
+
readonly manifest: ExtensionManifest;
|
|
44
|
+
private readonly permissions;
|
|
45
|
+
private readonly lifetime;
|
|
46
|
+
private readonly seen;
|
|
47
|
+
private inFlight;
|
|
48
|
+
private windowStart;
|
|
49
|
+
private windowRequests;
|
|
50
|
+
constructor(manifest: ExtensionManifest, sessionId: string, approved: readonly ExtensionPermission[], isCurrentResource: () => boolean, handlers: Partial<ExtensionHandlers>, now?: () => number);
|
|
51
|
+
revoke(): void;
|
|
52
|
+
private assertCurrent;
|
|
53
|
+
execute(raw: unknown): Promise<ExtensionResponse>;
|
|
54
|
+
private invoke;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { type ExtensionHandlers, ExtensionManifest, ExtensionPermission, ExtensionSession, type NetworkApproval, type NetworkApprovalPrompt, NetworkApprovalQueue, createNetworkHandler };
|