@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @orchestrator-ui/orchestrator-ui-components@1.11.0 build
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
  CLI Building entry: src/index.ts
@@ -9,6 +9,6 @@
9
9
  ESM Build start
10
10
  DTS Build start
11
11
  ESM dist/index.js 2.12 MB
12
- ESM ⚡️ Build success in 619ms
13
- DTS ⚡️ Build success in 13044ms
12
+ ESM ⚡️ Build success in 666ms
13
+ DTS ⚡️ Build success in 12853ms
14
14
  DTS dist/index.d.ts 161.35 KB
@@ -1,5 +1,5 @@
1
1
 
2
- > @orchestrator-ui/orchestrator-ui-components@1.11.0 lint
2
+ > @orchestrator-ui/orchestrator-ui-components@1.12.0 lint
3
3
  > eslint "src/**/*.ts*"
4
4
 
5
5
 
@@ -1,19 +1,19 @@
1
1
 
2
- > @orchestrator-ui/orchestrator-ui-components@1.11.0 test
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/toOptionalArrayEntry.spec.ts
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.684 s
35
+ Time: 3.654 s
36
36
  Ran all test suites.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @orchestrator-ui/orchestrator-ui-components
2
2
 
3
+ ## 1.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a95a6dc: Updates what the websocket interface is listening to
8
+
3
9
  ## 1.11.0
4
10
 
5
11
  ### Minor Changes
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
- return new WebSocket(url);
41392
- };
41393
- var PING_INTERVAL_MS = 5e3;
41394
- var DEBOUNCE_CLOSE_INTERVAL_MS = 1e4;
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
- yield cacheDataLoaded;
41420
- const state = getState();
41421
- const { orchestratorWebsocketUrl } = state.orchestratorConfig;
41422
- const webSocket = getWebSocket(orchestratorWebsocketUrl);
41423
- webSocket.onopen = () => {
41424
- updateCachedData(() => true);
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("ping");
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
- (message) => {
41436
- const tagOrPong = message.data.trim();
41437
- if (tagOrPong === "pong") {
41467
+ (messageEvent) => {
41468
+ const data = messageEvent.data;
41469
+ if (data === "__pong__") {
41438
41470
  debounceCloseWebSocket();
41439
41471
  return;
41440
41472
  }
41441
- const tagToInvalidate = tagOrPong;
41442
- const validCacheTags = Object.values(CacheTags);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@orchestrator-ui/orchestrator-ui-components",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Library of UI Components used to display the workflow orchestrator frontend",
6
6
  "author": {
@@ -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
- // TODO: Implement authentication taking this into account: https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api/77060459#77060459
12
- // https://github.com/workfloworchestrator/orchestrator-core/issues/502 - https://github.com/workfloworchestrator/orchestrator-ui-library/issues/823
13
- return new WebSocket(url);
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 = 5000;
17
- const DEBOUNCE_CLOSE_INTERVAL_MS = 10000;
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
- await cacheDataLoaded;
56
-
57
- const state = getState() as RootState;
58
- const { orchestratorWebsocketUrl } = state.orchestratorConfig;
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
- // Starts the websocket
61
- const webSocket = getWebSocket(orchestratorWebsocketUrl);
81
+ const handleInvalidateCacheMessage = (
82
+ message: WebSocketMessage,
83
+ ) => {
84
+ if (message.name === MessageTypes.invalidateCache) {
85
+ const messageValue = message.value;
62
86
 
63
- // Lets the WfoWebsocketStatusBadge know the websocket is connected
64
- webSocket.onopen = () => {
65
- updateCachedData(() => true);
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('ping');
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
- (message: MessageEvent<string>) => {
82
- const tagOrPong = message.data.trim();
127
+ (messageEvent: MessageEvent<string>) => {
128
+ const data = messageEvent.data;
83
129
 
84
- if (tagOrPong === 'pong') {
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
- const tagToInvalidate = tagOrPong as CacheTags;
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