-
Notifications
You must be signed in to change notification settings - Fork 22
/
config.ts
81 lines (69 loc) · 1.95 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import type { ResourceFetch } from '@openshift/dynamic-plugin-sdk';
import type { Store } from 'redux';
import type { WebSocketAppSettings, WebSocketOptions } from './web-socket/types';
export type UtilsConfig = {
/**
* Resource fetch implementation provided by the host application.
*
* Applications must validate the response before resolving the Promise.
*
* If the request cannot be completed successfully, the Promise should be rejected
* with an appropriate error.
*/
appFetch: ResourceFetch;
/**
* Configure the web socket settings for your application.
*/
wsAppSettings: (
options: WebSocketOptions & { wsPrefix?: string; pathPrefix?: string },
) => Promise<WebSocketAppSettings>;
};
let config: Readonly<UtilsConfig> | undefined;
/**
* Checks if the {@link UtilsConfig} is set.
*/
export const isUtilsConfigSet = (): boolean => {
return config !== undefined;
};
/**
* Set the {@link UtilsConfig} reference.
*
* This must be done before using any of the Kubernetes utilities.
*/
export const setUtilsConfig = (c: UtilsConfig) => {
if (config !== undefined) {
throw new Error('UtilsConfig reference has already been set');
}
config = Object.freeze({ ...c });
};
/**
* Get the {@link UtilsConfig} reference.
*
* Throws an error if the reference isn't already set.
*/
export const getUtilsConfig = (): UtilsConfig => {
if (config === undefined) {
throw new Error('UtilsConfig reference has not been set');
}
return config;
};
let reduxStore: Store;
/**
* Set the {@link Store} reference.
*
* This must be done before using the AppInitSDK React entrypoint
*/
export const setReduxStore = (storeData: Store) => {
reduxStore = storeData;
};
/**
* Get the {@link Store} reference.
*
* Throws an error if the reference isn't already set.
*/
export const getReduxStore = () => {
if (reduxStore === undefined) {
throw new Error('Redux store reference has not been set');
}
return reduxStore;
};