dce-expresskit 4.3.4 → 5.0.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/lib/helpers/addDBEditorEndpoints/generateEndpointPath.js +2 -1
- package/lib/helpers/addDBEditorEndpoints/generateEndpointPath.js.map +1 -1
- package/lib/helpers/addDBEditorEndpoints/index.js +5 -5
- package/lib/helpers/addDBEditorEndpoints/index.js.map +1 -1
- package/lib/helpers/dataSigner.js +13 -13
- package/lib/helpers/dataSigner.js.map +1 -1
- package/lib/helpers/genRouteHandler.d.ts +1 -1
- package/lib/helpers/genRouteHandler.js +35 -35
- package/lib/helpers/genRouteHandler.js.map +1 -1
- package/lib/helpers/getLogReviewerLogs.d.ts +1 -1
- package/lib/helpers/getLogReviewerLogs.js +5 -5
- package/lib/helpers/getLogReviewerLogs.js.map +1 -1
- package/lib/helpers/handleError.js +2 -2
- package/lib/helpers/handleError.js.map +1 -1
- package/lib/helpers/initExpressKitCollections.d.ts +7 -1
- package/lib/helpers/initExpressKitCollections.js +24 -1
- package/lib/helpers/initExpressKitCollections.js.map +1 -1
- package/lib/helpers/initServer.d.ts +1 -1
- package/lib/helpers/initServer.js +21 -21
- package/lib/helpers/initServer.js.map +1 -1
- package/lib/helpers/visitEndpointOnAnotherServer/index.js +5 -5
- package/lib/helpers/visitEndpointOnAnotherServer/index.js.map +1 -1
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js +7 -7
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js.map +1 -1
- package/lib/html/genErrorPage.d.ts +1 -1
- package/lib/html/genErrorPage.js +4 -4
- package/lib/html/genErrorPage.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +82 -47
- package/lib/index.js.map +1 -1
- package/package.json +2 -8
- package/src/helpers/addDBEditorEndpoints/generateEndpointPath.ts +2 -2
- package/src/helpers/addDBEditorEndpoints/index.ts +2 -2
- package/src/helpers/dataSigner.ts +2 -2
- package/src/helpers/genRouteHandler.ts +9 -9
- package/src/helpers/getLogReviewerLogs.ts +2 -2
- package/src/helpers/handleError.ts +2 -3
- package/src/helpers/initExpressKitCollections.ts +19 -2
- package/src/helpers/initServer.ts +3 -3
- package/src/helpers/visitEndpointOnAnotherServer/index.ts +5 -5
- package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +2 -2
- package/src/html/genErrorPage.ts +4 -7
- package/src/index.ts +4 -3
- package/src/errors/ErrorWithCode.tsx +0 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Import dce-
|
|
1
|
+
// Import dce-commonkit
|
|
2
2
|
import {
|
|
3
3
|
getTimeInfoInET,
|
|
4
4
|
LogFunction,
|
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
LogAction,
|
|
12
12
|
LogLevel,
|
|
13
13
|
ParamType,
|
|
14
|
-
|
|
14
|
+
CommonKitErrorCode,
|
|
15
15
|
LogSource,
|
|
16
|
-
} from 'dce-
|
|
16
|
+
} from 'dce-commonkit';
|
|
17
17
|
|
|
18
18
|
// Import caccl
|
|
19
19
|
import { getLaunchInfo } from 'caccl/server';
|
|
@@ -382,7 +382,7 @@ const genRouteHandler = (
|
|
|
382
382
|
res,
|
|
383
383
|
{
|
|
384
384
|
message: 'Your session has expired. Please refresh the page and try again.',
|
|
385
|
-
code:
|
|
385
|
+
code: CommonKitErrorCode.SessionExpired,
|
|
386
386
|
status: 401,
|
|
387
387
|
},
|
|
388
388
|
);
|
|
@@ -437,7 +437,7 @@ const genRouteHandler = (
|
|
|
437
437
|
res,
|
|
438
438
|
{
|
|
439
439
|
message: 'Your session was invalid. Please refresh the page and try again.',
|
|
440
|
-
code:
|
|
440
|
+
code: CommonKitErrorCode.SessionExpired,
|
|
441
441
|
status: 401,
|
|
442
442
|
},
|
|
443
443
|
);
|
|
@@ -686,7 +686,7 @@ const genRouteHandler = (
|
|
|
686
686
|
? {
|
|
687
687
|
type: LogType.Error,
|
|
688
688
|
errorMessage: (logOpts as any).error.message ?? 'Unknown message',
|
|
689
|
-
errorCode: (logOpts as any).error.code ??
|
|
689
|
+
errorCode: (logOpts as any).error.code ?? CommonKitErrorCode.NoCode,
|
|
690
690
|
errorStack: (logOpts as any).error.stack ?? 'No stack',
|
|
691
691
|
}
|
|
692
692
|
: {
|
|
@@ -730,10 +730,10 @@ const genRouteHandler = (
|
|
|
730
730
|
} else if (log.type === LogType.Error) {
|
|
731
731
|
// Print to console
|
|
732
732
|
// eslint-disable-next-line no-console
|
|
733
|
-
console.error('dce
|
|
733
|
+
console.error('dce error log:', log);
|
|
734
734
|
} else {
|
|
735
735
|
// eslint-disable-next-line no-console
|
|
736
|
-
console.log('dce
|
|
736
|
+
console.log('dce action log:', log);
|
|
737
737
|
}
|
|
738
738
|
|
|
739
739
|
// Return log entry
|
|
@@ -840,7 +840,7 @@ const genRouteHandler = (
|
|
|
840
840
|
* @param [renderOpts.title=An Error Occurred] title of the error box
|
|
841
841
|
* @param [renderOpts.description=An unknown server error occurred. Please contact support.]
|
|
842
842
|
* a human-readable description of the error
|
|
843
|
-
* @param [renderOpts.code=
|
|
843
|
+
* @param [renderOpts.code=CommonKitErrorCode.NoCode] error code to show
|
|
844
844
|
* @param [renderOpts.pageTitle=renderOpts.title] title of the page/tab if it differs from
|
|
845
845
|
* the title of the error
|
|
846
846
|
* @param [renderOpts.status=500] http status code
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Import dce-mango
|
|
2
2
|
import { Collection } from 'dce-mango';
|
|
3
3
|
|
|
4
|
-
// Import dce-
|
|
4
|
+
// Import dce-commonkit
|
|
5
5
|
import {
|
|
6
6
|
DAY_IN_MS,
|
|
7
7
|
Log,
|
|
8
8
|
LogReviewerFilterState,
|
|
9
9
|
LogType
|
|
10
|
-
} from 'dce-
|
|
10
|
+
} from 'dce-commonkit';
|
|
11
11
|
|
|
12
12
|
// Import shared types
|
|
13
13
|
import LOG_REVIEW_PAGE_SIZE from '../constants/LOG_REVIEW_PAGE_SIZE';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Import shared types
|
|
2
|
-
import {
|
|
3
|
-
import ExpressKitErrorCode from '../types/ExpressKitErrorCode';
|
|
2
|
+
import { CommonKitErrorCode } from 'dce-commonkit';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Handle an error and respond to the client
|
|
@@ -42,7 +41,7 @@ const handleError = (
|
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
// Get the error code
|
|
45
|
-
const code = (error.code ||
|
|
44
|
+
const code = (error.code || CommonKitErrorCode.NoCode);
|
|
46
45
|
|
|
47
46
|
// Get the status code
|
|
48
47
|
const status = (error.status || 500);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Import dce-mango
|
|
2
2
|
import { Collection as MangoCollection } from 'dce-mango';
|
|
3
3
|
|
|
4
|
-
// Import dce-
|
|
5
|
-
import { Log } from 'dce-
|
|
4
|
+
// Import dce-commonkit
|
|
5
|
+
import { Log } from 'dce-commonkit';
|
|
6
6
|
|
|
7
7
|
// Import shared types
|
|
8
8
|
import CrossServerCredential from '../types/CrossServerCredential';
|
|
@@ -79,6 +79,23 @@ export const internalGetLogReviewerAdminCollection = async () => {
|
|
|
79
79
|
return logReviewerAdminCollection;
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
/*------------------------------------------------------------------------*/
|
|
83
|
+
/* ----------------------- Public Collection Getters -------------------- */
|
|
84
|
+
/*------------------------------------------------------------------------*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get the log collection. Resolves after the collection has been initialized
|
|
88
|
+
* @author Yuen Ler Chow
|
|
89
|
+
* @returns a promise that resolves with the log collection
|
|
90
|
+
*/
|
|
91
|
+
export const getLogCollection = async () => {
|
|
92
|
+
// Wait for collections to be initialized
|
|
93
|
+
await collectionsInitialized;
|
|
94
|
+
|
|
95
|
+
// Return the log collection
|
|
96
|
+
return logCollection;
|
|
97
|
+
};
|
|
98
|
+
|
|
82
99
|
/*------------------------------------------------------------------------*/
|
|
83
100
|
/* -------------------------------- Main -------------------------------- */
|
|
84
101
|
/*------------------------------------------------------------------------*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Import express
|
|
2
2
|
import express from 'express';
|
|
3
3
|
|
|
4
|
-
// Import dce-
|
|
4
|
+
// Import dce-commonkit
|
|
5
5
|
import {
|
|
6
6
|
ParamType,
|
|
7
7
|
LogFunction,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
LOG_REVIEW_GET_LOGS_ROUTE,
|
|
11
11
|
SELECT_ADMIN_CHECK_ROUTE,
|
|
12
12
|
ErrorWithCode,
|
|
13
|
-
} from 'dce-
|
|
13
|
+
} from 'dce-commonkit';
|
|
14
14
|
|
|
15
15
|
// Import shared helpers
|
|
16
16
|
import genRouteHandler from './genRouteHandler';
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
/*------------------------------------------------------------------------*/
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Prepare dce-
|
|
33
|
+
* Prepare dce-commonkit to run on the server
|
|
34
34
|
* @author Gabe Abrams
|
|
35
35
|
* @param opts object containing all arguments
|
|
36
36
|
* @param opts.app express app from inside of the postprocessor function that
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// Import dce-
|
|
1
|
+
// Import dce-commonkit
|
|
2
2
|
import {
|
|
3
3
|
ErrorWithCode,
|
|
4
|
-
|
|
5
|
-
} from 'dce-
|
|
4
|
+
CommonKitErrorCode,
|
|
5
|
+
} from 'dce-commonkit';
|
|
6
6
|
|
|
7
7
|
// Import shared types
|
|
8
8
|
import sendServerToServerRequest from './sendServerToServerRequest';
|
|
@@ -43,7 +43,7 @@ const visitEndpointOnAnotherServer = async (
|
|
|
43
43
|
if (!response || !response.body) {
|
|
44
44
|
throw new ErrorWithCode(
|
|
45
45
|
'We didn\'t get a response from the other server. Please check the network between the two connection.',
|
|
46
|
-
|
|
46
|
+
CommonKitErrorCode.NoResponse,
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
if (!response.body.success) {
|
|
@@ -55,7 +55,7 @@ const visitEndpointOnAnotherServer = async (
|
|
|
55
55
|
),
|
|
56
56
|
(
|
|
57
57
|
response.body.code
|
|
58
|
-
||
|
|
58
|
+
|| CommonKitErrorCode.NoCode
|
|
59
59
|
),
|
|
60
60
|
);
|
|
61
61
|
}
|
package/src/html/genErrorPage.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
// Import dce-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
// Import shared types
|
|
5
|
-
import ExpressKitErrorCode from '../types/ExpressKitErrorCode';
|
|
1
|
+
// Import dce-commonkit
|
|
2
|
+
import { CommonKitErrorCode } from 'dce-commonkit';
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* Generate a static error page
|
|
@@ -11,7 +8,7 @@ import ExpressKitErrorCode from '../types/ExpressKitErrorCode';
|
|
|
11
8
|
* @param [opts.title=An Error Occurred] title of the error box
|
|
12
9
|
* @param [opts.description=An unknown server error occurred. Please contact support.]
|
|
13
10
|
* a human-readable description of the error
|
|
14
|
-
* @param [opts.code=
|
|
11
|
+
* @param [opts.code=CommonKitErrorCode.NoCode] error code to show
|
|
15
12
|
* @param [opts.pageTitle=opts.title] title of the page/tab if it differs from
|
|
16
13
|
* the title of the error
|
|
17
14
|
* @returns html of the page
|
|
@@ -30,7 +27,7 @@ const genErrorPage = (
|
|
|
30
27
|
opts.description
|
|
31
28
|
?? 'An unknown server error occurred. Please contact support.'
|
|
32
29
|
);
|
|
33
|
-
const code = (opts.code ??
|
|
30
|
+
const code = (opts.code ?? CommonKitErrorCode.NoCode);
|
|
34
31
|
|
|
35
32
|
return `
|
|
36
33
|
<head>
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Import dce-
|
|
1
|
+
// Import dce-commonkit
|
|
2
2
|
import {
|
|
3
3
|
abbreviate,
|
|
4
4
|
avg,
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
DAY_IN_MS,
|
|
47
47
|
ErrorWithCode,
|
|
48
48
|
ParamType,
|
|
49
|
-
} from 'dce-
|
|
49
|
+
} from 'dce-commonkit';
|
|
50
50
|
|
|
51
51
|
// Import helpers
|
|
52
52
|
import initServer from './helpers/initServer';
|
|
@@ -55,7 +55,7 @@ import handleError from './helpers/handleError';
|
|
|
55
55
|
import handleSuccess from './helpers/handleSuccess';
|
|
56
56
|
import addDBEditorEndpoints from './helpers/addDBEditorEndpoints';
|
|
57
57
|
import visitEndpointOnAnotherServer from './helpers/visitEndpointOnAnotherServer';
|
|
58
|
-
import initExpressKitCollections from './helpers/initExpressKitCollections';
|
|
58
|
+
import initExpressKitCollections, { getLogCollection } from './helpers/initExpressKitCollections';
|
|
59
59
|
|
|
60
60
|
// Import types
|
|
61
61
|
import CrossServerCredential from './types/CrossServerCredential';
|
|
@@ -108,6 +108,7 @@ export {
|
|
|
108
108
|
handleError,
|
|
109
109
|
handleSuccess,
|
|
110
110
|
initExpressKitCollections,
|
|
111
|
+
getLogCollection,
|
|
111
112
|
addDBEditorEndpoints,
|
|
112
113
|
visitEndpointOnAnotherServer,
|
|
113
114
|
// Types
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An error with a code
|
|
3
|
-
* @author Gabe Abrams
|
|
4
|
-
*/
|
|
5
|
-
class ErrorWithCode extends Error {
|
|
6
|
-
code: string;
|
|
7
|
-
|
|
8
|
-
constructor(message: string, code: string) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = 'ErrorWithCode';
|
|
11
|
-
this.code = code;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default ErrorWithCode;
|