dce-expresskit 4.3.5 → 5.0.1
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 +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.d.ts +4 -0
- package/lib/helpers/visitEndpointOnAnotherServer/index.js +9 -5
- package/lib/helpers/visitEndpointOnAnotherServer/index.js.map +1 -1
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +3 -0
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js +50 -30
- 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 +1 -1
- package/lib/index.js +45 -45
- 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 +2 -2
- package/src/helpers/initServer.ts +3 -3
- package/src/helpers/visitEndpointOnAnotherServer/index.ts +10 -5
- package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +54 -31
- package/src/html/genErrorPage.ts +4 -7
- package/src/index.ts +2 -2
- 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';
|
|
@@ -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';
|
|
@@ -20,6 +20,9 @@ import sendServerToServerRequest from './sendServerToServerRequest';
|
|
|
20
20
|
* @param opts.host the host of the other server
|
|
21
21
|
* @param [opts.params={}] query/body parameters to include
|
|
22
22
|
* @param [opts.responseType=JSON] the response type from the other server
|
|
23
|
+
* @param [opts.dceKitCrossServerCredentials] additional cross-server credentials
|
|
24
|
+
* that aren't in the env var list
|
|
25
|
+
* @returns the body of the response from the other server
|
|
23
26
|
*/
|
|
24
27
|
const visitEndpointOnAnotherServer = async (
|
|
25
28
|
opts: {
|
|
@@ -28,6 +31,7 @@ const visitEndpointOnAnotherServer = async (
|
|
|
28
31
|
host: string,
|
|
29
32
|
params?: { [key in string]: any },
|
|
30
33
|
responseType?: 'JSON' | 'Text',
|
|
34
|
+
dceKitCrossServerCredentials?: string,
|
|
31
35
|
},
|
|
32
36
|
): Promise<any> => {
|
|
33
37
|
// Send the request
|
|
@@ -37,13 +41,14 @@ const visitEndpointOnAnotherServer = async (
|
|
|
37
41
|
method: opts.method,
|
|
38
42
|
params: opts.params,
|
|
39
43
|
responseType: opts.responseType,
|
|
44
|
+
dceKitCrossServerCredentials: opts.dceKitCrossServerCredentials,
|
|
40
45
|
});
|
|
41
46
|
|
|
42
47
|
// Check for failure
|
|
43
48
|
if (!response || !response.body) {
|
|
44
49
|
throw new ErrorWithCode(
|
|
45
50
|
'We didn\'t get a response from the other server. Please check the network between the two connection.',
|
|
46
|
-
|
|
51
|
+
CommonKitErrorCode.NoResponse,
|
|
47
52
|
);
|
|
48
53
|
}
|
|
49
54
|
if (!response.body.success) {
|
|
@@ -55,7 +60,7 @@ const visitEndpointOnAnotherServer = async (
|
|
|
55
60
|
),
|
|
56
61
|
(
|
|
57
62
|
response.body.code
|
|
58
|
-
||
|
|
63
|
+
|| CommonKitErrorCode.NoCode
|
|
59
64
|
),
|
|
60
65
|
);
|
|
61
66
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Import libs
|
|
2
2
|
import qs from 'qs';
|
|
3
3
|
|
|
4
|
-
// Import dce-
|
|
4
|
+
// Import dce-commonkit
|
|
5
5
|
import {
|
|
6
6
|
ErrorWithCode,
|
|
7
|
-
} from 'dce-
|
|
7
|
+
} from 'dce-commonkit';
|
|
8
8
|
|
|
9
9
|
// Import data signer
|
|
10
10
|
import { signRequest } from '../dataSigner';
|
|
@@ -25,37 +25,52 @@ const credentials: {
|
|
|
25
25
|
host: string,
|
|
26
26
|
key: string,
|
|
27
27
|
secret: string,
|
|
28
|
-
}[] =
|
|
29
|
-
(process.env.DCEKIT_CROSS_SERVER_CREDENTIALS ?? '')
|
|
30
|
-
// Replace multiple | with a single one
|
|
31
|
-
.replace(/\|+/g, '|')
|
|
32
|
-
// Split by |
|
|
33
|
-
.split('|')
|
|
34
|
-
// Remove empty strings
|
|
35
|
-
.filter((str) => {
|
|
36
|
-
return str.trim().length > 0;
|
|
37
|
-
})
|
|
38
|
-
// Process each credential
|
|
39
|
-
.map((str) => {
|
|
40
|
-
// Split by :
|
|
41
|
-
const parts = str.split(':');
|
|
28
|
+
}[] = [];
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
'Invalid DCEKIT_CROSS_SERVER_CREDENTIALS format. Each credential must be in the format |host:key:secret|',
|
|
47
|
-
ExpressKitErrorCode.InvalidCrossServerCredentialsFormat,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
30
|
+
/*------------------------------------------------------------------------*/
|
|
31
|
+
/* ------------------------------- Helpers ------------------------------ */
|
|
32
|
+
/*------------------------------------------------------------------------*/
|
|
50
33
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Parse a credentials string into an array of credentials
|
|
36
|
+
* @author Gabe Abrams
|
|
37
|
+
* @param credentialsStr the credentials string to parse
|
|
38
|
+
* @returns an array of credentials
|
|
39
|
+
*/
|
|
40
|
+
const parseCredentials = (credentialsStr: string) => {
|
|
41
|
+
credentialsStr
|
|
42
|
+
// Replace multiple | with a single one
|
|
43
|
+
.replace(/\|+/g, '|')
|
|
44
|
+
// Split by |
|
|
45
|
+
.split('|')
|
|
46
|
+
// Remove empty strings
|
|
47
|
+
.filter((str) => {
|
|
48
|
+
return str.trim().length > 0;
|
|
49
|
+
})
|
|
50
|
+
// Process each credential
|
|
51
|
+
.forEach((str) => {
|
|
52
|
+
// Split by :
|
|
53
|
+
const parts = str.split(':');
|
|
54
|
+
|
|
55
|
+
// Check for errors
|
|
56
|
+
if (parts.length !== 3) {
|
|
57
|
+
throw new ErrorWithCode(
|
|
58
|
+
'Invalid DCEKIT_CROSS_SERVER_CREDENTIALS format. Each credential must be in the format |host:key:secret|',
|
|
59
|
+
ExpressKitErrorCode.InvalidCrossServerCredentialsFormat,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Add the credential to the array
|
|
64
|
+
credentials.push({
|
|
65
|
+
host: parts[0].trim(),
|
|
66
|
+
key: parts[1].trim(),
|
|
67
|
+
secret: parts[2].trim(),
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Auto-parse credentials from env variable
|
|
73
|
+
parseCredentials(process.env.DCEKIT_CROSS_SERVER_CREDENTIALS ?? '');
|
|
59
74
|
|
|
60
75
|
/*------------------------------------------------------------------------*/
|
|
61
76
|
/* ------------------------------- Helpers ------------------------------ */
|
|
@@ -96,6 +111,8 @@ const getCrossServerCredential = (host: string) => {
|
|
|
96
111
|
* @param [opts.method=GET] http method to use
|
|
97
112
|
* @param [opts.params] body/data to include in the request
|
|
98
113
|
* @param [opts.responseType=JSON] expected response type
|
|
114
|
+
* @param [opts.dceKitCrossServerCredentials] additional cross-server credentials
|
|
115
|
+
* that aren't in the env var list
|
|
99
116
|
* @returns { body, status, headers } on success
|
|
100
117
|
*/
|
|
101
118
|
const sendServerToServerRequest = async (
|
|
@@ -105,12 +122,18 @@ const sendServerToServerRequest = async (
|
|
|
105
122
|
method?: ('GET' | 'POST' | 'PUT' | 'DELETE'),
|
|
106
123
|
params?: { [k in string]: any },
|
|
107
124
|
responseType?: 'Text' | 'JSON',
|
|
125
|
+
dceKitCrossServerCredentials?: string,
|
|
108
126
|
},
|
|
109
127
|
): Promise<{
|
|
110
128
|
body: any,
|
|
111
129
|
status: number,
|
|
112
130
|
headers: { [k in string]: any },
|
|
113
131
|
}> => {
|
|
132
|
+
// If additional credentials were provided, parse them and add to the list
|
|
133
|
+
if (opts.dceKitCrossServerCredentials) {
|
|
134
|
+
parseCredentials(opts.dceKitCrossServerCredentials);
|
|
135
|
+
}
|
|
136
|
+
|
|
114
137
|
// Process method
|
|
115
138
|
const method: ('GET' | 'POST' | 'PUT' | 'DELETE') = (opts.method || 'GET');
|
|
116
139
|
|
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';
|
|
@@ -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;
|