@orchestrator-ui/orchestrator-ui-components 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +8 -8
- package/CHANGELOG.md +6 -0
- package/dist/index.js +49 -27
- package/package.json +1 -1
- package/src/rtk/endpoints/streamMessages.ts +67 -37
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @orchestrator-ui/orchestrator-ui-components@1.
|
|
2
|
+
> @orchestrator-ui/orchestrator-ui-components@1.12.0 build
|
|
3
3
|
> tsup src/index.ts --format esm --dts --tsconfig tsconfig.build.json
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[32mESM[39m [1mdist/index.js [22m[32m2.12 MB[39m
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mDTS[39m ⚡️ Build success in
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 666ms
|
|
13
|
+
[32mDTS[39m ⚡️ Build success in 12853ms
|
|
14
14
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m161.35 KB[39m
|
package/.turbo/turbo-lint.log
CHANGED
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
> @orchestrator-ui/orchestrator-ui-components@1.
|
|
2
|
+
> @orchestrator-ui/orchestrator-ui-components@1.12.0 test
|
|
3
3
|
> jest
|
|
4
4
|
|
|
5
|
-
PASS Orchestrator UI Components Tests src/utils/date.spec.ts
|
|
6
|
-
PASS Orchestrator UI Components Tests src/components/WfoForms/formFields/utils.spec.ts
|
|
7
5
|
PASS Orchestrator UI Components Tests src/components/WfoSubscription/utils/utils.spec.ts
|
|
6
|
+
PASS Orchestrator UI Components Tests src/components/WfoForms/formFields/utils.spec.ts
|
|
7
|
+
PASS Orchestrator UI Components Tests src/utils/date.spec.ts
|
|
8
|
+
PASS Orchestrator UI Components Tests src/utils/getProductNamesFromProcess.spec.ts
|
|
8
9
|
PASS Orchestrator UI Components Tests src/pages/processes/timelineUtils.spec.ts
|
|
9
10
|
PASS Orchestrator UI Components Tests src/utils/string.spec.ts
|
|
10
|
-
PASS Orchestrator UI Components Tests src/utils/getProductNamesFromProcess.spec.ts
|
|
11
11
|
PASS Orchestrator UI Components Tests src/components/WfoTable/WfoDataGridTable/WfodataGridColumns.spec.ts
|
|
12
12
|
PASS Orchestrator UI Components Tests src/components/WfoTree/treeUtils.spec.ts
|
|
13
13
|
PASS Orchestrator UI Components Tests src/components/WfoTable/WfoTableWithFilter/updateQueryString.spec.ts
|
|
14
14
|
PASS Orchestrator UI Components Tests src/components/WfoTable/utils/tableConfigPersistence.spec.ts
|
|
15
|
-
PASS Orchestrator UI Components Tests src/components/WfoTable/utils/tableUtils.spec.ts
|
|
16
15
|
PASS Orchestrator UI Components Tests src/components/WfoTable/utils/mapSortableAndFilterableValuesToTableColumnConfig.spec.ts
|
|
16
|
+
PASS Orchestrator UI Components Tests src/components/WfoTable/utils/tableUtils.spec.ts
|
|
17
17
|
PASS Orchestrator UI Components Tests src/utils/resultFlattener.spec.ts
|
|
18
18
|
PASS Orchestrator UI Components Tests src/messages/getTranslationMessages.spec.ts
|
|
19
19
|
PASS Orchestrator UI Components Tests src/utils/getToastMessage.spec.ts
|
|
@@ -23,14 +23,14 @@ PASS Orchestrator UI Components Tests src/components/WfoWorkflowSteps/stepListUt
|
|
|
23
23
|
PASS Orchestrator UI Components Tests src/utils/getTokenName.spec.ts
|
|
24
24
|
PASS Orchestrator UI Components Tests src/utils/environmentVariables.spec.ts
|
|
25
25
|
PASS Orchestrator UI Components Tests src/utils/onlyUnique.spec.ts
|
|
26
|
-
PASS Orchestrator UI Components Tests src/utils/uuid.spec.ts
|
|
27
26
|
PASS Orchestrator UI Components Tests src/utils/getTypedFieldFromObject.spec.ts
|
|
28
|
-
PASS Orchestrator UI Components Tests src/utils/
|
|
27
|
+
PASS Orchestrator UI Components Tests src/utils/uuid.spec.ts
|
|
29
28
|
PASS Orchestrator UI Components Tests src/utils/getQueryVariablesForExport.spec.ts
|
|
29
|
+
PASS Orchestrator UI Components Tests src/utils/toOptionalArrayEntry.spec.ts
|
|
30
30
|
PASS Orchestrator UI Components Tests src/components/WfoPageTemplate/WfoPageHeader/utils/toHexColorWithOpacity.spec.ts
|
|
31
31
|
|
|
32
32
|
Test Suites: 26 passed, 26 total
|
|
33
33
|
Tests: 157 passed, 157 total
|
|
34
34
|
Snapshots: 0 total
|
|
35
|
-
Time: 3.
|
|
35
|
+
Time: 3.654 s
|
|
36
36
|
Ran all test suites.
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -41359,6 +41359,7 @@ var {
|
|
|
41359
41359
|
|
|
41360
41360
|
// src/rtk/endpoints/streamMessages.ts
|
|
41361
41361
|
var import_lodash = __toESM(require_lodash(), 1);
|
|
41362
|
+
import { getSession as getSession2 } from "next-auth/react";
|
|
41362
41363
|
|
|
41363
41364
|
// src/utils/getToastMessage.ts
|
|
41364
41365
|
var getToastMessage = (type, text, title) => {
|
|
@@ -41387,11 +41388,13 @@ var getToastMessage = (type, text, title) => {
|
|
|
41387
41388
|
};
|
|
41388
41389
|
|
|
41389
41390
|
// src/rtk/endpoints/streamMessages.ts
|
|
41390
|
-
var getWebSocket = (url) => {
|
|
41391
|
-
|
|
41392
|
-
|
|
41393
|
-
|
|
41394
|
-
|
|
41391
|
+
var getWebSocket = (url) => __async(void 0, null, function* () {
|
|
41392
|
+
const session = yield getSession2();
|
|
41393
|
+
const token = (session == null ? void 0 : session.accessToken) ? [session == null ? void 0 : session.accessToken] : [];
|
|
41394
|
+
return new WebSocket(url, token);
|
|
41395
|
+
});
|
|
41396
|
+
var PING_INTERVAL_MS = 45e3;
|
|
41397
|
+
var DEBOUNCE_CLOSE_INTERVAL_MS = 6e4;
|
|
41395
41398
|
var streamMessagesApi = orchestratorApi.injectEndpoints({
|
|
41396
41399
|
endpoints: (build) => ({
|
|
41397
41400
|
streamMessages: build.query({
|
|
@@ -41416,40 +41419,59 @@ var streamMessagesApi = orchestratorApi.injectEndpoints({
|
|
|
41416
41419
|
clearInterval(pingInterval);
|
|
41417
41420
|
updateCachedData(() => false);
|
|
41418
41421
|
};
|
|
41419
|
-
|
|
41420
|
-
|
|
41421
|
-
|
|
41422
|
-
|
|
41423
|
-
|
|
41424
|
-
|
|
41422
|
+
const invalidateTag = (tag) => {
|
|
41423
|
+
const tagToInvalidate = tag;
|
|
41424
|
+
if (validCacheTags.includes(tagToInvalidate)) {
|
|
41425
|
+
const cacheInvalidationAction = orchestratorApi.util.invalidateTags([
|
|
41426
|
+
tagToInvalidate
|
|
41427
|
+
]);
|
|
41428
|
+
dispatch(cacheInvalidationAction);
|
|
41429
|
+
} else {
|
|
41430
|
+
console.error(
|
|
41431
|
+
`Trying to invalidate a cache entry with an unknown tag: ${tagToInvalidate}`
|
|
41432
|
+
);
|
|
41433
|
+
}
|
|
41434
|
+
};
|
|
41435
|
+
const handleInvalidateCacheMessage = (message) => {
|
|
41436
|
+
if (message.name === "invalidateCache" /* invalidateCache */) {
|
|
41437
|
+
const messageValue = message.value;
|
|
41438
|
+
if (typeof messageValue === "string") {
|
|
41439
|
+
invalidateTag(messageValue);
|
|
41440
|
+
} else if (Array.isArray(messageValue)) {
|
|
41441
|
+
messageValue.forEach((tag) => invalidateTag(tag));
|
|
41442
|
+
} else {
|
|
41443
|
+
console.error(
|
|
41444
|
+
"invalid message value type",
|
|
41445
|
+
messageValue
|
|
41446
|
+
);
|
|
41447
|
+
}
|
|
41448
|
+
}
|
|
41425
41449
|
};
|
|
41426
41450
|
const pingInterval = setInterval(() => {
|
|
41427
|
-
webSocket.send("
|
|
41451
|
+
webSocket.send("__ping__");
|
|
41428
41452
|
}, PING_INTERVAL_MS);
|
|
41429
41453
|
const debounceCloseWebSocket = (0, import_lodash.debounce)(() => {
|
|
41430
41454
|
webSocket.close();
|
|
41431
41455
|
}, DEBOUNCE_CLOSE_INTERVAL_MS);
|
|
41432
41456
|
debounceCloseWebSocket();
|
|
41457
|
+
yield cacheDataLoaded;
|
|
41458
|
+
const state = getState();
|
|
41459
|
+
const { orchestratorWebsocketUrl } = state.orchestratorConfig;
|
|
41460
|
+
const validCacheTags = Object.values(CacheTags);
|
|
41461
|
+
const webSocket = yield getWebSocket(orchestratorWebsocketUrl);
|
|
41462
|
+
webSocket.onopen = () => {
|
|
41463
|
+
updateCachedData(() => true);
|
|
41464
|
+
};
|
|
41433
41465
|
webSocket.addEventListener(
|
|
41434
41466
|
"message",
|
|
41435
|
-
(
|
|
41436
|
-
const
|
|
41437
|
-
if (
|
|
41467
|
+
(messageEvent) => {
|
|
41468
|
+
const data = messageEvent.data;
|
|
41469
|
+
if (data === "__pong__") {
|
|
41438
41470
|
debounceCloseWebSocket();
|
|
41439
41471
|
return;
|
|
41440
41472
|
}
|
|
41441
|
-
const
|
|
41442
|
-
|
|
41443
|
-
if (tagToInvalidate && validCacheTags.includes(tagToInvalidate)) {
|
|
41444
|
-
const cacheInvalidationAction = orchestratorApi.util.invalidateTags([
|
|
41445
|
-
tagToInvalidate
|
|
41446
|
-
]);
|
|
41447
|
-
dispatch(cacheInvalidationAction);
|
|
41448
|
-
} else {
|
|
41449
|
-
console.error(
|
|
41450
|
-
`Trying to invalidate a cache entry with an unknown tag: ${tagToInvalidate}`
|
|
41451
|
-
);
|
|
41452
|
-
}
|
|
41473
|
+
const message = JSON.parse(data);
|
|
41474
|
+
handleInvalidateCacheMessage(message);
|
|
41453
41475
|
}
|
|
41454
41476
|
);
|
|
41455
41477
|
webSocket.onerror = (event) => {
|
package/package.json
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { debounce } from 'lodash';
|
|
2
|
+
import { getSession } from 'next-auth/react';
|
|
2
3
|
|
|
4
|
+
import type { WfoSession } from '@/hooks';
|
|
3
5
|
import { addToastMessage } from '@/rtk/slices/toastMessages';
|
|
4
6
|
import type { RootState } from '@/rtk/store';
|
|
5
7
|
import { ToastTypes } from '@/types';
|
|
@@ -7,15 +9,24 @@ import { getToastMessage } from '@/utils/getToastMessage';
|
|
|
7
9
|
|
|
8
10
|
import { CacheTags, orchestratorApi } from '../api';
|
|
9
11
|
|
|
10
|
-
const getWebSocket = (url: string) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const getWebSocket = async (url: string) => {
|
|
13
|
+
const session = (await getSession()) as WfoSession;
|
|
14
|
+
const token = session?.accessToken ? [session?.accessToken] : [];
|
|
15
|
+
// Implemented authentication taking this into account: https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api/77060459#77060459
|
|
16
|
+
return new WebSocket(url, token);
|
|
14
17
|
};
|
|
15
18
|
|
|
16
|
-
const PING_INTERVAL_MS =
|
|
17
|
-
const DEBOUNCE_CLOSE_INTERVAL_MS =
|
|
19
|
+
const PING_INTERVAL_MS = 45000; // Recommended values are between 30 and 60 seconds
|
|
20
|
+
const DEBOUNCE_CLOSE_INTERVAL_MS = 60000;
|
|
18
21
|
|
|
22
|
+
type WebSocketMessage = {
|
|
23
|
+
name: MessageTypes;
|
|
24
|
+
value: string[] | string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
enum MessageTypes {
|
|
28
|
+
invalidateCache = 'invalidateCache',
|
|
29
|
+
}
|
|
19
30
|
/*
|
|
20
31
|
* Websocket handling as recommended by RTK QUery see: https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#streaming-data-with-no-initial-request
|
|
21
32
|
* The websocket is opened after the cacheDataLoaded promise is resolved, and closed after the cacheEntryRemoved promise is resolved maintaining
|
|
@@ -52,22 +63,43 @@ const streamMessagesApi = orchestratorApi.injectEndpoints({
|
|
|
52
63
|
updateCachedData(() => false);
|
|
53
64
|
};
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
const invalidateTag = (tag: string) => {
|
|
67
|
+
const tagToInvalidate = tag as CacheTags;
|
|
68
|
+
if (validCacheTags.includes(tagToInvalidate)) {
|
|
69
|
+
const cacheInvalidationAction =
|
|
70
|
+
orchestratorApi.util.invalidateTags([
|
|
71
|
+
tagToInvalidate,
|
|
72
|
+
]);
|
|
73
|
+
dispatch(cacheInvalidationAction);
|
|
74
|
+
} else {
|
|
75
|
+
console.error(
|
|
76
|
+
`Trying to invalidate a cache entry with an unknown tag: ${tagToInvalidate}`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
59
80
|
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
const handleInvalidateCacheMessage = (
|
|
82
|
+
message: WebSocketMessage,
|
|
83
|
+
) => {
|
|
84
|
+
if (message.name === MessageTypes.invalidateCache) {
|
|
85
|
+
const messageValue = message.value;
|
|
62
86
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
87
|
+
if (typeof messageValue === 'string') {
|
|
88
|
+
invalidateTag(messageValue);
|
|
89
|
+
} else if (Array.isArray(messageValue)) {
|
|
90
|
+
messageValue.forEach((tag) => invalidateTag(tag));
|
|
91
|
+
} else {
|
|
92
|
+
console.error(
|
|
93
|
+
'invalid message value type',
|
|
94
|
+
messageValue,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
66
98
|
};
|
|
67
99
|
|
|
68
100
|
// Send a ping message every to the websocket server to keep the connection alive
|
|
69
101
|
const pingInterval = setInterval(() => {
|
|
70
|
-
webSocket.send('
|
|
102
|
+
webSocket.send('__ping__');
|
|
71
103
|
}, PING_INTERVAL_MS);
|
|
72
104
|
|
|
73
105
|
const debounceCloseWebSocket = debounce(() => {
|
|
@@ -76,34 +108,32 @@ const streamMessagesApi = orchestratorApi.injectEndpoints({
|
|
|
76
108
|
// Start the debounced function to close the websocket when no 'pong' message is received after DEBOUNCE_CLOSE_INTERVAL
|
|
77
109
|
debounceCloseWebSocket();
|
|
78
110
|
|
|
111
|
+
await cacheDataLoaded;
|
|
112
|
+
|
|
113
|
+
const state = getState() as RootState;
|
|
114
|
+
const { orchestratorWebsocketUrl } = state.orchestratorConfig;
|
|
115
|
+
const validCacheTags = Object.values(CacheTags);
|
|
116
|
+
|
|
117
|
+
// Starts the websocket
|
|
118
|
+
const webSocket = await getWebSocket(orchestratorWebsocketUrl);
|
|
119
|
+
|
|
120
|
+
// Lets the WfoWebsocketStatusBadge know the websocket is connected
|
|
121
|
+
webSocket.onopen = () => {
|
|
122
|
+
updateCachedData(() => true);
|
|
123
|
+
};
|
|
124
|
+
|
|
79
125
|
webSocket.addEventListener(
|
|
80
126
|
'message',
|
|
81
|
-
(
|
|
82
|
-
const
|
|
127
|
+
(messageEvent: MessageEvent<string>) => {
|
|
128
|
+
const data = messageEvent.data;
|
|
83
129
|
|
|
84
|
-
if (
|
|
130
|
+
if (data === '__pong__') {
|
|
85
131
|
// Reset the debounced every time a 'pong' message is received
|
|
86
132
|
debounceCloseWebSocket();
|
|
87
133
|
return;
|
|
88
134
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const validCacheTags = Object.values(CacheTags);
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
tagToInvalidate &&
|
|
95
|
-
validCacheTags.includes(tagToInvalidate)
|
|
96
|
-
) {
|
|
97
|
-
const cacheInvalidationAction =
|
|
98
|
-
orchestratorApi.util.invalidateTags([
|
|
99
|
-
tagToInvalidate,
|
|
100
|
-
]);
|
|
101
|
-
dispatch(cacheInvalidationAction);
|
|
102
|
-
} else {
|
|
103
|
-
console.error(
|
|
104
|
-
`Trying to invalidate a cache entry with an unknown tag: ${tagToInvalidate}`,
|
|
105
|
-
);
|
|
106
|
-
}
|
|
135
|
+
const message = JSON.parse(data) as WebSocketMessage;
|
|
136
|
+
handleInvalidateCacheMessage(message);
|
|
107
137
|
},
|
|
108
138
|
);
|
|
109
139
|
|