@securitydept/client 0.3.0-beta.5 → 0.3.0-beta.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/{create-Bm-XRA3G.mjs → create-99Ksgl_O.mjs} +13 -634
- package/dist/create-99Ksgl_O.mjs.map +1 -0
- package/dist/handle-TnxwtQ4T.mjs +634 -0
- package/dist/handle-TnxwtQ4T.mjs.map +1 -0
- package/dist/{index-Ch8lrE44.d.mts → index-Cg_iY2yY.d.mts} +4 -21
- package/dist/{index-D5mW18cM.d.mts → index-DmIapvr-.d.mts} +50 -29
- package/dist/{index-BT-u3qNI.d.mts → index-O1A3CdBV.d.mts} +4 -18
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +9 -8
- package/dist/index.mjs.map +1 -1
- package/dist/{router-BJ8LqNJ1.mjs → router-DUh3bhLy.mjs} +4 -4
- package/dist/{router-BJ8LqNJ1.mjs.map → router-DUh3bhLy.mjs.map} +1 -1
- package/dist/rx/index.d.mts +1 -2
- package/dist/rx/index.mjs +1 -1
- package/dist/{rx-BoB32Dzg.mjs → rx-B3OU17wu.mjs} +1 -2
- package/dist/{rx-BoB32Dzg.mjs.map → rx-B3OU17wu.mjs.map} +1 -1
- package/dist/server/index.d.mts +1 -2
- package/dist/server/index.mjs +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/dist/test/index.d.mts +2 -3
- package/dist/test/index.mjs +3 -3
- package/dist/test/index.mjs.map +1 -1
- package/dist/{uri-string-BfnIT4gJ.mjs → uri-string-BPNbIMgv.mjs} +5 -3
- package/dist/{uri-string-BfnIT4gJ.mjs.map → uri-string-BPNbIMgv.mjs.map} +1 -1
- package/dist/web/index.d.mts +16 -4
- package/dist/web/index.mjs +27 -21
- package/dist/web/index.mjs.map +1 -1
- package/dist/webext/index.d.mts +2 -3
- package/dist/webext/index.mjs +12 -10
- package/dist/webext/index.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/create-Bm-XRA3G.mjs.map +0 -1
|
@@ -1,126 +1,8 @@
|
|
|
1
|
-
import { A as RxEventSubject,
|
|
1
|
+
import { A as RxEventSubject, F as SYMBOL_DISPOSE, G as UserRecovery, H as ClientErrorKind, M as isInteropObservableTrait, U as ClientErrorSource, V as ClientError, j as SYMBOL_OBSERVABLE, k as RxEventStream } from "./rx-B3OU17wu.mjs";
|
|
2
2
|
import { v7 } from "uuid";
|
|
3
3
|
import { InjectionToken, Injector, Optional, ReflectiveInjector } from "injection-js";
|
|
4
|
-
import {
|
|
4
|
+
import { EMPTY, from, fromEventPattern, map, merge, of } from "rxjs";
|
|
5
5
|
import { type } from "arktype";
|
|
6
|
-
//#region src/errors/presentation-descriptor.ts
|
|
7
|
-
const DEFAULT_RECOVERY_LABELS = {
|
|
8
|
-
[UserRecovery.None]: "",
|
|
9
|
-
[UserRecovery.Retry]: "Try again",
|
|
10
|
-
[UserRecovery.RestartFlow]: "Restart flow",
|
|
11
|
-
[UserRecovery.Reauthenticate]: "Sign in again",
|
|
12
|
-
[UserRecovery.ContactSupport]: "Contact support"
|
|
13
|
-
};
|
|
14
|
-
const userRecoveryValues = new Set(Object.values(UserRecovery));
|
|
15
|
-
const clientErrorKindValues = new Set(Object.values(ClientErrorKind));
|
|
16
|
-
function readErrorPresentationDescriptor(error, options = {}) {
|
|
17
|
-
const clientError = error instanceof ClientError ? error : coerceClientErrorLike(error);
|
|
18
|
-
if (!clientError) return {
|
|
19
|
-
code: null,
|
|
20
|
-
kind: null,
|
|
21
|
-
title: options.fallbackTitle ?? "Operation failed",
|
|
22
|
-
description: options.fallbackDescription ?? "An unexpected error prevented the operation from completing.",
|
|
23
|
-
recovery: UserRecovery.None,
|
|
24
|
-
retryable: false,
|
|
25
|
-
tone: ErrorPresentationTone.Danger,
|
|
26
|
-
primaryAction: null
|
|
27
|
-
};
|
|
28
|
-
const code = clientError.presentation?.code ?? clientError.code;
|
|
29
|
-
const codePresentation = code ? options.codePresentations?.[code] : void 0;
|
|
30
|
-
const recovery = clientError.presentation?.recovery ?? codePresentation?.recovery ?? clientError.recovery;
|
|
31
|
-
const generic = readGenericPresentation(clientError.kind);
|
|
32
|
-
return {
|
|
33
|
-
code,
|
|
34
|
-
kind: clientError.kind,
|
|
35
|
-
source: clientError.source,
|
|
36
|
-
title: codePresentation?.title ?? generic.title,
|
|
37
|
-
description: clientError.presentation?.message ?? codePresentation?.description ?? generic.description,
|
|
38
|
-
recovery,
|
|
39
|
-
retryable: clientError.retryable,
|
|
40
|
-
tone: codePresentation?.tone ?? readClientErrorTone(clientError.kind, recovery),
|
|
41
|
-
primaryAction: readPrimaryAction(recovery, options)
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function readGenericPresentation(kind) {
|
|
45
|
-
switch (kind) {
|
|
46
|
-
case ClientErrorKind.Unauthenticated: return {
|
|
47
|
-
title: "Authentication required",
|
|
48
|
-
description: "Sign in again to continue."
|
|
49
|
-
};
|
|
50
|
-
case ClientErrorKind.Unauthorized: return {
|
|
51
|
-
title: "Access denied",
|
|
52
|
-
description: "You do not have permission to complete this operation."
|
|
53
|
-
};
|
|
54
|
-
case ClientErrorKind.Cancelled: return {
|
|
55
|
-
title: "Operation cancelled",
|
|
56
|
-
description: "The operation was cancelled before it completed."
|
|
57
|
-
};
|
|
58
|
-
case ClientErrorKind.Timeout: return {
|
|
59
|
-
title: "Request timed out",
|
|
60
|
-
description: "The operation did not complete in time."
|
|
61
|
-
};
|
|
62
|
-
case ClientErrorKind.Configuration: return {
|
|
63
|
-
title: "Configuration error",
|
|
64
|
-
description: "The client is not configured to complete this operation."
|
|
65
|
-
};
|
|
66
|
-
case ClientErrorKind.Storage: return {
|
|
67
|
-
title: "Storage failed",
|
|
68
|
-
description: "The client could not access required stored data."
|
|
69
|
-
};
|
|
70
|
-
case ClientErrorKind.Transport: return {
|
|
71
|
-
title: "Network request failed",
|
|
72
|
-
description: "The client could not reach the service."
|
|
73
|
-
};
|
|
74
|
-
case ClientErrorKind.Server: return {
|
|
75
|
-
title: "Server request failed",
|
|
76
|
-
description: "The service could not complete the request."
|
|
77
|
-
};
|
|
78
|
-
case ClientErrorKind.Protocol: return {
|
|
79
|
-
title: "Invalid response",
|
|
80
|
-
description: "The service response did not satisfy the expected protocol."
|
|
81
|
-
};
|
|
82
|
-
case ClientErrorKind.Authorization: return {
|
|
83
|
-
title: "Authorization failed",
|
|
84
|
-
description: "The authorization flow could not be completed."
|
|
85
|
-
};
|
|
86
|
-
default: return {
|
|
87
|
-
title: "Operation failed",
|
|
88
|
-
description: "The operation could not be completed."
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function readClientErrorTone(kind, recovery) {
|
|
93
|
-
if (kind === ClientErrorKind.Cancelled) return ErrorPresentationTone.Neutral;
|
|
94
|
-
if (kind === ClientErrorKind.Unauthenticated || kind === ClientErrorKind.Timeout || kind === ClientErrorKind.Transport || kind === ClientErrorKind.Server || recovery === UserRecovery.Retry || recovery === UserRecovery.RestartFlow || recovery === UserRecovery.Reauthenticate) return ErrorPresentationTone.Warning;
|
|
95
|
-
return ErrorPresentationTone.Danger;
|
|
96
|
-
}
|
|
97
|
-
function coerceClientErrorLike(error) {
|
|
98
|
-
if (typeof error !== "object" || error === null) return null;
|
|
99
|
-
const candidate = error;
|
|
100
|
-
if (typeof candidate.kind !== "string" || !clientErrorKindValues.has(candidate.kind)) return null;
|
|
101
|
-
return {
|
|
102
|
-
code: typeof candidate.code === "string" ? candidate.code : null,
|
|
103
|
-
kind: candidate.kind,
|
|
104
|
-
recovery: typeof candidate.recovery === "string" && userRecoveryValues.has(candidate.recovery) ? candidate.recovery : UserRecovery.None,
|
|
105
|
-
retryable: candidate.retryable === true,
|
|
106
|
-
source: typeof candidate.source === "string" ? candidate.source : void 0,
|
|
107
|
-
presentation: isErrorPresentation(candidate.presentation) ? candidate.presentation : void 0
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
function isErrorPresentation(value) {
|
|
111
|
-
return typeof value === "object" && value !== null && typeof value.code === "string" && typeof value.message === "string" && typeof value.recovery === "string" && userRecoveryValues.has(value.recovery);
|
|
112
|
-
}
|
|
113
|
-
function readPrimaryAction(recovery, options) {
|
|
114
|
-
if (recovery === UserRecovery.None) return null;
|
|
115
|
-
const label = options.recoveryLabels?.[recovery] ?? DEFAULT_RECOVERY_LABELS[recovery];
|
|
116
|
-
if (!label) return null;
|
|
117
|
-
return {
|
|
118
|
-
recovery,
|
|
119
|
-
label,
|
|
120
|
-
href: options.recoveryLinks?.[recovery] ?? null
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
//#endregion
|
|
124
6
|
//#region src/injection/types.ts
|
|
125
7
|
var SecuritydeptInjectionToken = class extends InjectionToken {};
|
|
126
8
|
const SecurityDeptOptional = Optional;
|
|
@@ -229,22 +111,6 @@ function describeDependencyToken(token) {
|
|
|
229
111
|
return String(token);
|
|
230
112
|
}
|
|
231
113
|
//#endregion
|
|
232
|
-
//#region src/signals/signal.ts
|
|
233
|
-
/**
|
|
234
|
-
* Minimal writable signal implementation.
|
|
235
|
-
* `set()` always publishes a write. Equality-based value-version suppression is
|
|
236
|
-
* handled by the underlying Rx signal for computed dependency validation.
|
|
237
|
-
*/
|
|
238
|
-
function createSignal(initial, options) {
|
|
239
|
-
return RxStateSignal.fromInitialValue(initial, options);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Create a read-only view of a writable signal.
|
|
243
|
-
*/
|
|
244
|
-
function readonlySignal(signal) {
|
|
245
|
-
return signal;
|
|
246
|
-
}
|
|
247
|
-
//#endregion
|
|
248
114
|
//#region src/events/types.ts
|
|
249
115
|
const EventStreamTraitSchema = type({ subscribe: "Function" });
|
|
250
116
|
const EventSourceKind = {
|
|
@@ -263,32 +129,6 @@ function isEventStreamTrait(value) {
|
|
|
263
129
|
const PageLifecycleTraitSchema = type({ resume: EventStreamTraitSchema });
|
|
264
130
|
const PAGE_LIFECYCLE_TRAIT_TOKEN = new SecuritydeptInjectionToken("PAGE_LIFECYCLE_TRAIT_TOKEN");
|
|
265
131
|
//#endregion
|
|
266
|
-
//#region src/popup/errors.ts
|
|
267
|
-
const PopupErrorCode = {
|
|
268
|
-
Blocked: "popup.blocked",
|
|
269
|
-
Closed: "popup.closed_by_user"
|
|
270
|
-
};
|
|
271
|
-
function readPopupErrorPresentationDescriptor(error, options = {}) {
|
|
272
|
-
return readErrorPresentationDescriptor(error, {
|
|
273
|
-
...options,
|
|
274
|
-
codePresentations: {
|
|
275
|
-
[PopupErrorCode.Blocked]: {
|
|
276
|
-
title: "Popup was blocked",
|
|
277
|
-
description: "The browser blocked the popup window. Allow popups for this site, then try again.",
|
|
278
|
-
recovery: UserRecovery.Retry,
|
|
279
|
-
tone: ErrorPresentationTone.Warning
|
|
280
|
-
},
|
|
281
|
-
[PopupErrorCode.Closed]: {
|
|
282
|
-
title: "Popup was closed",
|
|
283
|
-
description: "The popup window was closed before the operation completed. Start the flow again.",
|
|
284
|
-
recovery: UserRecovery.RestartFlow,
|
|
285
|
-
tone: ErrorPresentationTone.Warning
|
|
286
|
-
},
|
|
287
|
-
...options.codePresentations
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
//#endregion
|
|
292
132
|
//#region src/validation/validator.ts
|
|
293
133
|
function formatValidationFailure(failure) {
|
|
294
134
|
if (!failure) return null;
|
|
@@ -363,473 +203,6 @@ function validateTraitInput(options) {
|
|
|
363
203
|
options.onInvalid(result);
|
|
364
204
|
}
|
|
365
205
|
//#endregion
|
|
366
|
-
//#region src/protocol/json-rpc/types.ts
|
|
367
|
-
const JsonRpcIdSchema = type("string | number");
|
|
368
|
-
const JsonRpcErrorPayloadSchema = type({
|
|
369
|
-
code: "number",
|
|
370
|
-
message: "string",
|
|
371
|
-
data: "unknown?"
|
|
372
|
-
});
|
|
373
|
-
const JsonRpcRequestMessageSchema = type({
|
|
374
|
-
jsonrpc: "\"2.0\"",
|
|
375
|
-
id: JsonRpcIdSchema,
|
|
376
|
-
method: "string",
|
|
377
|
-
params: "unknown?"
|
|
378
|
-
});
|
|
379
|
-
const JsonRpcNotificationMessageSchema = type({
|
|
380
|
-
jsonrpc: "\"2.0\"",
|
|
381
|
-
method: "string",
|
|
382
|
-
params: "unknown?"
|
|
383
|
-
});
|
|
384
|
-
const JsonRpcSuccessResponseMessageSchema = type({
|
|
385
|
-
jsonrpc: "\"2.0\"",
|
|
386
|
-
id: JsonRpcIdSchema,
|
|
387
|
-
result: "unknown"
|
|
388
|
-
});
|
|
389
|
-
const JsonRpcErrorResponseMessageSchema = type({
|
|
390
|
-
jsonrpc: "\"2.0\"",
|
|
391
|
-
id: JsonRpcIdSchema,
|
|
392
|
-
error: JsonRpcErrorPayloadSchema
|
|
393
|
-
});
|
|
394
|
-
const JsonRpcMessageSchema = JsonRpcRequestMessageSchema.or(JsonRpcNotificationMessageSchema).or(JsonRpcSuccessResponseMessageSchema).or(JsonRpcErrorResponseMessageSchema);
|
|
395
|
-
//#endregion
|
|
396
|
-
//#region src/protocol/json-rpc/create.ts
|
|
397
|
-
function createJsonRpcClient(options) {
|
|
398
|
-
return new JsonRpcClient(options);
|
|
399
|
-
}
|
|
400
|
-
function createJsonRpcServer(options) {
|
|
401
|
-
return new JsonRpcServer(options);
|
|
402
|
-
}
|
|
403
|
-
function createJsonRpcServerAndClient(options) {
|
|
404
|
-
return new JsonRpcServerAndClient(options);
|
|
405
|
-
}
|
|
406
|
-
var JsonRpcClient = class {
|
|
407
|
-
options;
|
|
408
|
-
onNotification;
|
|
409
|
-
notificationSubject = new RxEventSubject();
|
|
410
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
411
|
-
disposed = false;
|
|
412
|
-
nextRequestId = 1;
|
|
413
|
-
constructor(options) {
|
|
414
|
-
this.options = options;
|
|
415
|
-
this.onNotification = this.notificationSubject;
|
|
416
|
-
}
|
|
417
|
-
request(method, params, requestOptions = {}) {
|
|
418
|
-
if (this.disposed) return Promise.reject(createJsonRpcDisposedError("client"));
|
|
419
|
-
const id = this.nextRequestId++;
|
|
420
|
-
const timeoutMs = requestOptions.timeoutMs ?? this.options.defaultRequestTimeoutMs;
|
|
421
|
-
return new Promise((resolve, reject) => {
|
|
422
|
-
const pendingRequest = {
|
|
423
|
-
method,
|
|
424
|
-
reject,
|
|
425
|
-
resolve
|
|
426
|
-
};
|
|
427
|
-
if (timeoutMs !== void 0) pendingRequest.timeoutHandle = this.options.time.setTimeout(() => {
|
|
428
|
-
this.pendingRequests.delete(id);
|
|
429
|
-
reject(/* @__PURE__ */ new Error(`JSON-RPC request timed out for ${method}.`));
|
|
430
|
-
}, timeoutMs);
|
|
431
|
-
this.pendingRequests.set(id, pendingRequest);
|
|
432
|
-
try {
|
|
433
|
-
this.options.send({
|
|
434
|
-
jsonrpc: "2.0",
|
|
435
|
-
id,
|
|
436
|
-
method,
|
|
437
|
-
params
|
|
438
|
-
});
|
|
439
|
-
} catch (error) {
|
|
440
|
-
this.clearPendingRequest(id);
|
|
441
|
-
reject(error);
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
notify(method, params) {
|
|
446
|
-
if (this.disposed) return;
|
|
447
|
-
this.options.send({
|
|
448
|
-
jsonrpc: "2.0",
|
|
449
|
-
method,
|
|
450
|
-
params
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
receive(message) {
|
|
454
|
-
if (this.disposed) return;
|
|
455
|
-
for (const parsedMessage of parseIncomingMessages(message)) {
|
|
456
|
-
if (isJsonRpcResponseMessage(parsedMessage)) {
|
|
457
|
-
this.resolvePendingRequest(parsedMessage);
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
if (isJsonRpcNotificationMessage(parsedMessage)) this.notificationSubject.next({
|
|
461
|
-
method: parsedMessage.method,
|
|
462
|
-
params: parsedMessage.params
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
rejectAllPendingRequests(reason) {
|
|
467
|
-
for (const [id, pendingRequest] of this.pendingRequests) {
|
|
468
|
-
this.clearPendingRequest(id);
|
|
469
|
-
pendingRequest.reject(reason);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
dispose() {
|
|
473
|
-
if (this.disposed) return;
|
|
474
|
-
this.disposed = true;
|
|
475
|
-
this.rejectAllPendingRequests(/* @__PURE__ */ new Error("JSON-RPC client disposed."));
|
|
476
|
-
this.notificationSubject.complete();
|
|
477
|
-
}
|
|
478
|
-
[SYMBOL_DISPOSE]() {
|
|
479
|
-
this.dispose();
|
|
480
|
-
}
|
|
481
|
-
resolvePendingRequest(message) {
|
|
482
|
-
const pendingRequest = this.pendingRequests.get(message.id);
|
|
483
|
-
if (!pendingRequest) return;
|
|
484
|
-
this.clearPendingRequest(message.id);
|
|
485
|
-
if ("error" in message) {
|
|
486
|
-
pendingRequest.reject(/* @__PURE__ */ new Error(`JSON-RPC request failed for ${pendingRequest.method}: ${message.error.message}`));
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
pendingRequest.resolve(message.result);
|
|
490
|
-
}
|
|
491
|
-
clearPendingRequest(id) {
|
|
492
|
-
const pendingRequest = this.pendingRequests.get(id);
|
|
493
|
-
if (!pendingRequest) return;
|
|
494
|
-
if (pendingRequest.timeoutHandle !== void 0) this.options.time.clearTimeout(pendingRequest.timeoutHandle);
|
|
495
|
-
this.pendingRequests.delete(id);
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
var JsonRpcServer = class {
|
|
499
|
-
options;
|
|
500
|
-
onRequest;
|
|
501
|
-
onNotification;
|
|
502
|
-
requestSubject = new RxEventSubject();
|
|
503
|
-
notificationSubject = new RxEventSubject();
|
|
504
|
-
disposed = false;
|
|
505
|
-
constructor(options) {
|
|
506
|
-
this.options = options;
|
|
507
|
-
this.onRequest = this.requestSubject;
|
|
508
|
-
this.onNotification = this.notificationSubject;
|
|
509
|
-
}
|
|
510
|
-
notify(method, params) {
|
|
511
|
-
if (this.disposed) return;
|
|
512
|
-
this.options.send({
|
|
513
|
-
jsonrpc: "2.0",
|
|
514
|
-
method,
|
|
515
|
-
params
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
receive(message) {
|
|
519
|
-
if (this.disposed) return;
|
|
520
|
-
for (const parsedMessage of parseIncomingMessages(message)) {
|
|
521
|
-
if (isJsonRpcRequestMessage(parsedMessage)) {
|
|
522
|
-
this.requestSubject.next({
|
|
523
|
-
id: parsedMessage.id,
|
|
524
|
-
method: parsedMessage.method,
|
|
525
|
-
params: parsedMessage.params
|
|
526
|
-
});
|
|
527
|
-
continue;
|
|
528
|
-
}
|
|
529
|
-
if (isJsonRpcNotificationMessage(parsedMessage)) this.notificationSubject.next({
|
|
530
|
-
method: parsedMessage.method,
|
|
531
|
-
params: parsedMessage.params
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
respondSuccess(id, result) {
|
|
536
|
-
if (this.disposed) return;
|
|
537
|
-
this.options.send({
|
|
538
|
-
jsonrpc: "2.0",
|
|
539
|
-
id,
|
|
540
|
-
result
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
respondError(id, error) {
|
|
544
|
-
if (this.disposed) return;
|
|
545
|
-
this.options.send({
|
|
546
|
-
jsonrpc: "2.0",
|
|
547
|
-
id,
|
|
548
|
-
error
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
dispose() {
|
|
552
|
-
if (this.disposed) return;
|
|
553
|
-
this.disposed = true;
|
|
554
|
-
this.requestSubject.complete();
|
|
555
|
-
this.notificationSubject.complete();
|
|
556
|
-
}
|
|
557
|
-
[SYMBOL_DISPOSE]() {
|
|
558
|
-
this.dispose();
|
|
559
|
-
}
|
|
560
|
-
};
|
|
561
|
-
var JsonRpcServerAndClient = class {
|
|
562
|
-
onNotification;
|
|
563
|
-
onRequest;
|
|
564
|
-
client;
|
|
565
|
-
server;
|
|
566
|
-
disposed = false;
|
|
567
|
-
constructor(options) {
|
|
568
|
-
this.client = new JsonRpcClient(options);
|
|
569
|
-
this.server = new JsonRpcServer(options);
|
|
570
|
-
this.onNotification = this.server.onNotification;
|
|
571
|
-
this.onRequest = this.server.onRequest;
|
|
572
|
-
}
|
|
573
|
-
request(method, params, options) {
|
|
574
|
-
return this.client.request(method, params, options);
|
|
575
|
-
}
|
|
576
|
-
notify(method, params) {
|
|
577
|
-
this.client.notify(method, params);
|
|
578
|
-
}
|
|
579
|
-
receive(message) {
|
|
580
|
-
for (const parsedMessage of parseIncomingMessages(message)) {
|
|
581
|
-
if (isJsonRpcResponseMessage(parsedMessage)) {
|
|
582
|
-
this.client.receive(parsedMessage);
|
|
583
|
-
continue;
|
|
584
|
-
}
|
|
585
|
-
this.server.receive(parsedMessage);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
rejectAllPendingRequests(reason) {
|
|
589
|
-
this.client.rejectAllPendingRequests(reason);
|
|
590
|
-
}
|
|
591
|
-
respondSuccess(id, result) {
|
|
592
|
-
this.server.respondSuccess(id, result);
|
|
593
|
-
}
|
|
594
|
-
respondError(id, error) {
|
|
595
|
-
this.server.respondError(id, error);
|
|
596
|
-
}
|
|
597
|
-
dispose() {
|
|
598
|
-
if (this.disposed) return;
|
|
599
|
-
this.disposed = true;
|
|
600
|
-
this.client.dispose();
|
|
601
|
-
this.server.dispose();
|
|
602
|
-
}
|
|
603
|
-
[SYMBOL_DISPOSE]() {
|
|
604
|
-
this.dispose();
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
function parseIncomingMessages(message) {
|
|
608
|
-
if (!Array.isArray(message)) return parseJsonRpcMessage(message);
|
|
609
|
-
const parsedMessages = [];
|
|
610
|
-
for (const entry of message) parsedMessages.push(...parseJsonRpcMessage(entry));
|
|
611
|
-
return parsedMessages;
|
|
612
|
-
}
|
|
613
|
-
function parseJsonRpcMessage(message) {
|
|
614
|
-
const result = validateWithSchemaSync(JsonRpcMessageSchema, message);
|
|
615
|
-
return result.success ? [result.value] : [];
|
|
616
|
-
}
|
|
617
|
-
function isJsonRpcRequestMessage(message) {
|
|
618
|
-
return "method" in message && "id" in message;
|
|
619
|
-
}
|
|
620
|
-
function isJsonRpcResponseMessage(message) {
|
|
621
|
-
return "id" in message && !("method" in message);
|
|
622
|
-
}
|
|
623
|
-
function isJsonRpcNotificationMessage(message) {
|
|
624
|
-
return "method" in message && !("id" in message);
|
|
625
|
-
}
|
|
626
|
-
function createJsonRpcDisposedError(role) {
|
|
627
|
-
return /* @__PURE__ */ new Error(`JSON-RPC ${role} disposed.`);
|
|
628
|
-
}
|
|
629
|
-
//#endregion
|
|
630
|
-
//#region src/popup/session.ts
|
|
631
|
-
const PopupSessionControlMethod = {
|
|
632
|
-
Ready: "securitydept.popup.session.ready",
|
|
633
|
-
Ping: "securitydept.popup.session.ping",
|
|
634
|
-
Pong: "securitydept.popup.session.pong"
|
|
635
|
-
};
|
|
636
|
-
const DEFAULT_READY_TIMEOUT_MS = 1e4;
|
|
637
|
-
const DEFAULT_HEARTBEAT_INTERVAL_MS = 5e3;
|
|
638
|
-
const DEFAULT_HEARTBEAT_TIMEOUT_MS = 15e3;
|
|
639
|
-
var PopupClientSession = class {
|
|
640
|
-
failure = createSignal(null);
|
|
641
|
-
isActive = createSignal(false);
|
|
642
|
-
init$ = new ReplaySubject();
|
|
643
|
-
destroyed = createSignal(false);
|
|
644
|
-
destroyed$ = from(this.destroyed).pipe(distinctUntilChanged(), filter(Boolean), shareReplay(1));
|
|
645
|
-
constructor(options) {
|
|
646
|
-
const timestampScheduler = createAsyncSchedulerWithTimestampProvider(options.time);
|
|
647
|
-
const ready$ = new Subject();
|
|
648
|
-
const pong$ = new Subject();
|
|
649
|
-
const closed$ = from(options.closedStream).pipe(filter(Boolean));
|
|
650
|
-
const ping$ = merge(ready$.pipe(filter(Boolean)), pong$.pipe(filter(Boolean))).pipe(delayWhen(() => timer(options.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS, timestampScheduler)));
|
|
651
|
-
from(this.init$).pipe(exhaustMap(() => from(options.jsonRpc.onNotification).pipe(filter(function isReadyNotification(event) {
|
|
652
|
-
return event.method === PopupSessionControlMethod.Ready;
|
|
653
|
-
}), take(1), timeout({
|
|
654
|
-
each: options.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS,
|
|
655
|
-
scheduler: timestampScheduler
|
|
656
|
-
}), map(() => true), catchError(() => of(false)))), takeUntil(this.destroyed$)).subscribe(ready$);
|
|
657
|
-
ping$.pipe(exhaustMap(() => from(options.jsonRpc.onNotification).pipe(filter(function isPongNotification(event) {
|
|
658
|
-
return event.method === PopupSessionControlMethod.Pong;
|
|
659
|
-
}), take(1), timeout({
|
|
660
|
-
first: options.heartbeatTimeoutMs ?? DEFAULT_HEARTBEAT_TIMEOUT_MS,
|
|
661
|
-
scheduler: timestampScheduler
|
|
662
|
-
}), map(() => true), catchError(() => of(false)))), takeUntil(this.destroyed$)).subscribe(pong$);
|
|
663
|
-
merge(closed$.pipe(map(() => new ClientError({
|
|
664
|
-
kind: ClientErrorKind.Authorization,
|
|
665
|
-
code: PopupErrorCode.Closed,
|
|
666
|
-
message: "Popup window was closed before completing the login flow.",
|
|
667
|
-
recovery: UserRecovery.RestartFlow,
|
|
668
|
-
source: "popup"
|
|
669
|
-
}))), ready$.pipe(map((success) => !success ? new ClientError({
|
|
670
|
-
kind: ClientErrorKind.Protocol,
|
|
671
|
-
message: "Did not receive ready notification from popup within the expected time.",
|
|
672
|
-
recovery: UserRecovery.RestartFlow,
|
|
673
|
-
source: "popup"
|
|
674
|
-
}) : null)), pong$.pipe(map((success) => !success ? new ClientError({
|
|
675
|
-
kind: ClientErrorKind.Protocol,
|
|
676
|
-
message: "Did not receive pong notification from popup within the expected time.",
|
|
677
|
-
recovery: UserRecovery.RestartFlow,
|
|
678
|
-
source: "popup"
|
|
679
|
-
}) : null))).pipe(takeUntil(this.destroyed$), shareReplay({
|
|
680
|
-
bufferSize: 1,
|
|
681
|
-
refCount: false
|
|
682
|
-
})).subscribe((error) => this.failure.set(error));
|
|
683
|
-
merge(closed$.pipe(map(() => false)), ready$.pipe(map(Boolean)), pong$.pipe(map(Boolean))).pipe(takeUntil(this.destroyed$)).subscribe((nextIsActive) => {
|
|
684
|
-
this.isActive.set(nextIsActive);
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
init() {
|
|
688
|
-
this.init$.next(true);
|
|
689
|
-
}
|
|
690
|
-
dispose() {
|
|
691
|
-
this.destroyed.set(true);
|
|
692
|
-
}
|
|
693
|
-
[SYMBOL_DISPOSE]() {
|
|
694
|
-
this.dispose();
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
var PopupServerSession = class {
|
|
698
|
-
init$ = new ReplaySubject();
|
|
699
|
-
destroyed$$ = new BehaviorSubject(false);
|
|
700
|
-
destroyed$ = this.destroyed$$.pipe(distinctUntilChanged(), filter(Boolean), shareReplay(1));
|
|
701
|
-
constructor(options) {
|
|
702
|
-
const ready$ = from(this.init$);
|
|
703
|
-
const pong$ = from(options.jsonRpc.onNotification).pipe(filter(function isPing(event) {
|
|
704
|
-
return event.method === PopupSessionControlMethod.Ping;
|
|
705
|
-
}));
|
|
706
|
-
merge(ready$.pipe(map(function createReadyNotify() {
|
|
707
|
-
return { method: PopupSessionControlMethod.Ready };
|
|
708
|
-
})), pong$.pipe(map(function createPongNotify() {
|
|
709
|
-
return { method: PopupSessionControlMethod.Pong };
|
|
710
|
-
}))).pipe(takeUntil(this.destroyed$)).subscribe((event) => {
|
|
711
|
-
options.jsonRpc.notify(event.method, event.params);
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
init() {
|
|
715
|
-
this.init$.next(true);
|
|
716
|
-
}
|
|
717
|
-
dispose() {
|
|
718
|
-
this.destroyed$$.next(true);
|
|
719
|
-
}
|
|
720
|
-
[SYMBOL_DISPOSE]() {
|
|
721
|
-
this.dispose();
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
//#endregion
|
|
725
|
-
//#region src/popup/handle.ts
|
|
726
|
-
/**
|
|
727
|
-
* popup opener
|
|
728
|
-
*/
|
|
729
|
-
var PopupClientWindowHandle = class {
|
|
730
|
-
messaging;
|
|
731
|
-
disposed = false;
|
|
732
|
-
jsonRpc;
|
|
733
|
-
session;
|
|
734
|
-
incomingSubscription;
|
|
735
|
-
closePopup;
|
|
736
|
-
constructor(options) {
|
|
737
|
-
this.messaging = options.messaging;
|
|
738
|
-
this.closePopup = options.close;
|
|
739
|
-
this.jsonRpc = createJsonRpcClient({
|
|
740
|
-
send: (message) => {
|
|
741
|
-
options.messaging.outgoing.next(message);
|
|
742
|
-
},
|
|
743
|
-
time: options.time
|
|
744
|
-
});
|
|
745
|
-
this.session = new PopupClientSession({
|
|
746
|
-
jsonRpc: this.jsonRpc,
|
|
747
|
-
time: options.time,
|
|
748
|
-
closedStream: options.closedStream
|
|
749
|
-
});
|
|
750
|
-
this.incomingSubscription = options.messaging.incoming.subscribe({ next: (message) => {
|
|
751
|
-
this.jsonRpc.receive(message);
|
|
752
|
-
} });
|
|
753
|
-
this.session.init();
|
|
754
|
-
}
|
|
755
|
-
get onNotification() {
|
|
756
|
-
return this.jsonRpc.onNotification;
|
|
757
|
-
}
|
|
758
|
-
get failure() {
|
|
759
|
-
return this.session.failure;
|
|
760
|
-
}
|
|
761
|
-
get isActive() {
|
|
762
|
-
return this.session.isActive;
|
|
763
|
-
}
|
|
764
|
-
async notify(method, params) {
|
|
765
|
-
this.jsonRpc.notify(method, params);
|
|
766
|
-
}
|
|
767
|
-
request(method, params, options) {
|
|
768
|
-
return this.jsonRpc.request(method, params, options);
|
|
769
|
-
}
|
|
770
|
-
close() {
|
|
771
|
-
this.closePopup();
|
|
772
|
-
}
|
|
773
|
-
dispose() {
|
|
774
|
-
if (this.disposed) return;
|
|
775
|
-
this.disposed = true;
|
|
776
|
-
this.session.dispose();
|
|
777
|
-
this.jsonRpc.dispose();
|
|
778
|
-
this.incomingSubscription.unsubscribe();
|
|
779
|
-
this.messaging.outgoing.complete();
|
|
780
|
-
}
|
|
781
|
-
[SYMBOL_DISPOSE]() {
|
|
782
|
-
this.dispose();
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
/**
|
|
786
|
-
* popup target
|
|
787
|
-
*/
|
|
788
|
-
var PopupServerWindowHandle = class {
|
|
789
|
-
messaging;
|
|
790
|
-
disposed = false;
|
|
791
|
-
jsonRpc;
|
|
792
|
-
session;
|
|
793
|
-
incomingSubscription;
|
|
794
|
-
closePopup;
|
|
795
|
-
constructor(options) {
|
|
796
|
-
this.messaging = options.messaging;
|
|
797
|
-
this.closePopup = options.close;
|
|
798
|
-
this.jsonRpc = createJsonRpcServer({ send: (message) => {
|
|
799
|
-
options.messaging.outgoing.next(message);
|
|
800
|
-
} });
|
|
801
|
-
this.session = new PopupServerSession({ jsonRpc: this.jsonRpc });
|
|
802
|
-
this.incomingSubscription = options.messaging.incoming.subscribe({ next: (message) => {
|
|
803
|
-
this.jsonRpc.receive(message);
|
|
804
|
-
} });
|
|
805
|
-
this.session.init();
|
|
806
|
-
}
|
|
807
|
-
get onNotification() {
|
|
808
|
-
return this.jsonRpc.onNotification;
|
|
809
|
-
}
|
|
810
|
-
get onRequest() {
|
|
811
|
-
return this.jsonRpc.onRequest;
|
|
812
|
-
}
|
|
813
|
-
notify(method, params) {
|
|
814
|
-
this.jsonRpc.notify(method, params);
|
|
815
|
-
return Promise.resolve();
|
|
816
|
-
}
|
|
817
|
-
close() {
|
|
818
|
-
this.closePopup();
|
|
819
|
-
}
|
|
820
|
-
dispose() {
|
|
821
|
-
if (this.disposed) return;
|
|
822
|
-
this.disposed = true;
|
|
823
|
-
this.session.dispose();
|
|
824
|
-
this.jsonRpc.dispose();
|
|
825
|
-
this.incomingSubscription.unsubscribe();
|
|
826
|
-
this.messaging.outgoing.complete();
|
|
827
|
-
}
|
|
828
|
-
[SYMBOL_DISPOSE]() {
|
|
829
|
-
this.dispose();
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
//#endregion
|
|
833
206
|
//#region src/popup/index.ts
|
|
834
207
|
const PopupAttachFailureReason = {
|
|
835
208
|
MissingOpener: "missing_opener",
|
|
@@ -1129,11 +502,14 @@ function normalizeAbortError(token, error) {
|
|
|
1129
502
|
function isAbortError(error) {
|
|
1130
503
|
return typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
|
|
1131
504
|
}
|
|
1132
|
-
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region src/std/time.ts
|
|
507
|
+
const TimeTraitStdHostSchema = type({
|
|
1133
508
|
Date: type({ now: "Function" }),
|
|
1134
509
|
setTimeout: "Function",
|
|
1135
510
|
clearTimeout: "Function"
|
|
1136
|
-
})
|
|
511
|
+
});
|
|
512
|
+
const TimeForStdCreateOptionsSchema = type({ host: TimeTraitStdHostSchema });
|
|
1137
513
|
function createTimeForStd(options = {}) {
|
|
1138
514
|
const { validators, ...createOptions } = options;
|
|
1139
515
|
const resolvedCreateOptions = { host: createOptions.host ?? globalThis };
|
|
@@ -1321,8 +697,11 @@ function createInMemoryRecordStore() {
|
|
|
1321
697
|
};
|
|
1322
698
|
}
|
|
1323
699
|
//#endregion
|
|
700
|
+
//#region src/tracing/subscriber/types.ts
|
|
701
|
+
const TracingSubscriberTraitSchema = type({ record: "Function" });
|
|
702
|
+
//#endregion
|
|
1324
703
|
//#region src/tracing/create.ts
|
|
1325
|
-
const TracingCreateOptionsSchema = type({ subscribers:
|
|
704
|
+
const TracingCreateOptionsSchema = type({ subscribers: TracingSubscriberTraitSchema.array() });
|
|
1326
705
|
function createTracing(options) {
|
|
1327
706
|
const { validators, ...resolvedOptions } = options ?? {};
|
|
1328
707
|
const resolvedCreateOptions = { subscribers: resolvedOptions.subscribers ?? [] };
|
|
@@ -1568,6 +947,6 @@ function createFoundationEnvironmentUnit() {
|
|
|
1568
947
|
};
|
|
1569
948
|
}
|
|
1570
949
|
//#endregion
|
|
1571
|
-
export {
|
|
950
|
+
export { appendOrReplaceCompatFragment as A, validateWithSchemaSync as B, IDLE_CALLBACK_TRAIT_TOKEN as C, RouterNavigationMode as D, RouterNavigationIntent as E, PopupAttachFailureReason as F, PARENT_INJECTOR_TOKEN as G, EventSourceKind as H, formatValidationFailure as I, SecurityDeptOptional as J, SecuritydeptInjector as K, throwValidationClientError as L, parseCompatFragment as M, takeCompatFragment as N, takeCompatFragmentFromRouter as O, POPUP_TRAIT_TOKEN as P, notMissingProvider as Q, validateTraitInput as R, SPAN_TRAIT_TOKEN as S, ROUTER_TRAIT_TOKEN as T, isEventStreamTrait as U, PAGE_LIFECYCLE_TRAIT_TOKEN as V, INJECTOR_TOKEN as W, createProviderIfTokenMissing as X, SecuritydeptInjectionToken as Y, getSecuritydeptProviderToken as Z, abortSignalToCancellationToken as _, TracingLevel as a, abortSignalToEventStream as b, PERSISTENT_STORAGE_TRAIT_TOKEN as c, StorageChangeEventOrigin as d, FetchTransportRedirectKind as f, createTimeForStd as g, TransportErrorCode as h, TRACING_TRAIT_TOKEN as i, isCompatFragmentBlock as j, SECURITYDEPT_COMPAT_FRAGMENT_VERSION as k, REALM_STORAGE_TRAIT_TOKEN as l, TRANSPORT_TRAIT_TOKEN as m, ENVIRONMENT_TOKEN as n, createTracing as o, createBaseTransportForStdFetch as p, toRuntimeInjector as q, OperationTraceEventType as r, createInMemoryRecordStore as s, createFoundationEnvironment as t, SESSION_STORAGE_TRAIT_TOKEN as u, cancellationTokenToAbortSignal as v, TIME_TRAIT_TOKEN as w, createRootSpan as x, normalizeAbortError as y, validateWithSchema as z };
|
|
1572
951
|
|
|
1573
|
-
//# sourceMappingURL=create-
|
|
952
|
+
//# sourceMappingURL=create-99Ksgl_O.mjs.map
|