-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathsettings-service.ts
More file actions
76 lines (67 loc) · 3.03 KB
/
settings-service.ts
File metadata and controls
76 lines (67 loc) · 3.03 KB
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
import { BROWSER } from 'esm-env';
import type { SettingsResponse } from '$lib/types';
import type { Settings } from '$lib/types/global';
import { getApiOrigin } from '$lib/utilities/get-api-origin';
import { getEnvironment } from '$lib/utilities/get-environment';
import { requestFromAPI } from '$lib/utilities/request-from-api';
import { routeForApi } from '$lib/utilities/route-for-api';
export const isCloudMatch = /(tmprl\.cloud|tmprl-test\.cloud)$/;
export const fetchSettings = async (request = fetch): Promise<Settings> => {
const route = routeForApi('settings');
const settingsResponse: SettingsResponse = await requestFromAPI(route, {
request,
});
const EnvironmentOverride = getEnvironment();
const settingsInformation = {
auth: {
enabled: !!settingsResponse?.Auth?.Enabled,
options: settingsResponse?.Auth?.Options,
},
baseUrl: getApiOrigin(),
codec: {
endpoint: settingsResponse?.Codec?.Endpoint,
passAccessToken: settingsResponse?.Codec?.PassAccessToken,
includeCredentials: settingsResponse?.Codec?.IncludeCredentials,
customErrorMessage: {
default: {
message: settingsResponse?.Codec?.DefaultErrorMessage || '',
link: settingsResponse?.Codec?.DefaultErrorLink || '',
},
},
},
defaultNamespace: settingsResponse?.DefaultNamespace || 'default', // API returns an empty string if default namespace is not configured
disableWriteActions: !!settingsResponse?.DisableWriteActions || false,
workflowTerminateDisabled: !!settingsResponse?.WorkflowTerminateDisabled,
workflowCancelDisabled: !!settingsResponse?.WorkflowCancelDisabled,
workflowSignalDisabled: !!settingsResponse?.WorkflowSignalDisabled,
workflowUpdateDisabled: !!settingsResponse?.WorkflowUpdateDisabled,
workflowResetDisabled: !!settingsResponse?.WorkflowResetDisabled,
workflowPauseDisabled: !!settingsResponse?.WorkflowPauseDisabled,
batchActionsDisabled: !!settingsResponse?.BatchActionsDisabled,
startWorkflowDisabled: !!settingsResponse?.StartWorkflowDisabled,
hideWorkflowQueryErrors: !!settingsResponse?.HideWorkflowQueryErrors,
refreshWorkflowCountsDisabled:
!!settingsResponse?.RefreshWorkflowCountsDisabled,
activityCommandsDisabled: !!settingsResponse?.ActivityCommandsDisabled,
disableTrackingPixel: !!settingsResponse?.DisableTrackingPixel,
showTemporalSystemNamespace: settingsResponse?.ShowTemporalSystemNamespace,
feedbackURL: settingsResponse?.FeedbackURL,
runtimeEnvironment: {
get isCloud() {
if (EnvironmentOverride) {
return EnvironmentOverride === 'cloud';
}
return isCloudMatch.test(BROWSER ? window.location.hostname : '');
},
get isLocal() {
if (EnvironmentOverride) {
return EnvironmentOverride === 'local';
}
return isCloudMatch.test(BROWSER ? window.location.hostname : '');
},
envOverride: Boolean(EnvironmentOverride),
},
version: settingsResponse?.Version,
};
return settingsInformation;
};