@kosdev-code/kos-ui-sdk 0.1.0-next.1057 → 0.1.0-next.1063
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/core/core/transport/mock/future-simulator.d.ts +5 -1
- package/core/core/transport/mock/future-simulator.d.ts.map +1 -1
- package/core/core/transport/mock/mock-interceptor.d.ts.map +1 -1
- package/core/core/transport/mock/mock-registry.d.ts +14 -5
- package/core/core/transport/mock/mock-registry.d.ts.map +1 -1
- package/core/core/transport/mock/mock-types.d.ts +64 -1
- package/core/core/transport/mock/mock-types.d.ts.map +1 -1
- package/index.cjs +3 -3
- package/index.cjs.map +1 -1
- package/index.js +4 -4
- package/index.js.map +1 -1
- package/package.json +7 -3
- package/{software-info-registration-C8Yg5Z-Y.cjs → software-info-registration-DMOIY4c3.cjs} +144 -19
- package/software-info-registration-DMOIY4c3.cjs.map +1 -0
- package/{software-info-registration-B99UrnV0.js → software-info-registration-hfu4S9Qm.js} +144 -19
- package/software-info-registration-hfu4S9Qm.js.map +1 -0
- package/testing.cjs +1 -1
- package/testing.js +1 -1
- package/software-info-registration-B99UrnV0.js.map +0 -1
- package/software-info-registration-C8Yg5Z-Y.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosdev-code/kos-ui-sdk",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.1063",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/The-Coca-Cola-Company/kos-ui-sdk.git"
|
|
7
|
+
},
|
|
4
8
|
"type": "module",
|
|
5
9
|
"main": "./index.cjs",
|
|
6
10
|
"module": "./index.js",
|
|
@@ -50,7 +54,7 @@
|
|
|
50
54
|
"react-router-dom": "^6.11.2"
|
|
51
55
|
},
|
|
52
56
|
"dependencies": {
|
|
53
|
-
"@kosdev-code/kos-api-levels": "0.1.0-next.
|
|
57
|
+
"@kosdev-code/kos-api-levels": "0.1.0-next.1063",
|
|
54
58
|
"mobx": "^6.9.0",
|
|
55
59
|
"mobx-react-lite": "^3.4.3",
|
|
56
60
|
"date-fns": "^2.30.0",
|
|
@@ -59,7 +63,7 @@
|
|
|
59
63
|
},
|
|
60
64
|
"kos": {
|
|
61
65
|
"build": {
|
|
62
|
-
"gitHash": "
|
|
66
|
+
"gitHash": "b87f3d2a7ca810f829331ea34b316d950795afa2"
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
}
|
|
@@ -7462,6 +7462,7 @@ class KosMockFutureHandle {
|
|
|
7462
7462
|
elapsedMs = 0;
|
|
7463
7463
|
endStateValue;
|
|
7464
7464
|
reasonValue;
|
|
7465
|
+
endFields;
|
|
7465
7466
|
timer;
|
|
7466
7467
|
started = false;
|
|
7467
7468
|
durationMs;
|
|
@@ -7477,7 +7478,8 @@ class KosMockFutureHandle {
|
|
|
7477
7478
|
remainingTimeMs: this.remainingTimeMs,
|
|
7478
7479
|
endState: this.endStateValue,
|
|
7479
7480
|
reason: this.reasonValue,
|
|
7480
|
-
clientData: this.clientData
|
|
7481
|
+
clientData: this.clientData,
|
|
7482
|
+
...this.endFields
|
|
7481
7483
|
};
|
|
7482
7484
|
}
|
|
7483
7485
|
start() {
|
|
@@ -7508,14 +7510,15 @@ class KosMockFutureHandle {
|
|
|
7508
7510
|
}
|
|
7509
7511
|
this.emitFrame(encodeFutureFrame(this.snapshot()));
|
|
7510
7512
|
}
|
|
7511
|
-
complete(endState = "SUCCESS",
|
|
7513
|
+
complete(endState = "SUCCESS", end) {
|
|
7512
7514
|
if (this.done) {
|
|
7513
7515
|
return;
|
|
7514
7516
|
}
|
|
7515
7517
|
this.stopTimer();
|
|
7516
7518
|
this.done = true;
|
|
7517
7519
|
this.endStateValue = endState;
|
|
7518
|
-
this.
|
|
7520
|
+
this.endFields = typeof end === "string" ? { reason: end } : end;
|
|
7521
|
+
this.reasonValue = this.endFields?.reason;
|
|
7519
7522
|
this.remainingTimeMs = 0;
|
|
7520
7523
|
if (endState === "SUCCESS") {
|
|
7521
7524
|
this.progress = 1;
|
|
@@ -7573,6 +7576,39 @@ class KosMockFutureSimulator {
|
|
|
7573
7576
|
}
|
|
7574
7577
|
return void 0;
|
|
7575
7578
|
}
|
|
7579
|
+
endWith(method, pattern, options) {
|
|
7580
|
+
const ended = /* @__PURE__ */ new Set();
|
|
7581
|
+
return this.deps.transformFuture(
|
|
7582
|
+
method,
|
|
7583
|
+
pattern,
|
|
7584
|
+
(future) => {
|
|
7585
|
+
if (ended.has(future.id)) {
|
|
7586
|
+
if (future.endState) {
|
|
7587
|
+
ended.delete(future.id);
|
|
7588
|
+
}
|
|
7589
|
+
return null;
|
|
7590
|
+
}
|
|
7591
|
+
if (future.endState === "CANCEL") {
|
|
7592
|
+
return void 0;
|
|
7593
|
+
}
|
|
7594
|
+
const reached = !!future.endState || options.atProgress !== void 0 && (future.progress ?? 0) >= options.atProgress;
|
|
7595
|
+
if (!reached) {
|
|
7596
|
+
return void 0;
|
|
7597
|
+
}
|
|
7598
|
+
if (!future.endState) {
|
|
7599
|
+
const simulated = this.futures.get(future.id);
|
|
7600
|
+
if (simulated) {
|
|
7601
|
+
simulated.dispose();
|
|
7602
|
+
} else {
|
|
7603
|
+
ended.add(future.id);
|
|
7604
|
+
}
|
|
7605
|
+
}
|
|
7606
|
+
const { atProgress: _atProgress, ...end } = options;
|
|
7607
|
+
return { ...future, reason: void 0, remainingTimeMs: 0, ...end };
|
|
7608
|
+
},
|
|
7609
|
+
{ description: `futures end with ${options.endState}` }
|
|
7610
|
+
);
|
|
7611
|
+
}
|
|
7576
7612
|
get active() {
|
|
7577
7613
|
return [...this.futures.values()].filter((handle) => !handle.done);
|
|
7578
7614
|
}
|
|
@@ -8433,7 +8469,8 @@ class KosMockRegistry {
|
|
|
8433
8469
|
state = /* @__PURE__ */ new Map();
|
|
8434
8470
|
futures = new KosMockFutureSimulator({
|
|
8435
8471
|
emitFrame: (frame) => this.publishFrame(frame),
|
|
8436
|
-
ensureCancelRoutes: () => this.ensureFutureCancelRoutes()
|
|
8472
|
+
ensureCancelRoutes: () => this.ensureFutureCancelRoutes(),
|
|
8473
|
+
transformFuture: (method, pattern, transform, options) => this.transformFuture(method, pattern, transform, options)
|
|
8437
8474
|
});
|
|
8438
8475
|
recorder = new KosMockRecorder();
|
|
8439
8476
|
config = createConfigFacade(this);
|
|
@@ -8470,13 +8507,85 @@ class KosMockRegistry {
|
|
|
8470
8507
|
disable: remove
|
|
8471
8508
|
};
|
|
8472
8509
|
}
|
|
8510
|
+
futureTransformers = [];
|
|
8511
|
+
// Requests by tracker: the only link from a future frame to its endpoint.
|
|
8512
|
+
trackedRequests = /* @__PURE__ */ new Map();
|
|
8513
|
+
transformFuture(method, pattern, transform, options = {}) {
|
|
8514
|
+
const registered = {
|
|
8515
|
+
id: options.id ?? uuid(),
|
|
8516
|
+
method,
|
|
8517
|
+
pattern,
|
|
8518
|
+
compiled: compileRoutePattern(pattern),
|
|
8519
|
+
transform,
|
|
8520
|
+
description: options.description
|
|
8521
|
+
};
|
|
8522
|
+
this.futureTransformers.push(registered);
|
|
8523
|
+
const remove = () => {
|
|
8524
|
+
this.futureTransformers = this.futureTransformers.filter(
|
|
8525
|
+
(candidate) => candidate.id !== registered.id
|
|
8526
|
+
);
|
|
8527
|
+
};
|
|
8528
|
+
return {
|
|
8529
|
+
id: registered.id,
|
|
8530
|
+
remove,
|
|
8531
|
+
enable: () => void 0,
|
|
8532
|
+
disable: remove
|
|
8533
|
+
};
|
|
8534
|
+
}
|
|
8535
|
+
/** Runs a `kos.future` frame through the future transformers. */
|
|
8536
|
+
transformFutureFrame(frame, headers, body) {
|
|
8537
|
+
let future;
|
|
8538
|
+
try {
|
|
8539
|
+
future = JSON.parse(body);
|
|
8540
|
+
} catch {
|
|
8541
|
+
return frame;
|
|
8542
|
+
}
|
|
8543
|
+
const tracker = future?.tracker;
|
|
8544
|
+
const request = tracker ? this.trackedRequests.get(tracker) : void 0;
|
|
8545
|
+
if (!tracker || !request) {
|
|
8546
|
+
return frame;
|
|
8547
|
+
}
|
|
8548
|
+
if (future.endState) {
|
|
8549
|
+
this.trackedRequests.delete(tracker);
|
|
8550
|
+
}
|
|
8551
|
+
const matching = this.futureTransformers.filter(
|
|
8552
|
+
(transformer) => methodMatches(transformer.method, request.method) && matchRoutePattern(transformer.compiled, request.path) !== void 0
|
|
8553
|
+
);
|
|
8554
|
+
let current = future;
|
|
8555
|
+
let changed = false;
|
|
8556
|
+
for (const transformer of matching) {
|
|
8557
|
+
try {
|
|
8558
|
+
const result = transformer.transform(current, { request });
|
|
8559
|
+
if (result === null) {
|
|
8560
|
+
return void 0;
|
|
8561
|
+
}
|
|
8562
|
+
if (result !== void 0) {
|
|
8563
|
+
current = result;
|
|
8564
|
+
changed = true;
|
|
8565
|
+
}
|
|
8566
|
+
} catch (error) {
|
|
8567
|
+
log$L.error(
|
|
8568
|
+
`KosMock future transformer for ${transformer.method} ${transformer.pattern} threw`,
|
|
8569
|
+
error?.message
|
|
8570
|
+
);
|
|
8571
|
+
}
|
|
8572
|
+
}
|
|
8573
|
+
if (!changed) {
|
|
8574
|
+
return frame;
|
|
8575
|
+
}
|
|
8576
|
+
return encodeRawFrame(
|
|
8577
|
+
{ ...headers, [KOS_MOCK_TRANSFORMED_HEADER]: "true" },
|
|
8578
|
+
JSON.stringify(current)
|
|
8579
|
+
);
|
|
8580
|
+
}
|
|
8473
8581
|
/**
|
|
8474
|
-
* Interceptor seam: patches a matching inbound response
|
|
8475
|
-
* transformer chain before it reaches the app. Returns the
|
|
8476
|
-
* modified) frame
|
|
8582
|
+
* Interceptor seam: patches a matching inbound response or future frame
|
|
8583
|
+
* through its transformer chain before it reaches the app. Returns the
|
|
8584
|
+
* (possibly modified) frame, or undefined when a future transformer dropped
|
|
8585
|
+
* it. Internal.
|
|
8477
8586
|
*/
|
|
8478
8587
|
transformInboundFrame(frame) {
|
|
8479
|
-
if (this.transformers.length === 0) {
|
|
8588
|
+
if (this.transformers.length === 0 && this.futureTransformers.length === 0) {
|
|
8480
8589
|
return frame;
|
|
8481
8590
|
}
|
|
8482
8591
|
let headers;
|
|
@@ -8488,7 +8597,7 @@ class KosMockRegistry {
|
|
|
8488
8597
|
}
|
|
8489
8598
|
const responseId = headers["response-id"];
|
|
8490
8599
|
if (!responseId) {
|
|
8491
|
-
return frame;
|
|
8600
|
+
return headers["type"] === KOS_FUTURE_TYPE && this.futureTransformers.length > 0 ? this.transformFutureFrame(frame, headers, body) : frame;
|
|
8492
8601
|
}
|
|
8493
8602
|
const request = this.pendingRequests.get(responseId);
|
|
8494
8603
|
this.pendingRequests.delete(responseId);
|
|
@@ -8569,7 +8678,7 @@ class KosMockRegistry {
|
|
|
8569
8678
|
const hasRequestObservers = [...this.observers].some(
|
|
8570
8679
|
(observer) => observer.onRequest
|
|
8571
8680
|
);
|
|
8572
|
-
if (!hasRequestObservers && this.transformers.length === 0) {
|
|
8681
|
+
if (!hasRequestObservers && this.transformers.length === 0 && this.futureTransformers.length === 0) {
|
|
8573
8682
|
return;
|
|
8574
8683
|
}
|
|
8575
8684
|
const frame = decodeRequestFrame(data);
|
|
@@ -8586,6 +8695,15 @@ class KosMockRegistry {
|
|
|
8586
8695
|
tracker: frame.tracker,
|
|
8587
8696
|
rawBody: frame.rawBody
|
|
8588
8697
|
};
|
|
8698
|
+
if (this.futureTransformers.length > 0 && frame.tracker) {
|
|
8699
|
+
if (this.trackedRequests.size >= PENDING_REQUEST_CAP) {
|
|
8700
|
+
const oldest = this.trackedRequests.keys().next().value;
|
|
8701
|
+
if (oldest !== void 0) {
|
|
8702
|
+
this.trackedRequests.delete(oldest);
|
|
8703
|
+
}
|
|
8704
|
+
}
|
|
8705
|
+
this.trackedRequests.set(frame.tracker, observation);
|
|
8706
|
+
}
|
|
8589
8707
|
if (this.transformers.length > 0) {
|
|
8590
8708
|
if (this.pendingRequests.size >= PENDING_REQUEST_CAP) {
|
|
8591
8709
|
const oldest = this.pendingRequests.keys().next().value;
|
|
@@ -8831,14 +8949,16 @@ class KosMockRegistry {
|
|
|
8831
8949
|
enabled: this.enabled,
|
|
8832
8950
|
standalone: this.standalone,
|
|
8833
8951
|
routes: this.list(),
|
|
8834
|
-
transformers: this.transformers.map(
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8952
|
+
transformers: [...this.transformers, ...this.futureTransformers].map(
|
|
8953
|
+
(transformer) => {
|
|
8954
|
+
return {
|
|
8955
|
+
id: transformer.id,
|
|
8956
|
+
method: transformer.method,
|
|
8957
|
+
pattern: transformer.pattern,
|
|
8958
|
+
description: transformer.description
|
|
8959
|
+
};
|
|
8960
|
+
}
|
|
8961
|
+
),
|
|
8842
8962
|
setups: this.setups.active().map((setup) => {
|
|
8843
8963
|
return { name: setup.name, url: setup.url };
|
|
8844
8964
|
}),
|
|
@@ -8854,6 +8974,8 @@ class KosMockRegistry {
|
|
|
8854
8974
|
[...this.playbacks].forEach((playback) => playback.stop());
|
|
8855
8975
|
this.routes = [];
|
|
8856
8976
|
this.transformers = [];
|
|
8977
|
+
this.futureTransformers = [];
|
|
8978
|
+
this.trackedRequests.clear();
|
|
8857
8979
|
this.pendingRequests.clear();
|
|
8858
8980
|
this.cancelRoutesRegistered = false;
|
|
8859
8981
|
this.emitters.forEach((timer) => clearInterval(timer));
|
|
@@ -9168,6 +9290,9 @@ class MockInterceptorTransport {
|
|
|
9168
9290
|
*/
|
|
9169
9291
|
deliver(frame) {
|
|
9170
9292
|
const transformed = this.registry.transformInboundFrame(frame);
|
|
9293
|
+
if (transformed === void 0) {
|
|
9294
|
+
return;
|
|
9295
|
+
}
|
|
9171
9296
|
this.messageHandler?.({ data: transformed });
|
|
9172
9297
|
this.registry.noteInboundFrame(transformed);
|
|
9173
9298
|
}
|
|
@@ -25412,4 +25537,4 @@ exports.waitForRequest = waitForRequest;
|
|
|
25412
25537
|
exports.whenReady = whenReady;
|
|
25413
25538
|
exports.withCancellation = withCancellation;
|
|
25414
25539
|
exports.wrapWithFutureLifecycle = wrapWithFutureLifecycle;
|
|
25415
|
-
//# sourceMappingURL=software-info-registration-
|
|
25540
|
+
//# sourceMappingURL=software-info-registration-DMOIY4c3.cjs.map
|