@dual-os/dynamics-api 0.0.0-stage → 8.0.3
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 +4 -0
- package/Runner.js +5771 -0
- package/Runner.js.map +63 -0
- package/bundle-inventory.json +1 -0
- package/dist/_virtual/_rolldown/runtime.js +10 -0
- package/dist/_virtual/_rolldown/runtime.js.map +9 -0
- package/dist/auth.d.ts +35 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +16 -0
- package/dist/auth.js.map +9 -0
- package/dist/generated/http.d.ts +81 -0
- package/dist/generated/http.d.ts.map +1 -0
- package/dist/generated/http.js +64 -0
- package/dist/generated/http.js.map +9 -0
- package/dist/generated/operations.d.ts +113 -0
- package/dist/generated/operations.d.ts.map +1 -0
- package/dist/generated/operations.js +46 -0
- package/dist/generated/operations.js.map +9 -0
- package/dist/generated/plugin.d.ts +55 -0
- package/dist/generated/plugin.d.ts.map +1 -0
- package/dist/generated/plugin.js +95 -0
- package/dist/generated/plugin.js.map +10 -0
- package/dist/triggers.d.ts +92 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js +17 -0
- package/dist/triggers.js.map +9 -0
- package/dual-plugin.json +1 -0
- package/licenses/@dual-os_sdk@0.8.1/LICENSE +4 -0
- package/licenses/@effect_platform-node-shared@4.1.2/LICENSE +21 -0
- package/licenses/@effect_platform-node@4.1.2/LICENSE +21 -0
- package/licenses/effect@4.1.2/LICENSE +21 -0
- package/package.json +1 -6
- package/plugin-13g044ny.js +197 -0
- package/plugin-13g044ny.js.map +10 -0
- package/plugin-2jdfj02n.js +18 -0
- package/plugin-2jdfj02n.js.map +10 -0
- package/plugin-72zm9ftz.js +19124 -0
- package/plugin-72zm9ftz.js.map +159 -0
- package/plugin-dpa3d1wz.js +172 -0
- package/plugin-dpa3d1wz.js.map +10 -0
- package/plugin-ma04jcpp.js +62 -0
- package/plugin-ma04jcpp.js.map +10 -0
- package/plugin-y6mf6hx3.js +1362 -0
- package/plugin-y6mf6hx3.js.map +18 -0
- package/plugin.json +26 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1362 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
__exportAll2
|
|
4
|
+
} from "./plugin-2jdfj02n.js";
|
|
5
|
+
import {
|
|
6
|
+
dual,
|
|
7
|
+
identity,
|
|
8
|
+
pipe,
|
|
9
|
+
flow,
|
|
10
|
+
isString,
|
|
11
|
+
isObject,
|
|
12
|
+
hasProperty,
|
|
13
|
+
equals,
|
|
14
|
+
PipeInspectableProto,
|
|
15
|
+
Number2,
|
|
16
|
+
mapInput,
|
|
17
|
+
none,
|
|
18
|
+
some,
|
|
19
|
+
isNone,
|
|
20
|
+
match2,
|
|
21
|
+
getOrElse,
|
|
22
|
+
orElse,
|
|
23
|
+
fromNullishOr,
|
|
24
|
+
fromUndefinedOr,
|
|
25
|
+
getOrNull,
|
|
26
|
+
getOrUndefined,
|
|
27
|
+
liftThrowable,
|
|
28
|
+
map,
|
|
29
|
+
flatMap,
|
|
30
|
+
filter,
|
|
31
|
+
liftPredicate,
|
|
32
|
+
Reference,
|
|
33
|
+
succeed,
|
|
34
|
+
fail,
|
|
35
|
+
failVoid,
|
|
36
|
+
fromOption,
|
|
37
|
+
try_,
|
|
38
|
+
isSuccess,
|
|
39
|
+
match3,
|
|
40
|
+
fromEntries,
|
|
41
|
+
toEntries,
|
|
42
|
+
has,
|
|
43
|
+
map2,
|
|
44
|
+
ensure,
|
|
45
|
+
append,
|
|
46
|
+
isArray,
|
|
47
|
+
isReadonlyArrayNonEmpty,
|
|
48
|
+
getUnsafe2,
|
|
49
|
+
headNonEmpty,
|
|
50
|
+
findFirst,
|
|
51
|
+
sort,
|
|
52
|
+
zip,
|
|
53
|
+
contains2,
|
|
54
|
+
empty3,
|
|
55
|
+
map3,
|
|
56
|
+
flatMap2,
|
|
57
|
+
filterMap,
|
|
58
|
+
filter2,
|
|
59
|
+
reduce,
|
|
60
|
+
fromNullishOr2,
|
|
61
|
+
every,
|
|
62
|
+
join,
|
|
63
|
+
millis,
|
|
64
|
+
TaggedClass,
|
|
65
|
+
TaggedError,
|
|
66
|
+
currentTimeMillis,
|
|
67
|
+
increment,
|
|
68
|
+
toLowerCase,
|
|
69
|
+
replace,
|
|
70
|
+
trim,
|
|
71
|
+
slice,
|
|
72
|
+
isEmpty,
|
|
73
|
+
isNonEmpty,
|
|
74
|
+
split,
|
|
75
|
+
startsWith,
|
|
76
|
+
endsWith,
|
|
77
|
+
match4,
|
|
78
|
+
replaceAll,
|
|
79
|
+
isEffect,
|
|
80
|
+
forEach,
|
|
81
|
+
promise,
|
|
82
|
+
succeed4,
|
|
83
|
+
suspend,
|
|
84
|
+
sync,
|
|
85
|
+
void_2,
|
|
86
|
+
gen,
|
|
87
|
+
fail5,
|
|
88
|
+
withFiber,
|
|
89
|
+
fromOption2,
|
|
90
|
+
flatMap3,
|
|
91
|
+
result,
|
|
92
|
+
map4,
|
|
93
|
+
mapError,
|
|
94
|
+
orDie,
|
|
95
|
+
ignore,
|
|
96
|
+
serviceOption,
|
|
97
|
+
provideService,
|
|
98
|
+
scoped,
|
|
99
|
+
acquireRelease,
|
|
100
|
+
fnUntraced,
|
|
101
|
+
fn,
|
|
102
|
+
encode,
|
|
103
|
+
encode2,
|
|
104
|
+
decode,
|
|
105
|
+
makeZoned,
|
|
106
|
+
make3,
|
|
107
|
+
toUtc,
|
|
108
|
+
toDateUtc,
|
|
109
|
+
toEpochMillis,
|
|
110
|
+
formatIso,
|
|
111
|
+
formatIsoOffset,
|
|
112
|
+
empty4,
|
|
113
|
+
empty5,
|
|
114
|
+
InvalidValue,
|
|
115
|
+
compose2,
|
|
116
|
+
transform,
|
|
117
|
+
transformEffect,
|
|
118
|
+
is,
|
|
119
|
+
decodeUnknownEffect,
|
|
120
|
+
decodeOption,
|
|
121
|
+
encodeEffect,
|
|
122
|
+
isSchema,
|
|
123
|
+
optionalKey,
|
|
124
|
+
optional,
|
|
125
|
+
toType,
|
|
126
|
+
Literal,
|
|
127
|
+
Unknown,
|
|
128
|
+
String3,
|
|
129
|
+
Boolean2,
|
|
130
|
+
Struct,
|
|
131
|
+
Record,
|
|
132
|
+
StructWithRest,
|
|
133
|
+
ArraySchema,
|
|
134
|
+
Literals,
|
|
135
|
+
NullOr,
|
|
136
|
+
decodeTo,
|
|
137
|
+
withDecodingDefaultKey,
|
|
138
|
+
isPattern,
|
|
139
|
+
Finite,
|
|
140
|
+
isGreaterThan,
|
|
141
|
+
Int,
|
|
142
|
+
Natural,
|
|
143
|
+
NonEmptyString,
|
|
144
|
+
Defect,
|
|
145
|
+
fromJsonString,
|
|
146
|
+
Uint8ArrayFromBase64,
|
|
147
|
+
TaggedError2,
|
|
148
|
+
toEquivalence,
|
|
149
|
+
Json,
|
|
150
|
+
make5,
|
|
151
|
+
get3,
|
|
152
|
+
set2,
|
|
153
|
+
update,
|
|
154
|
+
fromEffect,
|
|
155
|
+
fromIterable,
|
|
156
|
+
paginate,
|
|
157
|
+
unwrap2,
|
|
158
|
+
mapEffect,
|
|
159
|
+
flatMap4,
|
|
160
|
+
filterMap2,
|
|
161
|
+
decodeText,
|
|
162
|
+
runCollect,
|
|
163
|
+
runHead,
|
|
164
|
+
empty7,
|
|
165
|
+
HttpClientError,
|
|
166
|
+
InvalidUrlError,
|
|
167
|
+
makeWith,
|
|
168
|
+
post,
|
|
169
|
+
put,
|
|
170
|
+
del,
|
|
171
|
+
setMethod,
|
|
172
|
+
setHeader,
|
|
173
|
+
setHeaders,
|
|
174
|
+
bearerToken,
|
|
175
|
+
setUrl,
|
|
176
|
+
updateUrl,
|
|
177
|
+
setUrlParam,
|
|
178
|
+
setBody,
|
|
179
|
+
bodyUint8Array,
|
|
180
|
+
bodyJsonUnsafe,
|
|
181
|
+
bodyUrlParams,
|
|
182
|
+
bodyFormDataRecord,
|
|
183
|
+
schemaBodyJson,
|
|
184
|
+
HttpClient,
|
|
185
|
+
transformResponse,
|
|
186
|
+
filterStatusOk,
|
|
187
|
+
mapRequest,
|
|
188
|
+
mapRequestEffect,
|
|
189
|
+
RequestInit,
|
|
190
|
+
__exportAll3,
|
|
191
|
+
ActionHandlerError,
|
|
192
|
+
fromHttpClientFailure,
|
|
193
|
+
AuthMethod_exports,
|
|
194
|
+
Schema,
|
|
195
|
+
Key,
|
|
196
|
+
Event,
|
|
197
|
+
commandSchema,
|
|
198
|
+
Service2,
|
|
199
|
+
File3,
|
|
200
|
+
read,
|
|
201
|
+
write
|
|
202
|
+
} from "./plugin-72zm9ftz.js";
|
|
203
|
+
|
|
204
|
+
// ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/internal/random.js
|
|
205
|
+
var Random = /* @__PURE__ */ Reference("effect/Random", {
|
|
206
|
+
defaultValue: () => ({
|
|
207
|
+
nextIntUnsafe() {
|
|
208
|
+
return Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - Number.MIN_SAFE_INTEGER + 1)) + Number.MIN_SAFE_INTEGER;
|
|
209
|
+
},
|
|
210
|
+
nextDoubleUnsafe() {
|
|
211
|
+
return Math.random();
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/Random.js
|
|
217
|
+
var Random2 = Random;
|
|
218
|
+
var randomWith = (f) => withFiber((fiber) => succeed4(f(fiber.getRef(Random2))));
|
|
219
|
+
var nextInt = /* @__PURE__ */ randomWith((r) => r.nextIntUnsafe());
|
|
220
|
+
|
|
221
|
+
// ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/Boolean.js
|
|
222
|
+
var Boolean = globalThis.Boolean;
|
|
223
|
+
var match = /* @__PURE__ */ dual(2, (value, options) => value ? options.onTrue() : options.onFalse());
|
|
224
|
+
|
|
225
|
+
// ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/Ref.js
|
|
226
|
+
var TypeId = "~effect/Ref";
|
|
227
|
+
var RefProto = {
|
|
228
|
+
[TypeId]: {
|
|
229
|
+
_A: identity
|
|
230
|
+
},
|
|
231
|
+
...PipeInspectableProto,
|
|
232
|
+
toJSON() {
|
|
233
|
+
return {
|
|
234
|
+
_id: "Ref",
|
|
235
|
+
ref: this.ref
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
var makeUnsafe = (value) => {
|
|
240
|
+
const self = Object.create(RefProto);
|
|
241
|
+
self.ref = make5(value);
|
|
242
|
+
return self;
|
|
243
|
+
};
|
|
244
|
+
var make = (value) => sync(() => makeUnsafe(value));
|
|
245
|
+
var get = (self) => sync(() => self.ref.current);
|
|
246
|
+
var set = /* @__PURE__ */ dual(2, (self, value) => sync(() => set2(self.ref, value)));
|
|
247
|
+
var getAndUpdate = /* @__PURE__ */ dual(2, (self, f) => sync(() => {
|
|
248
|
+
const current = self.ref.current;
|
|
249
|
+
self.ref.current = f(current);
|
|
250
|
+
return current;
|
|
251
|
+
}));
|
|
252
|
+
|
|
253
|
+
// ../../../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/encoding/Sse.js
|
|
254
|
+
var SseErrorTypeId = "~effect/encoding/Sse/SseError";
|
|
255
|
+
|
|
256
|
+
class EventTooLarge extends (/* @__PURE__ */ TaggedError("EventTooLarge")) {
|
|
257
|
+
get message() {
|
|
258
|
+
return `Pending SSE event exceeded the maximum size of ${this.maxEventSize}`;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
class SseError extends (/* @__PURE__ */ TaggedError("SseError")) {
|
|
263
|
+
[SseErrorTypeId] = SseErrorTypeId;
|
|
264
|
+
get message() {
|
|
265
|
+
return this.reason.message;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
var defaultMaxEventSize = 10 * 1024 * 1024;
|
|
269
|
+
function makeParser(onParse, options) {
|
|
270
|
+
const maxEventSize = options?.maxEventSize ?? defaultMaxEventSize;
|
|
271
|
+
const dispatchEmptyNamedEvents = options?.dispatchEmptyNamedEvents === true;
|
|
272
|
+
let isFirstChunk;
|
|
273
|
+
let pending;
|
|
274
|
+
let pendingLength;
|
|
275
|
+
let discardTrailingNewline;
|
|
276
|
+
let generation = 0;
|
|
277
|
+
let lastEventId;
|
|
278
|
+
let eventName;
|
|
279
|
+
let data;
|
|
280
|
+
reset();
|
|
281
|
+
return {
|
|
282
|
+
feed,
|
|
283
|
+
reset
|
|
284
|
+
};
|
|
285
|
+
function reset() {
|
|
286
|
+
generation++;
|
|
287
|
+
isFirstChunk = true;
|
|
288
|
+
pending = [];
|
|
289
|
+
pendingLength = 0;
|
|
290
|
+
discardTrailingNewline = false;
|
|
291
|
+
lastEventId = undefined;
|
|
292
|
+
eventName = undefined;
|
|
293
|
+
data = "";
|
|
294
|
+
}
|
|
295
|
+
function feed(chunk) {
|
|
296
|
+
if (chunk.length === 0)
|
|
297
|
+
return;
|
|
298
|
+
if (isFirstChunk && chunk.startsWith(BOM)) {
|
|
299
|
+
chunk = chunk.slice(BOM.length);
|
|
300
|
+
}
|
|
301
|
+
isFirstChunk = false;
|
|
302
|
+
const length = chunk.length;
|
|
303
|
+
const currentGeneration = generation;
|
|
304
|
+
let position = 0;
|
|
305
|
+
while (position < length) {
|
|
306
|
+
if (discardTrailingNewline) {
|
|
307
|
+
discardTrailingNewline = false;
|
|
308
|
+
if (chunk.charCodeAt(position) === LF) {
|
|
309
|
+
++position;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
let lineEnd = position;
|
|
314
|
+
while (lineEnd < length) {
|
|
315
|
+
const code = chunk.charCodeAt(lineEnd);
|
|
316
|
+
if (code === CR || code === LF)
|
|
317
|
+
break;
|
|
318
|
+
++lineEnd;
|
|
319
|
+
}
|
|
320
|
+
if (lineEnd === length) {
|
|
321
|
+
pending.push(chunk.slice(position));
|
|
322
|
+
pendingLength += length - position;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
discardTrailingNewline = chunk.charCodeAt(lineEnd) === CR;
|
|
326
|
+
let line = chunk.slice(position, lineEnd);
|
|
327
|
+
if (pending.length > 0) {
|
|
328
|
+
pending.push(line);
|
|
329
|
+
line = pending.join("");
|
|
330
|
+
pending = [];
|
|
331
|
+
pendingLength = 0;
|
|
332
|
+
}
|
|
333
|
+
parseLine(line);
|
|
334
|
+
if (generation !== currentGeneration) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
position = lineEnd + 1;
|
|
338
|
+
}
|
|
339
|
+
if (pendingLength + data.length > maxEventSize) {
|
|
340
|
+
const error = new SseError({
|
|
341
|
+
reason: new EventTooLarge({
|
|
342
|
+
maxEventSize
|
|
343
|
+
})
|
|
344
|
+
});
|
|
345
|
+
reset();
|
|
346
|
+
return error;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function parseLine(line) {
|
|
350
|
+
if (line.length === 0) {
|
|
351
|
+
const named = eventName !== undefined && eventName !== "";
|
|
352
|
+
const event = eventName || "message";
|
|
353
|
+
const eventData = data;
|
|
354
|
+
eventName = undefined;
|
|
355
|
+
data = "";
|
|
356
|
+
if (eventData.length > 0 || dispatchEmptyNamedEvents && named) {
|
|
357
|
+
onParse({
|
|
358
|
+
_tag: "Event",
|
|
359
|
+
id: lastEventId,
|
|
360
|
+
event,
|
|
361
|
+
data: eventData.slice(0, -1)
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const colon = line.indexOf(":");
|
|
367
|
+
let field = line;
|
|
368
|
+
let value = "";
|
|
369
|
+
if (colon >= 0) {
|
|
370
|
+
field = line.slice(0, colon);
|
|
371
|
+
value = line.slice(line.charCodeAt(colon + 1) === SPACE ? colon + 2 : colon + 1);
|
|
372
|
+
}
|
|
373
|
+
if (field === "data") {
|
|
374
|
+
data += value + `
|
|
375
|
+
`;
|
|
376
|
+
} else if (field === "event") {
|
|
377
|
+
eventName = value;
|
|
378
|
+
} else if (field === "id" && !value.includes("\x00")) {
|
|
379
|
+
lastEventId = value;
|
|
380
|
+
} else if (field === "retry" && /^\d+$/.test(value)) {
|
|
381
|
+
const retry = parseInt(value, 10);
|
|
382
|
+
onParse(new Retry({
|
|
383
|
+
duration: millis(retry),
|
|
384
|
+
lastEventId
|
|
385
|
+
}));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
var BOM = "\uFEFF";
|
|
390
|
+
var LF = 10;
|
|
391
|
+
var CR = 13;
|
|
392
|
+
var SPACE = 32;
|
|
393
|
+
var RetryTypeId = "~effect/encoding/Sse/Retry";
|
|
394
|
+
|
|
395
|
+
class Retry extends (/* @__PURE__ */ TaggedClass("Retry")) {
|
|
396
|
+
[RetryTypeId] = RetryTypeId;
|
|
397
|
+
static is(u) {
|
|
398
|
+
return hasProperty(u, RetryTypeId);
|
|
399
|
+
}
|
|
400
|
+
static filter(u) {
|
|
401
|
+
return Retry.is(u) ? succeed(u) : fail(u);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ../../../../node_modules/.bun/@dual-os+sdk@0.8.1+a827849ded09603e/node_modules/@dual-os/sdk/dist/AgentChannelConformance.js
|
|
406
|
+
var Command = commandSchema(Json);
|
|
407
|
+
var Fixture = Struct({
|
|
408
|
+
activate: Command,
|
|
409
|
+
channelId: Key,
|
|
410
|
+
connectionId: optionalKey(Key),
|
|
411
|
+
deactivate: Command,
|
|
412
|
+
definitionSettings: Json,
|
|
413
|
+
deliver: Command,
|
|
414
|
+
deploymentSettings: Json,
|
|
415
|
+
receive: Command
|
|
416
|
+
});
|
|
417
|
+
var ConformanceError = class extends TaggedError2()("AgentChannelConformanceError", {
|
|
418
|
+
command: Literals([
|
|
419
|
+
"activate",
|
|
420
|
+
"deactivate",
|
|
421
|
+
"receive",
|
|
422
|
+
"deliver"
|
|
423
|
+
]),
|
|
424
|
+
rule: Literals([
|
|
425
|
+
"command_kind",
|
|
426
|
+
"stable_result",
|
|
427
|
+
"stable_events",
|
|
428
|
+
"boundary_rejection"
|
|
429
|
+
])
|
|
430
|
+
}) {
|
|
431
|
+
};
|
|
432
|
+
var run = fn("AgentChannelConformance.run")(function* (input) {
|
|
433
|
+
const fixture = yield* decodeUnknownEffect(Fixture)(input, { onExcessProperty: "error" });
|
|
434
|
+
const runtime = yield* Service2;
|
|
435
|
+
const definition = yield* runtime.getAgentChannel({ channelId: fixture.channelId });
|
|
436
|
+
const { activate, receive, deliver, deactivate, ...config } = fixture;
|
|
437
|
+
const { connectionId: _connectionId, ...withoutConnection } = config;
|
|
438
|
+
const probes = [
|
|
439
|
+
{
|
|
440
|
+
code: "invalid_input",
|
|
441
|
+
input: {
|
|
442
|
+
...config,
|
|
443
|
+
channelId: "",
|
|
444
|
+
command: activate
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
input: {
|
|
449
|
+
...config,
|
|
450
|
+
channelId: "conformance/missing/channel",
|
|
451
|
+
command: activate
|
|
452
|
+
},
|
|
453
|
+
code: "not_found"
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
code: "invalid_input",
|
|
457
|
+
input: {
|
|
458
|
+
...config,
|
|
459
|
+
command: {
|
|
460
|
+
...activate,
|
|
461
|
+
operationKey: ""
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
code: "invalid_input",
|
|
467
|
+
input: {
|
|
468
|
+
...config,
|
|
469
|
+
agent: { id: "synthetic-authority" },
|
|
470
|
+
command: activate
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
code: "invalid_auth",
|
|
475
|
+
input: definition.authMethods.length === 0 ? {
|
|
476
|
+
...config,
|
|
477
|
+
command: activate,
|
|
478
|
+
connectionId: "unexpected"
|
|
479
|
+
} : {
|
|
480
|
+
...withoutConnection,
|
|
481
|
+
command: activate
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
];
|
|
485
|
+
for (const probe of probes) {
|
|
486
|
+
const outcome = yield* suspend(() => runtime.executeAgentChannel(probe.input)).pipe(result);
|
|
487
|
+
if (outcome._tag !== "Failure" || outcome.failure.code !== probe.code)
|
|
488
|
+
return yield* new ConformanceError({
|
|
489
|
+
command: "activate",
|
|
490
|
+
rule: "boundary_rejection"
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
const commands = [
|
|
494
|
+
["activate", activate],
|
|
495
|
+
["receive", receive],
|
|
496
|
+
["deliver", deliver],
|
|
497
|
+
["deactivate", deactivate]
|
|
498
|
+
];
|
|
499
|
+
for (const [kind, command] of commands)
|
|
500
|
+
if (command.kind !== kind)
|
|
501
|
+
return yield* new ConformanceError({
|
|
502
|
+
command: kind,
|
|
503
|
+
rule: "command_kind"
|
|
504
|
+
});
|
|
505
|
+
const activated = yield* acquireRelease(runtime.executeAgentChannel({
|
|
506
|
+
...config,
|
|
507
|
+
command: activate
|
|
508
|
+
}), (result2) => runtime.executeAgentChannel({
|
|
509
|
+
...config,
|
|
510
|
+
command: {
|
|
511
|
+
...deactivate,
|
|
512
|
+
...result2.kind === "activate" ? {
|
|
513
|
+
installationKey: result2.installationKey,
|
|
514
|
+
state: result2.state
|
|
515
|
+
} : {}
|
|
516
|
+
}
|
|
517
|
+
}).pipe(orDie));
|
|
518
|
+
for (const [kind, command] of commands) {
|
|
519
|
+
const first = kind === "activate" ? activated : yield* runtime.executeAgentChannel({
|
|
520
|
+
...config,
|
|
521
|
+
command
|
|
522
|
+
});
|
|
523
|
+
if (kind === "deliver" && definition.features.deliveryMode === "at-most-once")
|
|
524
|
+
continue;
|
|
525
|
+
const second = yield* runtime.executeAgentChannel({
|
|
526
|
+
...config,
|
|
527
|
+
command
|
|
528
|
+
});
|
|
529
|
+
const firstJson = yield* decodeUnknownEffect(Json)(first);
|
|
530
|
+
const secondJson = yield* decodeUnknownEffect(Json)(second);
|
|
531
|
+
if (!toEquivalence(Json)(firstJson, secondJson))
|
|
532
|
+
return yield* new ConformanceError({
|
|
533
|
+
command: kind,
|
|
534
|
+
rule: "stable_result"
|
|
535
|
+
});
|
|
536
|
+
if (kind === "receive") {
|
|
537
|
+
const nextReceipt = yield* runtime.executeAgentChannel({
|
|
538
|
+
...config,
|
|
539
|
+
command: {
|
|
540
|
+
...command,
|
|
541
|
+
operationKey: `${command.operationKey.slice(0, 500)}:replay`
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
if (first.kind !== "receive" || nextReceipt.kind !== "receive" || !toEquivalence(ArraySchema(Event))(first.events, nextReceipt.events))
|
|
545
|
+
return yield* new ConformanceError({
|
|
546
|
+
command: kind,
|
|
547
|
+
rule: "stable_events"
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}, scoped);
|
|
552
|
+
|
|
553
|
+
// ../../../../node_modules/.bun/@dual-os+sdk@0.8.1+a827849ded09603e/node_modules/@dual-os/sdk/dist/Mcp.js
|
|
554
|
+
var McpError = class extends TaggedError2()("McpError", {
|
|
555
|
+
cause: optional(Defect()),
|
|
556
|
+
message: String3
|
|
557
|
+
}) {
|
|
558
|
+
};
|
|
559
|
+
var protocolVersion = "2025-06-18";
|
|
560
|
+
var Implementation = Struct({
|
|
561
|
+
name: String3,
|
|
562
|
+
title: optionalKey(String3),
|
|
563
|
+
version: String3
|
|
564
|
+
});
|
|
565
|
+
var Tool = Struct({
|
|
566
|
+
annotations: optionalKey(Struct({ title: optionalKey(String3) })),
|
|
567
|
+
description: optionalKey(String3),
|
|
568
|
+
inputSchema: Record(String3, Unknown),
|
|
569
|
+
name: String3,
|
|
570
|
+
outputSchema: optionalKey(Record(String3, Unknown)),
|
|
571
|
+
title: optionalKey(String3)
|
|
572
|
+
});
|
|
573
|
+
var ListToolsResult = Struct({
|
|
574
|
+
nextCursor: optionalKey(String3),
|
|
575
|
+
tools: ArraySchema(Tool)
|
|
576
|
+
});
|
|
577
|
+
var ContentBlock = StructWithRest(Struct({
|
|
578
|
+
text: optionalKey(String3),
|
|
579
|
+
type: String3
|
|
580
|
+
}), [Record(String3, Unknown)]);
|
|
581
|
+
var CallToolResult = Struct({
|
|
582
|
+
content: ArraySchema(ContentBlock),
|
|
583
|
+
isError: optionalKey(Boolean2),
|
|
584
|
+
structuredContent: optionalKey(Unknown)
|
|
585
|
+
});
|
|
586
|
+
var InitializeResult = Struct({
|
|
587
|
+
protocolVersion: String3,
|
|
588
|
+
serverInfo: Implementation
|
|
589
|
+
});
|
|
590
|
+
var Message = Struct({
|
|
591
|
+
error: optionalKey(Struct({ message: String3 })),
|
|
592
|
+
id: optionalKey(Unknown),
|
|
593
|
+
result: optionalKey(Unknown)
|
|
594
|
+
});
|
|
595
|
+
var responseTo = fnUntraced(function* (id, method, response) {
|
|
596
|
+
const payloads = match(pipe(response.headers["content-type"] ?? "", startsWith("text/event-stream")), {
|
|
597
|
+
onFalse: () => fromEffect(response.text),
|
|
598
|
+
onTrue: () => unwrap2(sync(() => {
|
|
599
|
+
const events = make5(empty3());
|
|
600
|
+
const parser = makeParser((event) => {
|
|
601
|
+
if (event._tag === "Event")
|
|
602
|
+
update(events, append(event.data));
|
|
603
|
+
});
|
|
604
|
+
return pipe(response.stream, decodeText(), mapEffect((chunk) => {
|
|
605
|
+
const error = parser.feed(chunk);
|
|
606
|
+
if (error !== undefined)
|
|
607
|
+
return fail5(McpError.make({
|
|
608
|
+
cause: error,
|
|
609
|
+
message: error.message
|
|
610
|
+
}));
|
|
611
|
+
const ready = get3(events);
|
|
612
|
+
set2(events, empty3());
|
|
613
|
+
return succeed4(ready);
|
|
614
|
+
}), flatMap4(fromIterable));
|
|
615
|
+
}))
|
|
616
|
+
});
|
|
617
|
+
const found = yield* pipe(payloads, filterMap2((payload) => fromOption(filter(decodeOption(fromJsonString(Message))(payload), (message) => message.id === id && (message.result !== undefined || message.error !== undefined)), () => payload)), runHead);
|
|
618
|
+
return yield* fromOption2(found, () => McpError.make({ message: `${method} got no response` }));
|
|
619
|
+
});
|
|
620
|
+
var connect = fn("Mcp.connect")(function* (client, endpoint, headers) {
|
|
621
|
+
const checked = filterStatusOk(client);
|
|
622
|
+
const post2 = fnUntraced(function* (version, session, body) {
|
|
623
|
+
return yield* checked.execute(pipe(post(endpoint), setHeaders({
|
|
624
|
+
...headers,
|
|
625
|
+
accept: "application/json, text/event-stream",
|
|
626
|
+
"mcp-protocol-version": version,
|
|
627
|
+
...match2(session, {
|
|
628
|
+
onNone: () => ({}),
|
|
629
|
+
onSome: (id) => ({ "mcp-session-id": id })
|
|
630
|
+
})
|
|
631
|
+
}), bodyJsonUnsafe({
|
|
632
|
+
jsonrpc: "2.0",
|
|
633
|
+
...body
|
|
634
|
+
})));
|
|
635
|
+
});
|
|
636
|
+
const call = fnUntraced(function* (version, session, id, method, params) {
|
|
637
|
+
const response = yield* post2(version, session, {
|
|
638
|
+
id,
|
|
639
|
+
method,
|
|
640
|
+
params
|
|
641
|
+
});
|
|
642
|
+
const message = yield* responseTo(id, method, response);
|
|
643
|
+
if (message.error !== undefined)
|
|
644
|
+
return yield* McpError.make({ message: `${method}: ${message.error.message}` });
|
|
645
|
+
return {
|
|
646
|
+
result: message.result,
|
|
647
|
+
session: orElse(fromNullishOr(response.headers["mcp-session-id"]), () => session)
|
|
648
|
+
};
|
|
649
|
+
});
|
|
650
|
+
const negotiatedVersion = yield* make(protocolVersion);
|
|
651
|
+
const initialized = yield* acquireRelease(call(protocolVersion, none(), 0, "initialize", {
|
|
652
|
+
capabilities: {},
|
|
653
|
+
clientInfo: {
|
|
654
|
+
name: "dual",
|
|
655
|
+
version: "1"
|
|
656
|
+
},
|
|
657
|
+
protocolVersion
|
|
658
|
+
}), (opened) => match2(opened.session, {
|
|
659
|
+
onNone: () => void_2,
|
|
660
|
+
onSome: (id) => flatMap3(get(negotiatedVersion), (version) => ignore(client.execute(pipe(del(endpoint), setHeaders({
|
|
661
|
+
...headers,
|
|
662
|
+
"mcp-protocol-version": version,
|
|
663
|
+
"mcp-session-id": id
|
|
664
|
+
})))))
|
|
665
|
+
}));
|
|
666
|
+
const server = yield* decodeUnknownEffect(InitializeResult)(initialized.result);
|
|
667
|
+
if (server.protocolVersion !== protocolVersion && server.protocolVersion !== "2025-03-26")
|
|
668
|
+
return yield* McpError.make({ message: `Unsupported MCP protocol version ${server.protocolVersion}` });
|
|
669
|
+
yield* set(negotiatedVersion, server.protocolVersion);
|
|
670
|
+
yield* post2(server.protocolVersion, initialized.session, { method: "notifications/initialized" });
|
|
671
|
+
const ids = yield* make(1);
|
|
672
|
+
return {
|
|
673
|
+
request: fn("Mcp.request")(function* (method, params) {
|
|
674
|
+
return (yield* call(server.protocolVersion, initialized.session, yield* getAndUpdate(ids, increment), method, params)).result;
|
|
675
|
+
}),
|
|
676
|
+
server: server.serverInfo
|
|
677
|
+
};
|
|
678
|
+
});
|
|
679
|
+
var listTools = fn("Mcp.listTools")(function* (client, endpoint, headers) {
|
|
680
|
+
const session = yield* connect(client, endpoint, headers);
|
|
681
|
+
const tools = yield* runCollect(paginate({}, fnUntraced(function* (params) {
|
|
682
|
+
const page = yield* decodeUnknownEffect(ListToolsResult)(yield* session.request("tools/list", params));
|
|
683
|
+
return [page.tools, map(fromUndefinedOr(page.nextCursor), (cursor) => ({ cursor }))];
|
|
684
|
+
})));
|
|
685
|
+
return {
|
|
686
|
+
server: session.server,
|
|
687
|
+
tools
|
|
688
|
+
};
|
|
689
|
+
}, scoped);
|
|
690
|
+
|
|
691
|
+
// ../../../../node_modules/.bun/@dual-os+sdk@0.8.1+a827849ded09603e/node_modules/@dual-os/sdk/dist/Http.js
|
|
692
|
+
var Http_exports = /* @__PURE__ */ __exportAll3({
|
|
693
|
+
Base64FromFile: () => Base64FromFile2,
|
|
694
|
+
Base64UrlFromFile: () => Base64UrlFromFile2,
|
|
695
|
+
DataUriFromFile: () => DataUriFromFile2,
|
|
696
|
+
DateTimeFromRfc2822: () => DateTimeFromRfc28222,
|
|
697
|
+
DateTimeFromUnixSeconds: () => DateTimeFromUnixSeconds2,
|
|
698
|
+
File: () => File2,
|
|
699
|
+
FileFromBase64: () => FileFromBase642,
|
|
700
|
+
FileFromBase64Url: () => FileFromBase64Url2,
|
|
701
|
+
FileFromDataUri: () => FileFromDataUri2,
|
|
702
|
+
Http: () => Http_exports,
|
|
703
|
+
Rfc2822FromDateTime: () => Rfc2822FromDateTime2,
|
|
704
|
+
UnixSecondsFromDateTime: () => UnixSecondsFromDateTime2,
|
|
705
|
+
continuation: () => continuation2,
|
|
706
|
+
decoded: () => decoded2,
|
|
707
|
+
form: () => form2,
|
|
708
|
+
literal: () => literal2,
|
|
709
|
+
make: () => make2,
|
|
710
|
+
params: () => params2,
|
|
711
|
+
path: () => path2,
|
|
712
|
+
preauthenticated: () => preauthenticated2,
|
|
713
|
+
segments: () => segments2,
|
|
714
|
+
withFile: () => withFile,
|
|
715
|
+
withForm: () => withForm
|
|
716
|
+
});
|
|
717
|
+
function preserveJsonProperties(value, input) {
|
|
718
|
+
if (equals(value, input))
|
|
719
|
+
return value;
|
|
720
|
+
if (isArray(value) && isArray(input))
|
|
721
|
+
for (const entry of zip(value, input))
|
|
722
|
+
preserveJsonProperties(entry[0], entry[1]);
|
|
723
|
+
else if (isObject(value) && isObject(input))
|
|
724
|
+
for (const entry of toEntries(input))
|
|
725
|
+
if (has(value, entry[0]))
|
|
726
|
+
preserveJsonProperties(value[entry[0]], entry[1]);
|
|
727
|
+
else
|
|
728
|
+
Object.defineProperty(value, entry[0], {
|
|
729
|
+
configurable: true,
|
|
730
|
+
enumerable: true,
|
|
731
|
+
value: entry[1],
|
|
732
|
+
writable: true
|
|
733
|
+
});
|
|
734
|
+
return value;
|
|
735
|
+
}
|
|
736
|
+
function decodeResponse(output) {
|
|
737
|
+
return flow(succeed4, flatMap3((input) => pipe(decodeUnknownEffect(output)(input), map4((value) => preserveJsonProperties(value, input)))));
|
|
738
|
+
}
|
|
739
|
+
var File2 = Struct({
|
|
740
|
+
_tag: optionalKey(Literal("ToolFile")),
|
|
741
|
+
contentBase64: Uint8ArrayFromBase64,
|
|
742
|
+
contentType: optionalKey(NullOr(String3)),
|
|
743
|
+
filename: optionalKey(NullOr(String3)),
|
|
744
|
+
sizeBytes: optionalKey(Natural)
|
|
745
|
+
}).annotate({ description: "A ToolFile, such as the result of a download, passed unchanged; or its contentBase64 with an optional contentType and filename." });
|
|
746
|
+
var signatures = [
|
|
747
|
+
["image/jpeg", [[0, [
|
|
748
|
+
255,
|
|
749
|
+
216,
|
|
750
|
+
255
|
|
751
|
+
]]]],
|
|
752
|
+
["image/png", [[0, [
|
|
753
|
+
137,
|
|
754
|
+
80,
|
|
755
|
+
78,
|
|
756
|
+
71
|
|
757
|
+
]]]],
|
|
758
|
+
["image/gif", [[0, [
|
|
759
|
+
71,
|
|
760
|
+
73,
|
|
761
|
+
70,
|
|
762
|
+
56
|
|
763
|
+
]]]],
|
|
764
|
+
["image/webp", [[0, [
|
|
765
|
+
82,
|
|
766
|
+
73,
|
|
767
|
+
70,
|
|
768
|
+
70
|
|
769
|
+
]], [8, [
|
|
770
|
+
87,
|
|
771
|
+
69,
|
|
772
|
+
66,
|
|
773
|
+
80
|
|
774
|
+
]]]],
|
|
775
|
+
["application/pdf", [[0, [
|
|
776
|
+
37,
|
|
777
|
+
80,
|
|
778
|
+
68,
|
|
779
|
+
70
|
|
780
|
+
]]]],
|
|
781
|
+
["application/zip", [[0, [
|
|
782
|
+
80,
|
|
783
|
+
75,
|
|
784
|
+
3,
|
|
785
|
+
4
|
|
786
|
+
]]]]
|
|
787
|
+
];
|
|
788
|
+
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
789
|
+
function sniff(bytes) {
|
|
790
|
+
return pipe(findFirst(signatures, (signature) => every(signature[1], (part) => every(part[1], (byte, index) => bytes[part[0] + index] === byte))), map((signature) => signature[0]), orElse(() => liftPredicate("text/plain", () => isSuccess(try_(() => utf8.decode(bytes))))), getOrNull);
|
|
791
|
+
}
|
|
792
|
+
function toolFile(bytes, declared, filename) {
|
|
793
|
+
return {
|
|
794
|
+
_tag: "ToolFile",
|
|
795
|
+
contentBase64: encode(bytes),
|
|
796
|
+
contentType: declared === null || pipe(declared, startsWith("application/octet-stream")) ? sniff(bytes) ?? declared : declared,
|
|
797
|
+
filename,
|
|
798
|
+
sizeBytes: bytes.byteLength
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
function invalid(expected, value, options) {
|
|
802
|
+
return fail5(new InvalidValue({ expected }, value, options));
|
|
803
|
+
}
|
|
804
|
+
function decodeBytes(text, options) {
|
|
805
|
+
return match3(decode(pipe(text, replaceAll("+", "-"), replaceAll("/", "_"))), {
|
|
806
|
+
onFailure: () => invalid("a Base64 or Base64Url string", text, options),
|
|
807
|
+
onSuccess: (bytes) => succeed4(bytes)
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
function contentOf(carrier) {
|
|
811
|
+
return transformEffect((text, options) => {
|
|
812
|
+
if (carrier !== "data-uri")
|
|
813
|
+
return map4(decodeBytes(text, options), (bytes) => ({
|
|
814
|
+
bytes,
|
|
815
|
+
contentType: null
|
|
816
|
+
}));
|
|
817
|
+
return match2(pipe(text, match4(/^data:([^;,]*)(?:;[^;,]*)*;base64,(.*)$/su)), {
|
|
818
|
+
onNone: () => invalid("a Base64 data URI", text, options),
|
|
819
|
+
onSome: (parts) => map4(decodeBytes(getUnsafe2(parts, 2), options), (bytes) => ({
|
|
820
|
+
bytes,
|
|
821
|
+
contentType: pipe(getUnsafe2(parts, 1), liftPredicate(isNonEmpty), getOrNull)
|
|
822
|
+
}))
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
function textOf(carrier, content) {
|
|
827
|
+
if (carrier === "base64")
|
|
828
|
+
return encode(content.bytes);
|
|
829
|
+
if (carrier === "base64url")
|
|
830
|
+
return encode2(content.bytes);
|
|
831
|
+
return `data:${content.contentType ?? sniff(content.bytes) ?? "application/octet-stream"};base64,${encode(content.bytes)}`;
|
|
832
|
+
}
|
|
833
|
+
function fileFrom(carrier) {
|
|
834
|
+
return String3.pipe(decodeTo(Schema, {
|
|
835
|
+
decode: compose2(contentOf(carrier), transform((content) => toolFile(content.bytes, content.contentType, null))),
|
|
836
|
+
encode: transformEffect((file, options) => map4(decodeBytes(file.contentBase64, options), (bytes) => textOf(carrier, {
|
|
837
|
+
bytes,
|
|
838
|
+
contentType: file.contentType
|
|
839
|
+
})))
|
|
840
|
+
}));
|
|
841
|
+
}
|
|
842
|
+
function encodedFrom(carrier) {
|
|
843
|
+
return File2.pipe(decodeTo(String3, {
|
|
844
|
+
decode: transform((file) => textOf(carrier, {
|
|
845
|
+
bytes: file.contentBase64,
|
|
846
|
+
contentType: file.contentType ?? null
|
|
847
|
+
})),
|
|
848
|
+
encode: compose2(contentOf(carrier), transform((content) => ({
|
|
849
|
+
contentBase64: content.bytes,
|
|
850
|
+
contentType: content.contentType
|
|
851
|
+
})))
|
|
852
|
+
}));
|
|
853
|
+
}
|
|
854
|
+
var FileFromBase642 = fileFrom("base64");
|
|
855
|
+
var FileFromBase64Url2 = fileFrom("base64url");
|
|
856
|
+
var Base64FromFile2 = encodedFrom("base64");
|
|
857
|
+
var Base64UrlFromFile2 = encodedFrom("base64url");
|
|
858
|
+
var FileFromDataUri2 = fileFrom("data-uri");
|
|
859
|
+
var DataUriFromFile2 = encodedFrom("data-uri");
|
|
860
|
+
var DateTimeText = String3.annotate({ format: "date-time" });
|
|
861
|
+
var rfc3339 = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.\d+)?(?:Z|([+-]\d{2}:\d{2}))$/u;
|
|
862
|
+
function rfc3339Instant(text) {
|
|
863
|
+
return pipe(fromNullishOr(rfc3339.exec(text)), flatMap((match5) => filter(makeZoned(text, { timeZone: match5[2] ?? "+00:00" }), (zoned) => startsWith(match5[1] ?? "")(formatIsoOffset(zoned)))), map(toUtc));
|
|
864
|
+
}
|
|
865
|
+
function instants(wire, expected, read, write) {
|
|
866
|
+
const fromWire = transformEffect((value, options) => match2(read(value), {
|
|
867
|
+
onNone: () => invalid(expected, value, options),
|
|
868
|
+
onSome: (instant) => succeed4(formatIso(instant))
|
|
869
|
+
}));
|
|
870
|
+
const toWire = transformEffect((text, options) => match2(rfc3339Instant(text), {
|
|
871
|
+
onNone: () => invalid("an ISO 8601 date-time", text, options),
|
|
872
|
+
onSome: (instant) => succeed4(write(instant))
|
|
873
|
+
}));
|
|
874
|
+
return {
|
|
875
|
+
input: pipe(DateTimeText, decodeTo(wire, {
|
|
876
|
+
decode: toWire,
|
|
877
|
+
encode: fromWire
|
|
878
|
+
})),
|
|
879
|
+
output: pipe(wire, decodeTo(DateTimeText, {
|
|
880
|
+
decode: fromWire,
|
|
881
|
+
encode: toWire
|
|
882
|
+
}))
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
var unixSeconds = instants(Int, "Unix seconds", (seconds) => map(make3(seconds * 1000), toUtc), (instant) => Math.floor(toEpochMillis(instant) / 1000));
|
|
886
|
+
var rfc2822 = instants(String3, "an RFC 2822 date-time", (text) => map(make3(text), toUtc), (instant) => toDateUtc(instant).toUTCString());
|
|
887
|
+
var DateTimeFromUnixSeconds2 = unixSeconds.output;
|
|
888
|
+
var UnixSecondsFromDateTime2 = unixSeconds.input;
|
|
889
|
+
var DateTimeFromRfc28222 = rfc2822.output;
|
|
890
|
+
var Rfc2822FromDateTime2 = rfc2822.input;
|
|
891
|
+
function decoded2(wire) {
|
|
892
|
+
return {
|
|
893
|
+
_tag: "Decoded",
|
|
894
|
+
wire
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
var GraphqlResponse = Struct({
|
|
898
|
+
data: optionalKey(NullOr(Record(String3, Unknown))),
|
|
899
|
+
errors: optionalKey(ArraySchema(StructWithRest(Struct({ message: String3 }), [Record(String3, Unknown)])))
|
|
900
|
+
});
|
|
901
|
+
function coerce(value) {
|
|
902
|
+
return isObject(value) ? JSON.stringify(value) : `${value}`;
|
|
903
|
+
}
|
|
904
|
+
function path2(value) {
|
|
905
|
+
return encodeURIComponent(coerce(value));
|
|
906
|
+
}
|
|
907
|
+
function literal2(value) {
|
|
908
|
+
return path2(pipe(coerce(value), replaceAll("'", "''")));
|
|
909
|
+
}
|
|
910
|
+
function segments2(value) {
|
|
911
|
+
return join(map3(split(coerce(value), "/"), encodeURIComponent), "/");
|
|
912
|
+
}
|
|
913
|
+
function deepObject(name, value) {
|
|
914
|
+
if (isArray(value))
|
|
915
|
+
return flatMap2(value, (item, index) => deepObject(`${name}[${index}]`, item));
|
|
916
|
+
if (isObject(value))
|
|
917
|
+
return flatMap2(toEntries(value), (entry) => deepObject(`${name}[${entry[0]}]`, entry[1]));
|
|
918
|
+
return value === undefined ? [] : [[name, coerce(value)]];
|
|
919
|
+
}
|
|
920
|
+
function params2(fields, joined = [], deep = [], exploded = []) {
|
|
921
|
+
return flatMap2(toEntries(fields), (field) => {
|
|
922
|
+
if (field[1] === undefined)
|
|
923
|
+
return [];
|
|
924
|
+
if (contains2(deep, field[0]))
|
|
925
|
+
return deepObject(field[0], field[1]);
|
|
926
|
+
const values = field[1];
|
|
927
|
+
if (contains2(exploded, field[0]) && isObject(values) && !isArray(values))
|
|
928
|
+
return filterMap(toEntries(values), (entry) => entry[1] === undefined ? failVoid : succeed([entry[0], coerce(entry[1])]));
|
|
929
|
+
if (!isArray(values))
|
|
930
|
+
return [[field[0], coerce(values)]];
|
|
931
|
+
const separator = findFirst(joined, (entry) => {
|
|
932
|
+
const pair = isString(entry) ? [entry, ","] : entry;
|
|
933
|
+
return pair[0] === field[0] ? some(pair[1]) : none();
|
|
934
|
+
});
|
|
935
|
+
return match2(separator, {
|
|
936
|
+
onNone: () => map3(values, (item) => [field[0], coerce(item)]),
|
|
937
|
+
onSome: (value) => [[field[0], join(map3(values, coerce), value)]]
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
function filePart(bytes, name, contentType) {
|
|
942
|
+
return new globalThis.File([new Uint8Array(bytes)], name, { type: contentType });
|
|
943
|
+
}
|
|
944
|
+
function form2(payload) {
|
|
945
|
+
return map2(payload, (value, name) => map3(ensure(value), (item) => {
|
|
946
|
+
if (item === undefined)
|
|
947
|
+
return;
|
|
948
|
+
if (!is(File2)(item))
|
|
949
|
+
return coerce(item);
|
|
950
|
+
return filePart(item.contentBase64, item.filename ?? name, item.contentType ?? "application/octet-stream");
|
|
951
|
+
}));
|
|
952
|
+
}
|
|
953
|
+
function fileFailed(error) {
|
|
954
|
+
return ActionHandlerError.make({
|
|
955
|
+
cause: error,
|
|
956
|
+
message: error.message
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
function readFile(file) {
|
|
960
|
+
return pipe(read(file), mapError(fileFailed));
|
|
961
|
+
}
|
|
962
|
+
var withFile = fnUntraced(function* (request, file) {
|
|
963
|
+
return bodyUint8Array(request, yield* readFile(file), file.contentType);
|
|
964
|
+
});
|
|
965
|
+
var withForm = fnUntraced(function* (request, payload) {
|
|
966
|
+
return bodyFormDataRecord(request, fromEntries(yield* forEach(toEntries(payload), (field) => map4(forEach(filter2(ensure(field[1]), (item) => item !== undefined), (item) => gen(function* () {
|
|
967
|
+
if (!is(File3)(item))
|
|
968
|
+
return coerce(item);
|
|
969
|
+
return filePart(yield* readFile(item), item.name, item.contentType);
|
|
970
|
+
})), (parts) => [field[0], parts]))));
|
|
971
|
+
});
|
|
972
|
+
function mediaBytes(media) {
|
|
973
|
+
if (is(File3)(media))
|
|
974
|
+
return map4(readFile(media), (bytes) => ({
|
|
975
|
+
bytes,
|
|
976
|
+
contentType: media.contentType
|
|
977
|
+
}));
|
|
978
|
+
return succeed4({
|
|
979
|
+
bytes: media.contentBase64,
|
|
980
|
+
contentType: getOrNull(fromNullishOr(media.contentType))
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
function isSafeUrl(value, origin) {
|
|
984
|
+
if (!URL.canParse(value))
|
|
985
|
+
return false;
|
|
986
|
+
const url = new URL(value);
|
|
987
|
+
return url.protocol === "https:" && url.username === "" && url.password === "" && (origin === undefined || url.origin === origin);
|
|
988
|
+
}
|
|
989
|
+
function refused(message) {
|
|
990
|
+
return fail5(ActionHandlerError.make({ message }));
|
|
991
|
+
}
|
|
992
|
+
function continuation2(request, nextLink) {
|
|
993
|
+
if (nextLink === undefined)
|
|
994
|
+
return succeed4(request);
|
|
995
|
+
const declared = new URL(request.url);
|
|
996
|
+
const next = URL.canParse(nextLink) ? new URL(nextLink) : undefined;
|
|
997
|
+
if (next === undefined || !isSafeUrl(nextLink) || next.pathname !== declared.pathname)
|
|
998
|
+
return refused("A continuation URL must be an HTTPS link to the same operation path");
|
|
999
|
+
return succeed4(makeWith(request.method, `${declared.origin}${next.pathname}${next.search}`, empty5, none(), request.headers, empty7));
|
|
1000
|
+
}
|
|
1001
|
+
function preauthenticated2(method, url, ...steps) {
|
|
1002
|
+
if (!isSafeUrl(url))
|
|
1003
|
+
return refused("An upload session requires a preauthenticated HTTPS URL");
|
|
1004
|
+
return succeed4(reduce(steps, method(url), (request, step) => step(request)));
|
|
1005
|
+
}
|
|
1006
|
+
function failure(error) {
|
|
1007
|
+
return is(ActionHandlerError)(error) ? error : fromHttpClientFailure(error);
|
|
1008
|
+
}
|
|
1009
|
+
function redirect(response) {
|
|
1010
|
+
const location = response.headers["location"];
|
|
1011
|
+
if (response.status < 300 || response.status >= 400 || location === undefined)
|
|
1012
|
+
return;
|
|
1013
|
+
const sent = response.request;
|
|
1014
|
+
const url = new URL(location, sent.url);
|
|
1015
|
+
const request = response.status === 303 && sent.method !== "GET" && sent.method !== "HEAD" || (response.status === 301 || response.status === 302) && sent.method === "POST" ? setBody(setMethod(sent, "GET"), empty7) : sent;
|
|
1016
|
+
return url.origin === new URL(sent.url).origin ? setUrl(request, url) : setUrl(makeWith(request.method, "", empty5, none(), empty4, request.body), url);
|
|
1017
|
+
}
|
|
1018
|
+
function follow(client, response, redirects) {
|
|
1019
|
+
const next = redirect(response);
|
|
1020
|
+
return next === undefined || redirects === 10 ? succeed4(response) : flatMap3(client.execute(next), (result) => follow(client, result, redirects + 1));
|
|
1021
|
+
}
|
|
1022
|
+
function dispositionName(header) {
|
|
1023
|
+
if (header === undefined)
|
|
1024
|
+
return;
|
|
1025
|
+
const encoded = pipe(match4(/(?:^|;)\s*filename\*\s*=\s*UTF-8'[^']*'([^;]+)/iu)(header), flatMap((match5) => fromUndefinedOr(match5[1])));
|
|
1026
|
+
const decoded = pipe(encoded, flatMap((value) => liftThrowable(() => decodeURIComponent(trim(value)))()));
|
|
1027
|
+
return getOrElse(decoded, () => pipe(match4(/(?:^|;)\s*filename\s*=\s*(?:"((?:\\.|[^"\\])*)"|([^;]*))/iu)(header), flatMap((match5) => orElse(map(fromUndefinedOr(match5[1]), (name) => replace(/\\(.)/gu, "$1")(name)), () => map(fromUndefinedOr(match5[2]), trim))), getOrUndefined));
|
|
1028
|
+
}
|
|
1029
|
+
var read2 = fnUntraced(function* (response, body) {
|
|
1030
|
+
if (body === "json")
|
|
1031
|
+
return yield* response.json;
|
|
1032
|
+
if (body === "text")
|
|
1033
|
+
return yield* response.text;
|
|
1034
|
+
if (body === "void")
|
|
1035
|
+
return {};
|
|
1036
|
+
if (body === "unknown") {
|
|
1037
|
+
const text = yield* response.text;
|
|
1038
|
+
if (isEmpty(trim(text)))
|
|
1039
|
+
return null;
|
|
1040
|
+
return getOrElse(decodeOption(fromJsonString(Json))(text), () => text);
|
|
1041
|
+
}
|
|
1042
|
+
const bytes = new Uint8Array(yield* response.arrayBuffer);
|
|
1043
|
+
const name = dispositionName(response.headers["content-disposition"]);
|
|
1044
|
+
if (body === "file")
|
|
1045
|
+
return yield* pipe(write({
|
|
1046
|
+
bytes,
|
|
1047
|
+
contentType: getOrNull(fromUndefinedOr(response.headers["content-type"])),
|
|
1048
|
+
name: name ?? "file"
|
|
1049
|
+
}), mapError(fileFailed));
|
|
1050
|
+
return toolFile(bytes, response.headers["content-type"] ?? null, name ?? null);
|
|
1051
|
+
});
|
|
1052
|
+
function make2(auth) {
|
|
1053
|
+
const { authorize, checkResponse = () => void_2 } = auth;
|
|
1054
|
+
const send = fnUntraced(function* (context, request) {
|
|
1055
|
+
const base = yield* HttpClient;
|
|
1056
|
+
const uploadPolicy = context === undefined ? auth.preauthenticatedUploadUrl : undefined;
|
|
1057
|
+
const client = uploadPolicy === undefined ? base : mapRequestEffect(base, (outgoing) => isSafeUrl(outgoing.url) && is(uploadPolicy)(outgoing.url) ? succeed4(outgoing) : fail5(new HttpClientError({ reason: new InvalidUrlError({
|
|
1058
|
+
description: "The upload URL is not an approved provider HTTPS destination",
|
|
1059
|
+
request: outgoing
|
|
1060
|
+
}) })));
|
|
1061
|
+
const transport = transformResponse(client, flatMap3((response) => follow(client, response, 0)));
|
|
1062
|
+
const execution = (context === undefined ? transport : authorize(transport, context)).execute(isEffect(request) ? yield* request : request);
|
|
1063
|
+
const options = yield* serviceOption(RequestInit);
|
|
1064
|
+
const response = yield* match(uploadPolicy !== undefined, {
|
|
1065
|
+
onFalse: () => execution,
|
|
1066
|
+
onTrue: () => provideService(execution, RequestInit, {
|
|
1067
|
+
...getOrElse(options, () => ({})),
|
|
1068
|
+
redirect: "manual"
|
|
1069
|
+
})
|
|
1070
|
+
});
|
|
1071
|
+
if (response.status < 200 || response.status >= 300)
|
|
1072
|
+
return yield* fail5({
|
|
1073
|
+
cause: yield* response.text,
|
|
1074
|
+
response
|
|
1075
|
+
});
|
|
1076
|
+
yield* checkResponse(response);
|
|
1077
|
+
return response;
|
|
1078
|
+
});
|
|
1079
|
+
function endpoint(contract, run) {
|
|
1080
|
+
if (!isSchema(contract.output)) {
|
|
1081
|
+
const wire = contract.output.wire;
|
|
1082
|
+
return {
|
|
1083
|
+
input: contract.input,
|
|
1084
|
+
output: toType(wire),
|
|
1085
|
+
run: (input, context) => run(input, context, wire),
|
|
1086
|
+
wire
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
const output = contract.output;
|
|
1090
|
+
return {
|
|
1091
|
+
input: contract.input,
|
|
1092
|
+
output,
|
|
1093
|
+
run: (input, context) => run(input, context, output)
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
function execute(context, output, request, body) {
|
|
1097
|
+
return pipe(send(context, request), flatMap3((response) => read2(response, body)), flatMap3(decodeResponse(output)), mapError(failure));
|
|
1098
|
+
}
|
|
1099
|
+
const variants = fnUntraced(function* (context, output, request, declared, media) {
|
|
1100
|
+
const response = yield* send(context, request);
|
|
1101
|
+
const exact = flatMap2(declared, (variant) => variant.status === undefined ? [] : [variant.status]);
|
|
1102
|
+
const contentType = pipe(response.headers["content-type"] ?? "", split(";"), headNonEmpty, trim, toLowerCase);
|
|
1103
|
+
const ordered = sort(declared, mapInput(Number2, (variant) => {
|
|
1104
|
+
if (variant.body === "void" || variant.body === "unknown")
|
|
1105
|
+
return 3;
|
|
1106
|
+
if (variant.contentType === "*/*")
|
|
1107
|
+
return 2;
|
|
1108
|
+
return pipe(variant.contentType, endsWith("/*")) ? 1 : 0;
|
|
1109
|
+
}));
|
|
1110
|
+
const variant = findFirst(ordered, (candidate) => {
|
|
1111
|
+
if (!(candidate.status === undefined ? !contains2(exact, response.status) : candidate.status === response.status))
|
|
1112
|
+
return false;
|
|
1113
|
+
if (media !== undefined)
|
|
1114
|
+
return (candidate.body === "binary" || candidate.body === "file") === media;
|
|
1115
|
+
if (candidate.body === "void" || candidate.body === "unknown" || candidate.contentType === "*/*")
|
|
1116
|
+
return true;
|
|
1117
|
+
if (pipe(candidate.contentType, endsWith("/*")))
|
|
1118
|
+
return pipe(contentType, startsWith(pipe(candidate.contentType, slice(0, -1))));
|
|
1119
|
+
return contentType === candidate.contentType;
|
|
1120
|
+
});
|
|
1121
|
+
if (isNone(variant))
|
|
1122
|
+
return yield* fail5({
|
|
1123
|
+
cause: "The API returned an undeclared successful response",
|
|
1124
|
+
response
|
|
1125
|
+
});
|
|
1126
|
+
const headers = flatMap2(variant.value.headers ?? [], (name) => {
|
|
1127
|
+
const value = response.headers[toLowerCase(name)];
|
|
1128
|
+
return value === undefined ? [] : [[name, value]];
|
|
1129
|
+
});
|
|
1130
|
+
return yield* decodeResponse(output)({
|
|
1131
|
+
body: yield* read2(response, variant.value.body),
|
|
1132
|
+
contentType: variant.value.contentType,
|
|
1133
|
+
status: response.status,
|
|
1134
|
+
...variant.value.headers === undefined ? {} : { headers: fromEntries(headers) }
|
|
1135
|
+
});
|
|
1136
|
+
}, mapError(failure));
|
|
1137
|
+
return {
|
|
1138
|
+
endpoint,
|
|
1139
|
+
execute,
|
|
1140
|
+
googleUpload: fnUntraced(function* (context, output, request, payload, options) {
|
|
1141
|
+
const client = authorize(yield* HttpClient, context);
|
|
1142
|
+
const media = "media" in payload ? yield* mediaBytes(payload.media) : undefined;
|
|
1143
|
+
const size = "totalBytes" in payload ? payload.totalBytes : media?.bytes.byteLength ?? 0;
|
|
1144
|
+
if (size < 0 || options.maxSize !== undefined && size > options.maxSize)
|
|
1145
|
+
return yield* refused("The upload size is outside the API's declared limit");
|
|
1146
|
+
const origin = new URL(request.url).origin;
|
|
1147
|
+
if (payload.mode === "start") {
|
|
1148
|
+
if (options.resumable === undefined)
|
|
1149
|
+
return yield* refused("This API has no resumable upload protocol");
|
|
1150
|
+
const response = yield* client.execute(pipe(setUrl(request, options.resumable), setUrlParam("uploadType", "resumable"), setHeaders({
|
|
1151
|
+
"x-upload-content-length": `${size}`,
|
|
1152
|
+
"x-upload-content-type": payload.contentType
|
|
1153
|
+
}), bodyJsonUnsafe(payload.metadata ?? {})));
|
|
1154
|
+
if (response.status < 200 || response.status >= 300)
|
|
1155
|
+
return yield* fail5({
|
|
1156
|
+
cause: yield* response.text,
|
|
1157
|
+
response
|
|
1158
|
+
});
|
|
1159
|
+
const sessionUrl = response.headers["location"];
|
|
1160
|
+
if (sessionUrl === undefined || !isSafeUrl(sessionUrl, origin))
|
|
1161
|
+
return yield* fail5({
|
|
1162
|
+
cause: "The API returned an invalid upload session URL",
|
|
1163
|
+
response
|
|
1164
|
+
});
|
|
1165
|
+
return yield* decodeResponse(output)({
|
|
1166
|
+
nextOffset: 0,
|
|
1167
|
+
sessionUrl,
|
|
1168
|
+
state: "pending"
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
if (payload.mode === "chunk" || payload.mode === "status") {
|
|
1172
|
+
if (!isSafeUrl(payload.sessionUrl, origin))
|
|
1173
|
+
return yield* refused("The upload session URL must use the API's HTTPS origin");
|
|
1174
|
+
const bytes = media?.bytes ?? /* @__PURE__ */ new Uint8Array;
|
|
1175
|
+
const end = payload.mode === "chunk" ? payload.offset + bytes.byteLength : 0;
|
|
1176
|
+
if (payload.mode === "chunk" && (payload.offset < 0 || bytes.byteLength === 0 || end > size || end < size && bytes.byteLength % 262144 !== 0))
|
|
1177
|
+
return yield* refused("Upload chunks must fit the total size and use 256 KiB multiples except for the final chunk");
|
|
1178
|
+
const response = yield* client.execute(pipe(put(payload.sessionUrl), bodyUint8Array(bytes, media?.contentType ?? "application/octet-stream"), setHeader("content-range", payload.mode === "status" ? `bytes */${size}` : `bytes ${payload.offset}-${end - 1}/${size}`)));
|
|
1179
|
+
if (response.status === 308) {
|
|
1180
|
+
const range = response.headers["range"];
|
|
1181
|
+
if (range !== undefined && !/^bytes=0-\d+$/u.test(range))
|
|
1182
|
+
return yield* fail5({
|
|
1183
|
+
cause: "The API returned an invalid upload range",
|
|
1184
|
+
response
|
|
1185
|
+
});
|
|
1186
|
+
const nextOffset = range === undefined ? 0 : Number(pipe(range, slice(8))) + 1;
|
|
1187
|
+
if (nextOffset > size)
|
|
1188
|
+
return yield* fail5({
|
|
1189
|
+
cause: "The API returned an upload offset beyond the total size",
|
|
1190
|
+
response
|
|
1191
|
+
});
|
|
1192
|
+
return yield* decodeResponse(output)({
|
|
1193
|
+
nextOffset,
|
|
1194
|
+
sessionUrl: payload.sessionUrl,
|
|
1195
|
+
state: "pending"
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
if (response.status < 200 || response.status >= 300)
|
|
1199
|
+
return yield* fail5({
|
|
1200
|
+
cause: yield* response.text,
|
|
1201
|
+
response
|
|
1202
|
+
});
|
|
1203
|
+
return yield* decodeResponse(output)({
|
|
1204
|
+
resource: yield* response.json,
|
|
1205
|
+
state: "complete"
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
const selected = setUrlParam(request, "uploadType", payload.mode);
|
|
1209
|
+
const bytes = media?.bytes ?? /* @__PURE__ */ new Uint8Array;
|
|
1210
|
+
const contentType = media?.contentType ?? "application/octet-stream";
|
|
1211
|
+
const boundary = `dual-${yield* nextInt}-${yield* nextInt}`;
|
|
1212
|
+
const metadata = payload.mode === "multipart" ? yield* encodeEffect(fromJsonString(Unknown))(payload.metadata) : "";
|
|
1213
|
+
const body = payload.mode === "media" ? bodyUint8Array(selected, bytes, contentType) : bodyUint8Array(selected, new Uint8Array(yield* promise(() => new Blob([
|
|
1214
|
+
`--${boundary}\r
|
|
1215
|
+
Content-Type: application/json; charset=UTF-8\r
|
|
1216
|
+
\r
|
|
1217
|
+
${metadata}\r
|
|
1218
|
+
--${boundary}\r
|
|
1219
|
+
Content-Type: ${contentType}\r
|
|
1220
|
+
\r
|
|
1221
|
+
`,
|
|
1222
|
+
new Uint8Array(bytes),
|
|
1223
|
+
`\r
|
|
1224
|
+
--${boundary}--\r
|
|
1225
|
+
`
|
|
1226
|
+
]).arrayBuffer())), `multipart/related; boundary=${boundary}`);
|
|
1227
|
+
const response = yield* client.execute(body);
|
|
1228
|
+
if (response.status < 200 || response.status >= 300)
|
|
1229
|
+
return yield* fail5({
|
|
1230
|
+
cause: yield* response.text,
|
|
1231
|
+
response
|
|
1232
|
+
});
|
|
1233
|
+
return yield* decodeResponse(output)({
|
|
1234
|
+
resource: yield* response.json,
|
|
1235
|
+
state: "complete"
|
|
1236
|
+
});
|
|
1237
|
+
}, mapError(failure)),
|
|
1238
|
+
graphql: fnUntraced(function* (context, output, request, field) {
|
|
1239
|
+
const response = yield* send(context, request);
|
|
1240
|
+
const body = yield* decodeUnknownEffect(GraphqlResponse)(yield* response.json);
|
|
1241
|
+
if (body.errors !== undefined && isReadonlyArrayNonEmpty(body.errors))
|
|
1242
|
+
return yield* ActionHandlerError.make({
|
|
1243
|
+
details: body.errors,
|
|
1244
|
+
message: join(map3(body.errors, (error) => error.message), "; ")
|
|
1245
|
+
});
|
|
1246
|
+
return yield* decodeResponse(output)(body.data?.[field]);
|
|
1247
|
+
}, mapError(failure)),
|
|
1248
|
+
mcp: fnUntraced(function* (context, output, server, tool, args, structured) {
|
|
1249
|
+
const connection = yield* connect(authorize(yield* HttpClient, context), server, {});
|
|
1250
|
+
const result = yield* decodeUnknownEffect(CallToolResult)(yield* connection.request("tools/call", {
|
|
1251
|
+
arguments: args,
|
|
1252
|
+
name: tool
|
|
1253
|
+
}));
|
|
1254
|
+
if (result.isError === true)
|
|
1255
|
+
return yield* ActionHandlerError.make({
|
|
1256
|
+
details: result.content,
|
|
1257
|
+
message: join(flatMap2(result.content, (block) => fromNullishOr2(block.text)), `
|
|
1258
|
+
`)
|
|
1259
|
+
});
|
|
1260
|
+
return yield* decodeResponse(output)(match(structured, {
|
|
1261
|
+
onFalse: () => ({ content: result.content }),
|
|
1262
|
+
onTrue: () => result.structuredContent
|
|
1263
|
+
}));
|
|
1264
|
+
}, scoped, mapError((error) => is(McpError)(error) ? ActionHandlerError.make({ message: error.message }) : failure(error))),
|
|
1265
|
+
variants
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
// dist/auth.js
|
|
1270
|
+
var auth_exports2 = /* @__PURE__ */ __exportAll2({
|
|
1271
|
+
authMethods: () => authMethods2,
|
|
1272
|
+
authorize: () => authorize2
|
|
1273
|
+
});
|
|
1274
|
+
var OrganizationUrl = String3.check(isPattern(/^https:\/\/[a-z0-9-]+(?:\.[a-z0-9-]+)+$/u)).annotate({ description: "The Dynamics 365 organization URL, such as https://contoso.crm4.dynamics.com" });
|
|
1275
|
+
var TenantId = String3.check(isPattern(/^[a-zA-Z0-9.-]+$/u));
|
|
1276
|
+
var ApplicationSetup = Struct({
|
|
1277
|
+
clientId: NonEmptyString,
|
|
1278
|
+
clientSecret: NonEmptyString,
|
|
1279
|
+
organizationUrl: OrganizationUrl,
|
|
1280
|
+
tenantId: TenantId
|
|
1281
|
+
});
|
|
1282
|
+
var TokenResponse = Struct({
|
|
1283
|
+
access_token: NonEmptyString,
|
|
1284
|
+
expires_in: Int.check(isGreaterThan(0))
|
|
1285
|
+
});
|
|
1286
|
+
var Connection = Struct({
|
|
1287
|
+
accessToken: String3,
|
|
1288
|
+
organizationUrl: OrganizationUrl
|
|
1289
|
+
});
|
|
1290
|
+
var acquire = fn("Dynamics.application.acquire")(function* (setup) {
|
|
1291
|
+
const client = filterStatusOk(yield* HttpClient);
|
|
1292
|
+
const now = yield* currentTimeMillis;
|
|
1293
|
+
const token = yield* pipe(post(`https://login.microsoftonline.com/${setup.tenantId}/oauth2/v2.0/token`), bodyUrlParams({
|
|
1294
|
+
client_id: setup.clientId,
|
|
1295
|
+
client_secret: setup.clientSecret,
|
|
1296
|
+
grant_type: "client_credentials",
|
|
1297
|
+
scope: `${setup.organizationUrl}/.default`
|
|
1298
|
+
}), client.execute, flatMap3(schemaBodyJson(TokenResponse)));
|
|
1299
|
+
return {
|
|
1300
|
+
accessToken: token.access_token,
|
|
1301
|
+
expiresAt: now + token.expires_in * 1000
|
|
1302
|
+
};
|
|
1303
|
+
});
|
|
1304
|
+
function scope(organizationUrl) {
|
|
1305
|
+
return { scope: `openid offline_access ${organizationUrl}/user_impersonation` };
|
|
1306
|
+
}
|
|
1307
|
+
var authMethods2 = [AuthMethod_exports.oauth2("oauth", {
|
|
1308
|
+
authorizationParams: (context) => ({
|
|
1309
|
+
...scope(context.setup.organizationUrl),
|
|
1310
|
+
prompt: "select_account"
|
|
1311
|
+
}),
|
|
1312
|
+
authorizationUrl: (context) => `https://login.microsoftonline.com/${context.setup.tenantId}/oauth2/v2.0/authorize`,
|
|
1313
|
+
client: (context) => ({
|
|
1314
|
+
authentication: "post",
|
|
1315
|
+
clientId: context.setup.clientId,
|
|
1316
|
+
clientSecret: context.setup.clientSecret
|
|
1317
|
+
}),
|
|
1318
|
+
description: "A Dynamics 365 user of one organization. The Entra app registration needs the Dynamics CRM user_impersonation permission.",
|
|
1319
|
+
material: AuthMethod_exports.OAuth2TokenMaterial,
|
|
1320
|
+
name: "Dynamics 365 account",
|
|
1321
|
+
resolve: (material, context) => ({
|
|
1322
|
+
accessToken: material.accessToken,
|
|
1323
|
+
organizationUrl: context.setup.organizationUrl
|
|
1324
|
+
}),
|
|
1325
|
+
scopes: [],
|
|
1326
|
+
setup: Struct({
|
|
1327
|
+
clientId: String3,
|
|
1328
|
+
clientSecret: String3,
|
|
1329
|
+
organizationUrl: OrganizationUrl,
|
|
1330
|
+
tenantId: pipe(TenantId, withDecodingDefaultKey(succeed4("common")))
|
|
1331
|
+
}),
|
|
1332
|
+
tokenParams: (context) => scope(context.setup.organizationUrl),
|
|
1333
|
+
tokenUrl: (context) => `https://login.microsoftonline.com/${context.setup.tenantId}/oauth2/v2.0/token`,
|
|
1334
|
+
value: Connection
|
|
1335
|
+
}), AuthMethod_exports.auth("application", {
|
|
1336
|
+
description: "An application user of one organization, created in the Power Platform admin center with its security roles.",
|
|
1337
|
+
input: Struct({}),
|
|
1338
|
+
material: Struct({
|
|
1339
|
+
accessToken: String3,
|
|
1340
|
+
expiresAt: Finite
|
|
1341
|
+
}),
|
|
1342
|
+
name: "Dynamics 365 application",
|
|
1343
|
+
prepare: (_, context) => acquire(context.setup),
|
|
1344
|
+
refresh: (material, context) => context.reason === "forced" || material.expiresAt <= context.now + context.minValidityMs ? acquire(context.setup) : undefined,
|
|
1345
|
+
resolve: (material, context) => ({
|
|
1346
|
+
accessToken: material.accessToken,
|
|
1347
|
+
organizationUrl: context.setup.organizationUrl
|
|
1348
|
+
}),
|
|
1349
|
+
setup: ApplicationSetup,
|
|
1350
|
+
value: Connection
|
|
1351
|
+
})];
|
|
1352
|
+
function authorize2(client, context) {
|
|
1353
|
+
const connection = context.auth.current.value;
|
|
1354
|
+
return mapRequest(client, (request) => pipe(request, updateUrl(replace(/^https:\/\/[^/]+/u, connection.organizationUrl)), bearerToken(connection.accessToken), setHeaders({
|
|
1355
|
+
"OData-MaxVersion": "4.0",
|
|
1356
|
+
"OData-Version": "4.0"
|
|
1357
|
+
})));
|
|
1358
|
+
}
|
|
1359
|
+
export { match, Http_exports, File2, FileFromBase642, FileFromBase64Url2, Base64FromFile2, Base64UrlFromFile2, FileFromDataUri2, DataUriFromFile2, DateTimeFromUnixSeconds2, UnixSecondsFromDateTime2, DateTimeFromRfc28222, Rfc2822FromDateTime2, decoded2, path2, literal2, segments2, params2, form2, continuation2, preauthenticated2, auth_exports2, authMethods2, authorize2 };
|
|
1360
|
+
|
|
1361
|
+
//# debugId=E7A5EC8A827F7D4D64756E2164756E21
|
|
1362
|
+
//# sourceMappingURL=plugin-y6mf6hx3.js.map
|