dce-reactkit 3.10.3 → 3.11.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/dist/cjs/index.js +16 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/client/initClient.d.ts +16 -2
- package/dist/esm/index.js +16 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/client/initClient.d.ts +16 -2
- package/dist/index.d.ts +10 -2
- package/package.json +1 -1
- package/src/client/initClient.tsx +49 -11
- package/src/helpers/logClientEvent.tsx +8 -0
- package/src/helpers/visitServerEndpoint.tsx +1 -0
|
@@ -19,6 +19,12 @@ type SendRequestFunction = (opts: {
|
|
|
19
19
|
[x: string]: any;
|
|
20
20
|
};
|
|
21
21
|
}>;
|
|
22
|
+
declare let noServer: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Check if there is no server for this app
|
|
25
|
+
* @author Gabe Abrams
|
|
26
|
+
*/
|
|
27
|
+
export declare const appHasNoServer: () => boolean;
|
|
22
28
|
/**
|
|
23
29
|
* Get the send request function
|
|
24
30
|
* @author Gabe Abrams
|
|
@@ -44,10 +50,18 @@ export declare const isDarkModeOn: () => boolean;
|
|
|
44
50
|
* @param opts object containing all arguments
|
|
45
51
|
* @param opts.sendRequest caccl send request functions
|
|
46
52
|
* @param [opts.sessionExpiredMessage] a custom session expired message
|
|
53
|
+
* @param [opts.darkModeOn] if true, dark mode is enabled
|
|
54
|
+
* @param [opts.noServer] if true, there is no server for this app
|
|
47
55
|
*/
|
|
48
|
-
declare const initClient: (opts: {
|
|
56
|
+
declare const initClient: (opts: ({
|
|
49
57
|
sendRequest: SendRequestFunction;
|
|
50
58
|
sessionExpiredMessage?: string;
|
|
51
59
|
darkModeOn?: boolean;
|
|
52
|
-
|
|
60
|
+
noServer?: false;
|
|
61
|
+
} | {
|
|
62
|
+
darkModeOn?: boolean;
|
|
63
|
+
noServer: true;
|
|
64
|
+
sendRequest?: undefined;
|
|
65
|
+
sessionExpiredMessage?: undefined;
|
|
66
|
+
})) => void;
|
|
53
67
|
export default initClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -810,12 +810,20 @@ type SendRequestFunction = (opts: {
|
|
|
810
810
|
* @param opts object containing all arguments
|
|
811
811
|
* @param opts.sendRequest caccl send request functions
|
|
812
812
|
* @param [opts.sessionExpiredMessage] a custom session expired message
|
|
813
|
+
* @param [opts.darkModeOn] if true, dark mode is enabled
|
|
814
|
+
* @param [opts.noServer] if true, there is no server for this app
|
|
813
815
|
*/
|
|
814
|
-
declare const initClient: (opts: {
|
|
816
|
+
declare const initClient: (opts: ({
|
|
815
817
|
sendRequest: SendRequestFunction;
|
|
816
818
|
sessionExpiredMessage?: string;
|
|
817
819
|
darkModeOn?: boolean;
|
|
818
|
-
|
|
820
|
+
noServer?: false;
|
|
821
|
+
} | {
|
|
822
|
+
darkModeOn?: boolean;
|
|
823
|
+
noServer: true;
|
|
824
|
+
sendRequest?: undefined;
|
|
825
|
+
sessionExpiredMessage?: undefined;
|
|
826
|
+
})) => void;
|
|
819
827
|
|
|
820
828
|
/**
|
|
821
829
|
* Shorten text so it fits into a certain number of chars
|
package/package.json
CHANGED
|
@@ -47,6 +47,18 @@ const initialized = new Promise((resolve) => {
|
|
|
47
47
|
onInitialized = resolve;
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
/* ------------ No Server ----------- */
|
|
51
|
+
|
|
52
|
+
let noServer = false;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Check if there is no server for this app
|
|
56
|
+
* @author Gabe Abrams
|
|
57
|
+
*/
|
|
58
|
+
export const appHasNoServer = () => {
|
|
59
|
+
return noServer;
|
|
60
|
+
};
|
|
61
|
+
|
|
50
62
|
/* ---------- Send Request ---------- */
|
|
51
63
|
|
|
52
64
|
let storedSendRequest: SendRequestFunction;
|
|
@@ -119,20 +131,46 @@ export const isDarkModeOn = () => {
|
|
|
119
131
|
* @param opts object containing all arguments
|
|
120
132
|
* @param opts.sendRequest caccl send request functions
|
|
121
133
|
* @param [opts.sessionExpiredMessage] a custom session expired message
|
|
134
|
+
* @param [opts.darkModeOn] if true, dark mode is enabled
|
|
135
|
+
* @param [opts.noServer] if true, there is no server for this app
|
|
122
136
|
*/
|
|
123
137
|
const initClient = (
|
|
124
|
-
opts:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
opts: (
|
|
139
|
+
| {
|
|
140
|
+
// Copy of CACCL's send request function
|
|
141
|
+
sendRequest: SendRequestFunction,
|
|
142
|
+
// Custom session expired message
|
|
143
|
+
sessionExpiredMessage?: string,
|
|
144
|
+
// If true, dark mode is enabled
|
|
145
|
+
darkModeOn?: boolean,
|
|
146
|
+
// If true, there is no server for this app
|
|
147
|
+
noServer?: false,
|
|
148
|
+
}
|
|
149
|
+
| {
|
|
150
|
+
// If true, dark mode is enabled
|
|
151
|
+
darkModeOn?: boolean,
|
|
152
|
+
// If true, there is no server for this app
|
|
153
|
+
noServer: true
|
|
154
|
+
// Copy of CACCL's send request function
|
|
155
|
+
sendRequest?: undefined,
|
|
156
|
+
// Custom session expired message
|
|
157
|
+
sessionExpiredMessage?: undefined,
|
|
158
|
+
}
|
|
159
|
+
),
|
|
132
160
|
) => {
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
161
|
+
// Handle separately if there is no server
|
|
162
|
+
if (opts.noServer) {
|
|
163
|
+
// Store values
|
|
164
|
+
storedSendRequest = async () => {
|
|
165
|
+
throw new Error('Cannot send requests because there is no server');
|
|
166
|
+
};
|
|
167
|
+
} else {
|
|
168
|
+
// Store values
|
|
169
|
+
storedSendRequest = opts.sendRequest;
|
|
170
|
+
sessionExpiredMessage = opts.sessionExpiredMessage;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Handle universal parts
|
|
136
174
|
darkModeOn = !!opts.darkModeOn;
|
|
137
175
|
|
|
138
176
|
// Mark as initialized
|
|
@@ -7,6 +7,9 @@ import LogLevel from '../types/LogLevel';
|
|
|
7
7
|
// Import shared functions
|
|
8
8
|
import visitServerEndpoint from './visitServerEndpoint';
|
|
9
9
|
|
|
10
|
+
// Import status
|
|
11
|
+
import { appHasNoServer } from '../client/initClient';
|
|
12
|
+
|
|
10
13
|
/* ------- Metadata Populator ------- */
|
|
11
14
|
|
|
12
15
|
// Type of a metadata populator function
|
|
@@ -36,6 +39,11 @@ export const setClientEventMetadataPopulator = (
|
|
|
36
39
|
* @author Gabe Abrams
|
|
37
40
|
*/
|
|
38
41
|
const logClientEvent: LogFunction = async (opts) => {
|
|
42
|
+
// Don't write to the server if there is none
|
|
43
|
+
if (appHasNoServer()) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
// Populate metadata
|
|
40
48
|
let metadata = (opts.metadata ?? {});
|
|
41
49
|
if (metadataPopulator) {
|
|
@@ -102,6 +102,7 @@ const visitServerEndpoint = async (
|
|
|
102
102
|
params?: { [key in string]: any },
|
|
103
103
|
},
|
|
104
104
|
): Promise<any> => {
|
|
105
|
+
// Set default method
|
|
105
106
|
const method = (opts.method ?? 'GET');
|
|
106
107
|
// Handle stubs
|
|
107
108
|
const stubResponse = stubResponses[method]?.[opts.path];
|