@muze-nl/metro-oidc 0.5.4 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +259 -144
- package/dist/browser.js.map +4 -4
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +4 -4
- package/package.json +4 -4
package/dist/browser.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
var Client = class _Client {
|
|
29
29
|
clientOptions = {
|
|
30
|
-
url: typeof window != "undefined" ? window.location : "https://localhost",
|
|
30
|
+
url: typeof window != "undefined" ? url(window.location) : url("https://localhost"),
|
|
31
31
|
verbs: ["get", "post", "put", "delete", "patch", "head", "options", "query"]
|
|
32
32
|
};
|
|
33
33
|
static tracers = {};
|
|
@@ -44,13 +44,17 @@
|
|
|
44
44
|
constructor(...options) {
|
|
45
45
|
for (let option of options) {
|
|
46
46
|
if (typeof option == "string" || option instanceof String) {
|
|
47
|
-
this.clientOptions.url =
|
|
47
|
+
this.clientOptions.url = url(this.clientOptions.url.href, option);
|
|
48
|
+
} else if (option instanceof _Client) {
|
|
49
|
+
Object.assign(this.clientOptions, option.clientOptions);
|
|
48
50
|
} else if (option instanceof Function) {
|
|
49
51
|
this.#addMiddlewares([option]);
|
|
50
52
|
} else if (option && typeof option == "object") {
|
|
51
53
|
for (let param in option) {
|
|
52
54
|
if (param == "middlewares") {
|
|
53
55
|
this.#addMiddlewares(option[param]);
|
|
56
|
+
} else if (param == "url") {
|
|
57
|
+
this.clientOptions.url = url(this.clientOptions.url.href, option[param]);
|
|
54
58
|
} else if (typeof option[param] == "function") {
|
|
55
59
|
this.clientOptions[param] = option[param](this.clientOptions[param], this.clientOptions);
|
|
56
60
|
} else {
|
|
@@ -135,14 +139,17 @@
|
|
|
135
139
|
with(...options) {
|
|
136
140
|
return new _Client(deepClone(this.clientOptions), ...options);
|
|
137
141
|
}
|
|
142
|
+
get location() {
|
|
143
|
+
return this.clientOptions.url;
|
|
144
|
+
}
|
|
138
145
|
};
|
|
139
146
|
function client(...options) {
|
|
140
147
|
return new Client(...deepClone(options));
|
|
141
148
|
}
|
|
142
149
|
function getRequestParams(req, current) {
|
|
143
|
-
let
|
|
144
|
-
if (!
|
|
145
|
-
|
|
150
|
+
let params = current || {};
|
|
151
|
+
if (!params.url && current.url) {
|
|
152
|
+
params.url = current.url;
|
|
146
153
|
}
|
|
147
154
|
for (let prop of [
|
|
148
155
|
"method",
|
|
@@ -168,31 +175,31 @@
|
|
|
168
175
|
value = value[Symbol.metroSource];
|
|
169
176
|
}
|
|
170
177
|
if (typeof value == "function") {
|
|
171
|
-
|
|
178
|
+
params[prop] = value(params[prop], params);
|
|
172
179
|
} else {
|
|
173
180
|
if (prop == "url") {
|
|
174
|
-
|
|
181
|
+
params.url = url(params.url, value);
|
|
175
182
|
} else if (prop == "headers") {
|
|
176
|
-
|
|
183
|
+
params.headers = new Headers(current.headers);
|
|
177
184
|
if (!(value instanceof Headers)) {
|
|
178
185
|
value = new Headers(req.headers);
|
|
179
186
|
}
|
|
180
187
|
for (let [key, val] of value.entries()) {
|
|
181
|
-
|
|
188
|
+
params.headers.set(key, val);
|
|
182
189
|
}
|
|
183
190
|
} else {
|
|
184
|
-
|
|
191
|
+
params[prop] = value;
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
194
|
}
|
|
188
195
|
if (req instanceof Request && req.data) {
|
|
189
|
-
|
|
196
|
+
params.body = req.data;
|
|
190
197
|
}
|
|
191
|
-
return
|
|
198
|
+
return params;
|
|
192
199
|
}
|
|
193
200
|
function request(...options) {
|
|
194
201
|
let requestParams = {
|
|
195
|
-
url: typeof window != "undefined" ? window.location : "https://localhost/",
|
|
202
|
+
url: typeof window != "undefined" ? url(window.location) : url("https://localhost/"),
|
|
196
203
|
duplex: "half"
|
|
197
204
|
// required when setting body to ReadableStream, just set it here by default already
|
|
198
205
|
};
|
|
@@ -208,7 +215,7 @@
|
|
|
208
215
|
let r = new Request(requestParams.url, requestParams);
|
|
209
216
|
let data = requestParams.body;
|
|
210
217
|
if (data) {
|
|
211
|
-
if (typeof data == "object" && !(data instanceof String) && !(data instanceof ReadableStream) && !(data instanceof Blob) && !(data instanceof ArrayBuffer) && !(data instanceof DataView) && !(data instanceof FormData) && !(data instanceof URLSearchParams) && (typeof TypedArray == "undefined" || !(data instanceof TypedArray))) {
|
|
218
|
+
if (typeof data == "object" && !(data instanceof String) && !(data instanceof ReadableStream) && !(data instanceof Blob) && !(data instanceof ArrayBuffer) && !(data instanceof DataView) && !(data instanceof FormData) && !(data instanceof URLSearchParams) && (typeof globalThis.TypedArray == "undefined" || !(data instanceof globalThis.TypedArray))) {
|
|
212
219
|
if (typeof data.toString == "function") {
|
|
213
220
|
requestParams.body = data.toString({ headers: r.headers });
|
|
214
221
|
r = new Request(requestParams.url, requestParams);
|
|
@@ -217,16 +224,17 @@
|
|
|
217
224
|
}
|
|
218
225
|
Object.freeze(r);
|
|
219
226
|
return new Proxy(r, {
|
|
220
|
-
get(target, prop
|
|
227
|
+
get(target, prop) {
|
|
228
|
+
let result;
|
|
221
229
|
switch (prop) {
|
|
222
230
|
case Symbol.metroSource:
|
|
223
|
-
|
|
231
|
+
result = target;
|
|
224
232
|
break;
|
|
225
233
|
case Symbol.metroProxy:
|
|
226
|
-
|
|
234
|
+
result = true;
|
|
227
235
|
break;
|
|
228
236
|
case "with":
|
|
229
|
-
|
|
237
|
+
result = function(...options2) {
|
|
230
238
|
if (data) {
|
|
231
239
|
options2.unshift({ body: data });
|
|
232
240
|
}
|
|
@@ -234,22 +242,26 @@
|
|
|
234
242
|
};
|
|
235
243
|
break;
|
|
236
244
|
case "data":
|
|
237
|
-
|
|
245
|
+
result = data;
|
|
246
|
+
break;
|
|
247
|
+
default:
|
|
248
|
+
if (target[prop] instanceof Function) {
|
|
249
|
+
if (prop === "clone") {
|
|
250
|
+
}
|
|
251
|
+
result = target[prop].bind(target);
|
|
252
|
+
} else {
|
|
253
|
+
result = target[prop];
|
|
254
|
+
}
|
|
238
255
|
break;
|
|
239
256
|
}
|
|
240
|
-
|
|
241
|
-
if (prop === "clone") {
|
|
242
|
-
}
|
|
243
|
-
return target[prop].bind(target);
|
|
244
|
-
}
|
|
245
|
-
return target[prop];
|
|
257
|
+
return result;
|
|
246
258
|
}
|
|
247
259
|
});
|
|
248
260
|
}
|
|
249
261
|
function getResponseParams(res, current) {
|
|
250
|
-
let
|
|
251
|
-
if (!
|
|
252
|
-
|
|
262
|
+
let params = current || {};
|
|
263
|
+
if (!params.url && current.url) {
|
|
264
|
+
params.url = current.url;
|
|
253
265
|
}
|
|
254
266
|
for (let prop of ["status", "statusText", "headers", "body", "url", "type", "redirected"]) {
|
|
255
267
|
let value = res[prop];
|
|
@@ -260,19 +272,19 @@
|
|
|
260
272
|
value = value[Symbol.metroSource];
|
|
261
273
|
}
|
|
262
274
|
if (typeof value == "function") {
|
|
263
|
-
|
|
275
|
+
params[prop] = value(params[prop], params);
|
|
264
276
|
} else {
|
|
265
277
|
if (prop == "url") {
|
|
266
|
-
|
|
278
|
+
params.url = new URL(value, params.url || "https://localhost/");
|
|
267
279
|
} else {
|
|
268
|
-
|
|
280
|
+
params[prop] = value;
|
|
269
281
|
}
|
|
270
282
|
}
|
|
271
283
|
}
|
|
272
284
|
if (res instanceof Response && res.data) {
|
|
273
|
-
|
|
285
|
+
params.body = res.data;
|
|
274
286
|
}
|
|
275
|
-
return
|
|
287
|
+
return params;
|
|
276
288
|
}
|
|
277
289
|
function response(...options) {
|
|
278
290
|
let responseParams = {};
|
|
@@ -282,7 +294,7 @@
|
|
|
282
294
|
} else if (option instanceof Response) {
|
|
283
295
|
Object.assign(responseParams, getResponseParams(option, responseParams));
|
|
284
296
|
} else if (option && typeof option == "object") {
|
|
285
|
-
if (option instanceof FormData || option instanceof Blob || option instanceof ArrayBuffer || option instanceof DataView || option instanceof ReadableStream || option instanceof URLSearchParams || option instanceof String || typeof TypedArray != "undefined" && option instanceof TypedArray) {
|
|
297
|
+
if (option instanceof FormData || option instanceof Blob || option instanceof ArrayBuffer || option instanceof DataView || option instanceof ReadableStream || option instanceof URLSearchParams || option instanceof String || typeof globalThis.TypedArray != "undefined" && option instanceof globalThis.TypedArray) {
|
|
286
298
|
responseParams.body = option;
|
|
287
299
|
} else {
|
|
288
300
|
Object.assign(responseParams, getResponseParams(option, responseParams));
|
|
@@ -299,39 +311,44 @@
|
|
|
299
311
|
let r = new Response(responseParams.body, responseParams);
|
|
300
312
|
Object.freeze(r);
|
|
301
313
|
return new Proxy(r, {
|
|
302
|
-
get(target, prop
|
|
314
|
+
get(target, prop) {
|
|
315
|
+
let result;
|
|
303
316
|
switch (prop) {
|
|
304
317
|
case Symbol.metroProxy:
|
|
305
|
-
|
|
318
|
+
result = true;
|
|
306
319
|
break;
|
|
307
320
|
case Symbol.metroSource:
|
|
308
|
-
|
|
321
|
+
result = target;
|
|
309
322
|
break;
|
|
310
323
|
case "with":
|
|
311
|
-
|
|
324
|
+
result = function(...options2) {
|
|
312
325
|
return response(target, ...options2);
|
|
313
326
|
};
|
|
314
327
|
break;
|
|
315
328
|
case "data":
|
|
316
|
-
|
|
329
|
+
result = data;
|
|
317
330
|
break;
|
|
318
331
|
case "ok":
|
|
319
|
-
|
|
332
|
+
result = target.status >= 200 && target.status < 400;
|
|
333
|
+
break;
|
|
334
|
+
default:
|
|
335
|
+
if (typeof target[prop] == "function") {
|
|
336
|
+
result = target[prop].bind(target);
|
|
337
|
+
} else {
|
|
338
|
+
result = target[prop];
|
|
339
|
+
}
|
|
320
340
|
break;
|
|
321
341
|
}
|
|
322
|
-
|
|
323
|
-
return target[prop].bind(target);
|
|
324
|
-
}
|
|
325
|
-
return target[prop];
|
|
342
|
+
return result;
|
|
326
343
|
}
|
|
327
344
|
});
|
|
328
345
|
}
|
|
329
|
-
function appendSearchParams(url2,
|
|
330
|
-
if (typeof
|
|
331
|
-
|
|
346
|
+
function appendSearchParams(url2, params) {
|
|
347
|
+
if (typeof params == "function") {
|
|
348
|
+
params(url2.searchParams, url2);
|
|
332
349
|
} else {
|
|
333
|
-
|
|
334
|
-
|
|
350
|
+
params = new URLSearchParams(params);
|
|
351
|
+
params.forEach((value, key) => {
|
|
335
352
|
url2.searchParams.append(key, value);
|
|
336
353
|
});
|
|
337
354
|
}
|
|
@@ -393,25 +410,25 @@
|
|
|
393
410
|
}
|
|
394
411
|
Object.freeze(u);
|
|
395
412
|
return new Proxy(u, {
|
|
396
|
-
get(target, prop
|
|
413
|
+
get(target, prop) {
|
|
397
414
|
let result;
|
|
398
415
|
switch (prop) {
|
|
399
416
|
case Symbol.metroProxy:
|
|
400
|
-
|
|
417
|
+
result = true;
|
|
401
418
|
break;
|
|
402
419
|
case Symbol.metroSource:
|
|
403
|
-
|
|
420
|
+
result = target;
|
|
404
421
|
break;
|
|
405
422
|
case "with":
|
|
406
|
-
|
|
423
|
+
result = function(...options2) {
|
|
407
424
|
return url(target, ...options2);
|
|
408
425
|
};
|
|
409
426
|
break;
|
|
410
427
|
case "filename":
|
|
411
|
-
|
|
428
|
+
result = target.pathname.split("/").pop();
|
|
412
429
|
break;
|
|
413
430
|
case "folderpath":
|
|
414
|
-
|
|
431
|
+
result = target.pathname.substring(0, target.pathname.lastIndexOf("\\") + 1);
|
|
415
432
|
break;
|
|
416
433
|
case "authority":
|
|
417
434
|
result = target.username ?? "";
|
|
@@ -421,78 +438,86 @@
|
|
|
421
438
|
result += target.port ? ":" + target.port : "";
|
|
422
439
|
result += "/";
|
|
423
440
|
result = target.protocol + "//" + result;
|
|
424
|
-
return result;
|
|
425
441
|
break;
|
|
426
442
|
case "origin":
|
|
427
443
|
result = target.protocol + "//" + target.hostname;
|
|
428
444
|
result += target.port ? ":" + target.port : "";
|
|
429
445
|
result += "/";
|
|
430
|
-
return result;
|
|
431
446
|
break;
|
|
432
447
|
case "fragment":
|
|
433
|
-
|
|
448
|
+
result = target.hash.substring(1);
|
|
434
449
|
break;
|
|
435
450
|
case "scheme":
|
|
436
451
|
if (target.protocol) {
|
|
437
|
-
|
|
452
|
+
result = target.protocol.substring(0, target.protocol.length - 1);
|
|
453
|
+
} else {
|
|
454
|
+
result = "";
|
|
455
|
+
}
|
|
456
|
+
break;
|
|
457
|
+
default:
|
|
458
|
+
if (target[prop] instanceof Function) {
|
|
459
|
+
result = target[prop].bind(target);
|
|
460
|
+
} else {
|
|
461
|
+
result = target[prop];
|
|
438
462
|
}
|
|
439
|
-
return "";
|
|
440
463
|
break;
|
|
441
464
|
}
|
|
442
|
-
|
|
443
|
-
return target[prop].bind(target);
|
|
444
|
-
}
|
|
445
|
-
return target[prop];
|
|
465
|
+
return result;
|
|
446
466
|
}
|
|
447
467
|
});
|
|
448
468
|
}
|
|
449
469
|
function formdata(...options) {
|
|
450
|
-
var
|
|
470
|
+
var params = new FormData();
|
|
451
471
|
for (let option of options) {
|
|
452
472
|
if (option instanceof HTMLFormElement) {
|
|
453
473
|
option = new FormData(option);
|
|
454
474
|
}
|
|
455
475
|
if (option instanceof FormData) {
|
|
456
476
|
for (let entry of option.entries()) {
|
|
457
|
-
|
|
477
|
+
params.append(entry[0], entry[1]);
|
|
458
478
|
}
|
|
459
479
|
} else if (option && typeof option == "object") {
|
|
460
480
|
for (let entry of Object.entries(option)) {
|
|
461
481
|
if (Array.isArray(entry[1])) {
|
|
462
482
|
for (let value of entry[1]) {
|
|
463
|
-
|
|
483
|
+
params.append(entry[0], value);
|
|
464
484
|
}
|
|
465
485
|
} else {
|
|
466
|
-
|
|
486
|
+
params.append(entry[0], entry[1]);
|
|
467
487
|
}
|
|
468
488
|
}
|
|
469
489
|
} else {
|
|
470
490
|
throw new metroError("metro.formdata: unknown option type " + metroURL + "formdata/unknown-option-value/", option);
|
|
471
491
|
}
|
|
472
492
|
}
|
|
473
|
-
Object.freeze(
|
|
474
|
-
return new Proxy(
|
|
475
|
-
get
|
|
493
|
+
Object.freeze(params);
|
|
494
|
+
return new Proxy(params, {
|
|
495
|
+
get(target, prop) {
|
|
496
|
+
let result;
|
|
476
497
|
switch (prop) {
|
|
477
498
|
case Symbol.metroProxy:
|
|
478
|
-
|
|
499
|
+
result = true;
|
|
479
500
|
break;
|
|
480
501
|
case Symbol.metroSource:
|
|
481
|
-
|
|
502
|
+
result = target;
|
|
482
503
|
break;
|
|
483
504
|
//TODO: add toString() that can check
|
|
484
505
|
//headers param: toString({headers:request.headers})
|
|
485
506
|
//for the content-type
|
|
486
507
|
case "with":
|
|
487
|
-
|
|
508
|
+
result = function(...options2) {
|
|
488
509
|
return formdata(target, ...options2);
|
|
489
510
|
};
|
|
490
511
|
break;
|
|
512
|
+
default:
|
|
513
|
+
if (target[prop] instanceof Function) {
|
|
514
|
+
result = target[prop].bind(target);
|
|
515
|
+
} else {
|
|
516
|
+
result = target[prop];
|
|
517
|
+
}
|
|
518
|
+
break;
|
|
491
519
|
}
|
|
492
|
-
|
|
493
|
-
return target[prop].bind(target);
|
|
494
|
-
}
|
|
495
|
-
return target[prop];
|
|
520
|
+
return result;
|
|
496
521
|
}
|
|
497
522
|
});
|
|
498
523
|
}
|
|
@@ -578,35 +603,38 @@
|
|
|
578
603
|
// node_modules/@muze-nl/metro/src/mw/json.mjs
|
|
579
604
|
function jsonmw(options) {
|
|
580
605
|
options = Object.assign({
|
|
581
|
-
|
|
606
|
+
contentType: "application/json",
|
|
582
607
|
reviver: null,
|
|
583
608
|
replacer: null,
|
|
584
609
|
space: ""
|
|
585
610
|
}, options);
|
|
586
611
|
return async function json(req, next) {
|
|
587
|
-
if (!
|
|
612
|
+
if (!req.headers.get("Accept")) {
|
|
588
613
|
req = req.with({
|
|
589
614
|
headers: {
|
|
590
|
-
"Accept": options.
|
|
615
|
+
"Accept": options.accept ?? options.contentType
|
|
591
616
|
}
|
|
592
617
|
});
|
|
593
618
|
}
|
|
594
|
-
if (
|
|
619
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
595
620
|
if (req.data && typeof req.data == "object" && !(req.data instanceof ReadableStream)) {
|
|
596
|
-
|
|
621
|
+
const contentType = req.headers.get("Content-Type");
|
|
622
|
+
if (!contentType || isPlainText(contentType)) {
|
|
597
623
|
req = req.with({
|
|
598
624
|
headers: {
|
|
599
|
-
"Content-Type": options.
|
|
625
|
+
"Content-Type": options.contentType
|
|
600
626
|
}
|
|
601
627
|
});
|
|
602
628
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
629
|
+
if (isJSON(req.headers.get("Content-Type"))) {
|
|
630
|
+
req = req.with({
|
|
631
|
+
body: JSON.stringify(req.data, options.replacer, options.space)
|
|
632
|
+
});
|
|
633
|
+
}
|
|
606
634
|
}
|
|
607
635
|
}
|
|
608
636
|
let res = await next(req);
|
|
609
|
-
if (isJSON(res.headers
|
|
637
|
+
if (res && isJSON(res.headers?.get("Content-Type"))) {
|
|
610
638
|
let tempRes = res.clone();
|
|
611
639
|
let body = await tempRes.text();
|
|
612
640
|
try {
|
|
@@ -624,6 +652,9 @@
|
|
|
624
652
|
function isJSON(contentType) {
|
|
625
653
|
return jsonRE.exec(contentType);
|
|
626
654
|
}
|
|
655
|
+
function isPlainText(contentType) {
|
|
656
|
+
return /^text\/plain\b/.exec(contentType);
|
|
657
|
+
}
|
|
627
658
|
|
|
628
659
|
// node_modules/@muze-nl/metro/src/mw/thrower.mjs
|
|
629
660
|
function throwermw(options) {
|
|
@@ -642,12 +673,64 @@
|
|
|
642
673
|
};
|
|
643
674
|
}
|
|
644
675
|
|
|
676
|
+
// node_modules/@muze-nl/metro/src/mw/getdata.mjs
|
|
677
|
+
function getdatamw() {
|
|
678
|
+
return async function getdata(req, next) {
|
|
679
|
+
let res = await next(req);
|
|
680
|
+
if (res.ok && res.data) {
|
|
681
|
+
return res.data;
|
|
682
|
+
}
|
|
683
|
+
return res;
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// node_modules/@muze-nl/metro/src/api.mjs
|
|
688
|
+
var API = class extends Client {
|
|
689
|
+
constructor(base, methods, bind = null) {
|
|
690
|
+
if (base instanceof Client) {
|
|
691
|
+
super(base.clientOptions, throwermw(), getdatamw());
|
|
692
|
+
} else {
|
|
693
|
+
super(base, throwermw(), getdatamw());
|
|
694
|
+
}
|
|
695
|
+
if (!bind) {
|
|
696
|
+
bind = this;
|
|
697
|
+
}
|
|
698
|
+
for (const methodName in methods) {
|
|
699
|
+
if (typeof methods[methodName] == "function") {
|
|
700
|
+
this[methodName] = methods[methodName].bind(bind);
|
|
701
|
+
} else if (methods[methodName] && typeof methods[methodName] == "object") {
|
|
702
|
+
this[methodName] = new this.constructor(base, methods[methodName], bind);
|
|
703
|
+
} else {
|
|
704
|
+
this[methodName] = methods[methodName];
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
var JsonAPI = class extends API {
|
|
710
|
+
constructor(base, methods, bind = null) {
|
|
711
|
+
if (base instanceof Client) {
|
|
712
|
+
super(base.with(jsonmw()), methods, bind);
|
|
713
|
+
} else {
|
|
714
|
+
super(client(base, jsonmw()), methods, bind);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
function api(...options) {
|
|
719
|
+
return new API(...deepClone(options));
|
|
720
|
+
}
|
|
721
|
+
function jsonApi(...options) {
|
|
722
|
+
return new JsonAPI(...deepClone(options));
|
|
723
|
+
}
|
|
724
|
+
|
|
645
725
|
// node_modules/@muze-nl/metro/src/everything.mjs
|
|
646
726
|
var metro = Object.assign({}, metro_exports, {
|
|
647
727
|
mw: {
|
|
648
|
-
jsonmw,
|
|
649
|
-
thrower: throwermw
|
|
650
|
-
|
|
728
|
+
json: jsonmw,
|
|
729
|
+
thrower: throwermw,
|
|
730
|
+
getdata: getdatamw
|
|
731
|
+
},
|
|
732
|
+
api,
|
|
733
|
+
jsonApi
|
|
651
734
|
});
|
|
652
735
|
if (!globalThis.metro) {
|
|
653
736
|
globalThis.metro = metro;
|
|
@@ -656,6 +739,12 @@
|
|
|
656
739
|
|
|
657
740
|
// node_modules/@muze-nl/assert/src/assert.mjs
|
|
658
741
|
globalThis.assertEnabled = false;
|
|
742
|
+
function enable() {
|
|
743
|
+
globalThis.assertEnabled = true;
|
|
744
|
+
}
|
|
745
|
+
function disable() {
|
|
746
|
+
globalThis.assertEnabled = false;
|
|
747
|
+
}
|
|
659
748
|
function assert(source, test) {
|
|
660
749
|
if (globalThis.assertEnabled) {
|
|
661
750
|
let problems = fails(source, test);
|
|
@@ -869,6 +958,24 @@
|
|
|
869
958
|
function warn(message, data, pattern, path) {
|
|
870
959
|
console.warn("\u{1F170}\uFE0F Assert: " + path, message, pattern, data);
|
|
871
960
|
}
|
|
961
|
+
globalThis.assert = {
|
|
962
|
+
warn,
|
|
963
|
+
error,
|
|
964
|
+
assert,
|
|
965
|
+
enable,
|
|
966
|
+
disable,
|
|
967
|
+
Required,
|
|
968
|
+
Recommended,
|
|
969
|
+
Optional,
|
|
970
|
+
oneOf,
|
|
971
|
+
anyOf,
|
|
972
|
+
allOf,
|
|
973
|
+
validURL,
|
|
974
|
+
validEmail,
|
|
975
|
+
instanceOf,
|
|
976
|
+
not,
|
|
977
|
+
fails
|
|
978
|
+
};
|
|
872
979
|
|
|
873
980
|
// node_modules/@muze-nl/metro-oauth2/src/tokenstore.mjs
|
|
874
981
|
function tokenStore(site) {
|
|
@@ -962,7 +1069,7 @@
|
|
|
962
1069
|
return res;
|
|
963
1070
|
}
|
|
964
1071
|
} catch (err) {
|
|
965
|
-
switch (res
|
|
1072
|
+
switch (res?.status) {
|
|
966
1073
|
case 400:
|
|
967
1074
|
// Oauth2.1 RFC 3.2.4
|
|
968
1075
|
case 401:
|
|
@@ -1019,20 +1126,20 @@
|
|
|
1019
1126
|
function getTokensFromLocation() {
|
|
1020
1127
|
if (typeof window !== "undefined" && window?.location) {
|
|
1021
1128
|
let url2 = url(window.location);
|
|
1022
|
-
let code, state,
|
|
1129
|
+
let code, state, params;
|
|
1023
1130
|
if (url2.searchParams.has("code")) {
|
|
1024
|
-
|
|
1131
|
+
params = url2.searchParams;
|
|
1025
1132
|
url2 = url2.with({ search: "" });
|
|
1026
1133
|
history.pushState({}, "", url2.href);
|
|
1027
1134
|
} else if (url2.hash) {
|
|
1028
1135
|
let query = url2.hash.substr(1);
|
|
1029
|
-
|
|
1136
|
+
params = new URLSearchParams("?" + query);
|
|
1030
1137
|
url2 = url2.with({ hash: "" });
|
|
1031
1138
|
history.pushState({}, "", url2.href);
|
|
1032
1139
|
}
|
|
1033
|
-
if (
|
|
1034
|
-
code =
|
|
1035
|
-
state =
|
|
1140
|
+
if (params) {
|
|
1141
|
+
code = params.get("code");
|
|
1142
|
+
state = params.get("state");
|
|
1036
1143
|
let storedState = options.state.get("metro/state");
|
|
1037
1144
|
if (!state || state !== storedState) {
|
|
1038
1145
|
return;
|
|
@@ -1060,7 +1167,7 @@
|
|
|
1060
1167
|
let response2 = await options.client.post(tokenReq);
|
|
1061
1168
|
if (!response2.ok) {
|
|
1062
1169
|
let msg = await response2.text();
|
|
1063
|
-
throw metroError("OAuth2mw: fetch access_token: " + response2.status + ": " + response2.statusText, { cause: tokenReq });
|
|
1170
|
+
throw metroError("OAuth2mw: fetch access_token: " + response2.status + ": " + response2.statusText + " (" + msg + ")", { cause: tokenReq });
|
|
1064
1171
|
}
|
|
1065
1172
|
let data = await response2.json();
|
|
1066
1173
|
options.tokens.set("access_token", {
|
|
@@ -1151,36 +1258,35 @@
|
|
|
1151
1258
|
throw metroError("oauth2mw: Missing options.endpoints.token url");
|
|
1152
1259
|
}
|
|
1153
1260
|
let url2 = url(oauth2.token_endpoint, { hash: "" });
|
|
1154
|
-
let
|
|
1261
|
+
let params = {
|
|
1155
1262
|
grant_type: grant_type || oauth2.grant_type,
|
|
1156
1263
|
client_id: oauth2.client_id
|
|
1157
1264
|
};
|
|
1158
1265
|
if (oauth2.client_secret) {
|
|
1159
|
-
|
|
1266
|
+
params.client_secret = oauth2.client_secret;
|
|
1160
1267
|
}
|
|
1161
1268
|
if (oauth2.scope) {
|
|
1162
|
-
|
|
1269
|
+
params.scope = oauth2.scope;
|
|
1163
1270
|
}
|
|
1164
|
-
switch (
|
|
1271
|
+
switch (params.grant_type) {
|
|
1165
1272
|
case "authorization_code":
|
|
1166
|
-
|
|
1167
|
-
|
|
1273
|
+
params.redirect_uri = oauth2.redirect_uri;
|
|
1274
|
+
params.code = options.tokens.get("authorization_code");
|
|
1168
1275
|
const code_verifier = options.tokens.get("code_verifier");
|
|
1169
1276
|
if (code_verifier) {
|
|
1170
|
-
|
|
1277
|
+
params.code_verifier = code_verifier;
|
|
1171
1278
|
}
|
|
1172
1279
|
break;
|
|
1173
1280
|
case "client_credentials":
|
|
1174
1281
|
break;
|
|
1175
1282
|
case "refresh_token":
|
|
1176
|
-
|
|
1177
|
-
params2.refresh_token = refreshToken.value;
|
|
1283
|
+
params.refresh_token = options.tokens.get("refresh_token");
|
|
1178
1284
|
break;
|
|
1179
1285
|
default:
|
|
1180
1286
|
throw new Error("Unknown grant_type: ".oauth2.grant_type);
|
|
1181
1287
|
break;
|
|
1182
1288
|
}
|
|
1183
|
-
return request(url2, { method: "POST", body: new URLSearchParams(
|
|
1289
|
+
return request(url2, { method: "POST", body: new URLSearchParams(params) });
|
|
1184
1290
|
}
|
|
1185
1291
|
}
|
|
1186
1292
|
function isExpired(token) {
|
|
@@ -1232,7 +1338,7 @@
|
|
|
1232
1338
|
if (!url2.searchParams.has("code")) {
|
|
1233
1339
|
if (url2.hash) {
|
|
1234
1340
|
let query = url2.hash.substr(1);
|
|
1235
|
-
params = new URLSearchParams("?" + query);
|
|
1341
|
+
const params = new URLSearchParams("?" + query);
|
|
1236
1342
|
if (params.has("code")) {
|
|
1237
1343
|
return true;
|
|
1238
1344
|
}
|
|
@@ -1333,35 +1439,44 @@
|
|
|
1333
1439
|
const signature = b64u(await crypto.subtle.sign(subtleAlgorithm(key), key, buf(input)));
|
|
1334
1440
|
return `${input}.${signature}`;
|
|
1335
1441
|
}
|
|
1336
|
-
var
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
input
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1442
|
+
var encodeBase64Url;
|
|
1443
|
+
if (Uint8Array.prototype.toBase64) {
|
|
1444
|
+
encodeBase64Url = (input) => {
|
|
1445
|
+
if (input instanceof ArrayBuffer) {
|
|
1446
|
+
input = new Uint8Array(input);
|
|
1447
|
+
}
|
|
1448
|
+
return input.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
1449
|
+
};
|
|
1450
|
+
} else {
|
|
1451
|
+
const CHUNK_SIZE = 32768;
|
|
1452
|
+
encodeBase64Url = (input) => {
|
|
1453
|
+
if (input instanceof ArrayBuffer) {
|
|
1454
|
+
input = new Uint8Array(input);
|
|
1455
|
+
}
|
|
1456
|
+
const arr = [];
|
|
1457
|
+
for (let i = 0; i < input.byteLength; i += CHUNK_SIZE) {
|
|
1458
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
1459
|
+
}
|
|
1460
|
+
return btoa(arr.join("")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1461
|
+
};
|
|
1346
1462
|
}
|
|
1347
1463
|
function b64u(input) {
|
|
1348
1464
|
return encodeBase64Url(input);
|
|
1349
1465
|
}
|
|
1350
|
-
function randomBytes() {
|
|
1351
|
-
return b64u(crypto.getRandomValues(new Uint8Array(32)));
|
|
1352
|
-
}
|
|
1353
1466
|
var UnsupportedOperationError = class extends Error {
|
|
1354
1467
|
constructor(message) {
|
|
1355
|
-
|
|
1468
|
+
var _a;
|
|
1469
|
+
super(message !== null && message !== void 0 ? message : "operation not supported");
|
|
1356
1470
|
this.name = this.constructor.name;
|
|
1357
|
-
Error.captureStackTrace
|
|
1471
|
+
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, this.constructor);
|
|
1358
1472
|
}
|
|
1359
1473
|
};
|
|
1360
1474
|
var OperationProcessingError = class extends Error {
|
|
1361
1475
|
constructor(message) {
|
|
1476
|
+
var _a;
|
|
1362
1477
|
super(message);
|
|
1363
1478
|
this.name = this.constructor.name;
|
|
1364
|
-
Error.captureStackTrace
|
|
1479
|
+
(_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, this, this.constructor);
|
|
1365
1480
|
}
|
|
1366
1481
|
};
|
|
1367
1482
|
function psAlg(key) {
|
|
@@ -1397,7 +1512,7 @@
|
|
|
1397
1512
|
case "ECDSA":
|
|
1398
1513
|
return esAlg(key);
|
|
1399
1514
|
case "Ed25519":
|
|
1400
|
-
return "
|
|
1515
|
+
return "Ed25519";
|
|
1401
1516
|
default:
|
|
1402
1517
|
throw new UnsupportedOperationError("unsupported CryptoKey algorithm name");
|
|
1403
1518
|
}
|
|
@@ -1414,9 +1529,9 @@
|
|
|
1414
1529
|
function epochTime() {
|
|
1415
1530
|
return Math.floor(Date.now() / 1e3);
|
|
1416
1531
|
}
|
|
1417
|
-
async function
|
|
1418
|
-
const privateKey = keypair
|
|
1419
|
-
const publicKey = keypair
|
|
1532
|
+
async function generateProof(keypair, htu, htm, nonce, accessToken, additional) {
|
|
1533
|
+
const privateKey = keypair === null || keypair === void 0 ? void 0 : keypair.privateKey;
|
|
1534
|
+
const publicKey = keypair === null || keypair === void 0 ? void 0 : keypair.publicKey;
|
|
1420
1535
|
if (!isPrivateKey(privateKey)) {
|
|
1421
1536
|
throw new TypeError('"keypair.privateKey" must be a private CryptoKey');
|
|
1422
1537
|
}
|
|
@@ -1445,21 +1560,21 @@
|
|
|
1445
1560
|
alg: determineJWSAlgorithm(privateKey),
|
|
1446
1561
|
typ: "dpop+jwt",
|
|
1447
1562
|
jwk: await publicJwk(publicKey)
|
|
1448
|
-
}, {
|
|
1449
|
-
...additional,
|
|
1563
|
+
}, Object.assign(Object.assign({}, additional), {
|
|
1450
1564
|
iat: epochTime(),
|
|
1451
|
-
jti:
|
|
1565
|
+
jti: crypto.randomUUID(),
|
|
1452
1566
|
htm,
|
|
1453
1567
|
nonce,
|
|
1454
1568
|
htu,
|
|
1455
1569
|
ath: accessToken ? b64u(await crypto.subtle.digest("SHA-256", buf(accessToken))) : void 0
|
|
1456
|
-
}, privateKey);
|
|
1570
|
+
}), privateKey);
|
|
1457
1571
|
}
|
|
1458
1572
|
async function publicJwk(key) {
|
|
1459
1573
|
const { kty, e, n, x, y, crv } = await crypto.subtle.exportKey("jwk", key);
|
|
1460
1574
|
return { kty, crv, e, n, x, y };
|
|
1461
1575
|
}
|
|
1462
1576
|
async function generateKeyPair(alg, options) {
|
|
1577
|
+
var _a;
|
|
1463
1578
|
let algorithm;
|
|
1464
1579
|
if (typeof alg !== "string" || alg.length === 0) {
|
|
1465
1580
|
throw new TypeError('"alg" must be a non-empty string');
|
|
@@ -1469,7 +1584,7 @@
|
|
|
1469
1584
|
algorithm = {
|
|
1470
1585
|
name: "RSA-PSS",
|
|
1471
1586
|
hash: "SHA-256",
|
|
1472
|
-
modulusLength:
|
|
1587
|
+
modulusLength: 2048,
|
|
1473
1588
|
publicExponent: new Uint8Array([1, 0, 1])
|
|
1474
1589
|
};
|
|
1475
1590
|
break;
|
|
@@ -1477,20 +1592,20 @@
|
|
|
1477
1592
|
algorithm = {
|
|
1478
1593
|
name: "RSASSA-PKCS1-v1_5",
|
|
1479
1594
|
hash: "SHA-256",
|
|
1480
|
-
modulusLength:
|
|
1595
|
+
modulusLength: 2048,
|
|
1481
1596
|
publicExponent: new Uint8Array([1, 0, 1])
|
|
1482
1597
|
};
|
|
1483
1598
|
break;
|
|
1484
1599
|
case "ES256":
|
|
1485
1600
|
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
1486
1601
|
break;
|
|
1487
|
-
case "
|
|
1602
|
+
case "Ed25519":
|
|
1488
1603
|
algorithm = { name: "Ed25519" };
|
|
1489
1604
|
break;
|
|
1490
1605
|
default:
|
|
1491
1606
|
throw new UnsupportedOperationError();
|
|
1492
1607
|
}
|
|
1493
|
-
return crypto.subtle.generateKey(algorithm, options
|
|
1608
|
+
return crypto.subtle.generateKey(algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, ["sign", "verify"]);
|
|
1494
1609
|
}
|
|
1495
1610
|
|
|
1496
1611
|
// node_modules/@muze-nl/metro-oauth2/src/oauth2.dpop.mjs
|
|
@@ -1512,14 +1627,14 @@
|
|
|
1512
1627
|
}
|
|
1513
1628
|
const url2 = everything_default.url(req.url);
|
|
1514
1629
|
if (req.url.startsWith(options.authorization_endpoint)) {
|
|
1515
|
-
let
|
|
1516
|
-
if (
|
|
1517
|
-
|
|
1630
|
+
let params = req.body;
|
|
1631
|
+
if (params instanceof URLSearchParams || params instanceof FormData) {
|
|
1632
|
+
params.set("dpop_jkt", keyInfo.keyPair.publicKey);
|
|
1518
1633
|
} else {
|
|
1519
|
-
|
|
1634
|
+
params.dpop_jkt = keyInfo.keyPair.publicKey;
|
|
1520
1635
|
}
|
|
1521
1636
|
} else if (req.url.startsWith(options.token_endpoint)) {
|
|
1522
|
-
const dpopHeader = await
|
|
1637
|
+
const dpopHeader = await generateProof(keyInfo.keyPair, req.url, req.method);
|
|
1523
1638
|
req = req.with({
|
|
1524
1639
|
headers: {
|
|
1525
1640
|
"DPoP": dpopHeader
|
|
@@ -1528,7 +1643,7 @@
|
|
|
1528
1643
|
} else if (req.headers.has("Authorization")) {
|
|
1529
1644
|
const nonce = localStorage.getItem(url2.host + ":nonce") || void 0;
|
|
1530
1645
|
const accessToken = req.headers.get("Authorization").split(" ")[1];
|
|
1531
|
-
const dpopHeader = await
|
|
1646
|
+
const dpopHeader = await generateProof(keyInfo.keyPair, req.url, req.method, nonce, accessToken);
|
|
1532
1647
|
req = req.with({
|
|
1533
1648
|
headers: {
|
|
1534
1649
|
"Authorization": "DPoP " + accessToken,
|