dce-expresskit 5.0.0 → 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/visitEndpointOnAnotherServer/index.d.ts +4 -0
- package/lib/helpers/visitEndpointOnAnotherServer/index.js +4 -0
- package/lib/helpers/visitEndpointOnAnotherServer/index.js.map +1 -1
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +3 -0
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js +44 -24
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/visitEndpointOnAnotherServer/index.ts +5 -0
- package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +52 -29
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* @param opts.host the host of the other server
|
|
8
8
|
* @param [opts.params={}] query/body parameters to include
|
|
9
9
|
* @param [opts.responseType=JSON] the response type from the other server
|
|
10
|
+
* @param [opts.dceKitCrossServerCredentials] additional cross-server credentials
|
|
11
|
+
* that aren't in the env var list
|
|
12
|
+
* @returns the body of the response from the other server
|
|
10
13
|
*/
|
|
11
14
|
declare const visitEndpointOnAnotherServer: (opts: {
|
|
12
15
|
method: "GET" | "POST" | "DELETE" | "PUT";
|
|
@@ -14,5 +17,6 @@ declare const visitEndpointOnAnotherServer: (opts: {
|
|
|
14
17
|
host: string;
|
|
15
18
|
params?: { [key in string]: any; };
|
|
16
19
|
responseType?: "JSON" | "Text";
|
|
20
|
+
dceKitCrossServerCredentials?: string;
|
|
17
21
|
}) => Promise<any>;
|
|
18
22
|
export default visitEndpointOnAnotherServer;
|
|
@@ -55,6 +55,9 @@ var sendServerToServerRequest_1 = __importDefault(require("./sendServerToServerR
|
|
|
55
55
|
* @param opts.host the host of the other server
|
|
56
56
|
* @param [opts.params={}] query/body parameters to include
|
|
57
57
|
* @param [opts.responseType=JSON] the response type from the other server
|
|
58
|
+
* @param [opts.dceKitCrossServerCredentials] additional cross-server credentials
|
|
59
|
+
* that aren't in the env var list
|
|
60
|
+
* @returns the body of the response from the other server
|
|
58
61
|
*/
|
|
59
62
|
var visitEndpointOnAnotherServer = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
63
|
var response, body;
|
|
@@ -66,6 +69,7 @@ var visitEndpointOnAnotherServer = function (opts) { return __awaiter(void 0, vo
|
|
|
66
69
|
method: opts.method,
|
|
67
70
|
params: opts.params,
|
|
68
71
|
responseType: opts.responseType,
|
|
72
|
+
dceKitCrossServerCredentials: opts.dceKitCrossServerCredentials,
|
|
69
73
|
})];
|
|
70
74
|
case 1:
|
|
71
75
|
response = _a.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/visitEndpointOnAnotherServer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAuB;AACvB,+CAGuB;AAEvB,sBAAsB;AACtB,0FAAoE;AAEpE,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/visitEndpointOnAnotherServer/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAuB;AACvB,+CAGuB;AAEvB,sBAAsB;AACtB,0FAAoE;AAEpE,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;;;;;;;;;;GAYG;AACH,IAAM,4BAA4B,GAAG,UACnC,IAOC;;;;oBAGgB,qBAAM,IAAA,mCAAyB,EAAC;oBAC/C,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,YAAY,EAAE,IAAI,CAAC,YAAY;oBAC/B,4BAA4B,EAAE,IAAI,CAAC,4BAA4B;iBAChE,CAAC,EAAA;;gBAPI,QAAQ,GAAG,SAOf;gBAEF,oBAAoB;gBACpB,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;oBAChC,MAAM,IAAI,6BAAa,CACrB,uGAAuG,EACvG,kCAAkB,CAAC,UAAU,CAC9B,CAAC;gBACJ,CAAC;gBACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;oBAC3B,eAAe;oBACf,MAAM,IAAI,6BAAa,CACrB,CACE,QAAQ,CAAC,IAAI,CAAC,OAAO;2BAClB,qDAAqD,CACzD,EACD,CACE,QAAQ,CAAC,IAAI,CAAC,IAAI;2BACf,kCAAkB,CAAC,MAAM,CAC7B,CACF,CAAC;gBACJ,CAAC;gBAGO,IAAI,GAAK,QAAQ,CAAC,IAAI,KAAlB,CAAmB;gBAE/B,SAAS;gBACT,sBAAO,IAAI,EAAC;;;KACb,CAAC;AAEF,kBAAe,4BAA4B,CAAC"}
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* @param [opts.method=GET] http method to use
|
|
8
8
|
* @param [opts.params] body/data to include in the request
|
|
9
9
|
* @param [opts.responseType=JSON] expected response type
|
|
10
|
+
* @param [opts.dceKitCrossServerCredentials] additional cross-server credentials
|
|
11
|
+
* that aren't in the env var list
|
|
10
12
|
* @returns { body, status, headers } on success
|
|
11
13
|
*/
|
|
12
14
|
declare const sendServerToServerRequest: (opts: {
|
|
@@ -15,6 +17,7 @@ declare const sendServerToServerRequest: (opts: {
|
|
|
15
17
|
method?: ("GET" | "POST" | "PUT" | "DELETE");
|
|
16
18
|
params?: { [k in string]: any; };
|
|
17
19
|
responseType?: "Text" | "JSON";
|
|
20
|
+
dceKitCrossServerCredentials?: string;
|
|
18
21
|
}) => Promise<{
|
|
19
22
|
body: any;
|
|
20
23
|
status: number;
|
|
@@ -55,30 +55,44 @@ var ExpressKitErrorCode_1 = __importDefault(require("../../types/ExpressKitError
|
|
|
55
55
|
DCEKIT_CROSS_SERVER_CREDENTIALS format:
|
|
56
56
|
|host:key:secret||host:key:secret|...
|
|
57
57
|
*/
|
|
58
|
-
var credentials =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
58
|
+
var credentials = [];
|
|
59
|
+
/*------------------------------------------------------------------------*/
|
|
60
|
+
/* ------------------------------- Helpers ------------------------------ */
|
|
61
|
+
/*------------------------------------------------------------------------*/
|
|
62
|
+
/**
|
|
63
|
+
* Parse a credentials string into an array of credentials
|
|
64
|
+
* @author Gabe Abrams
|
|
65
|
+
* @param credentialsStr the credentials string to parse
|
|
66
|
+
* @returns an array of credentials
|
|
67
|
+
*/
|
|
68
|
+
var parseCredentials = function (credentialsStr) {
|
|
69
|
+
credentialsStr
|
|
70
|
+
// Replace multiple | with a single one
|
|
71
|
+
.replace(/\|+/g, '|')
|
|
72
|
+
// Split by |
|
|
73
|
+
.split('|')
|
|
74
|
+
// Remove empty strings
|
|
75
|
+
.filter(function (str) {
|
|
76
|
+
return str.trim().length > 0;
|
|
77
|
+
})
|
|
78
|
+
// Process each credential
|
|
79
|
+
.forEach(function (str) {
|
|
80
|
+
// Split by :
|
|
81
|
+
var parts = str.split(':');
|
|
82
|
+
// Check for errors
|
|
83
|
+
if (parts.length !== 3) {
|
|
84
|
+
throw new dce_commonkit_1.ErrorWithCode('Invalid DCEKIT_CROSS_SERVER_CREDENTIALS format. Each credential must be in the format |host:key:secret|', ExpressKitErrorCode_1.default.InvalidCrossServerCredentialsFormat);
|
|
85
|
+
}
|
|
86
|
+
// Add the credential to the array
|
|
87
|
+
credentials.push({
|
|
88
|
+
host: parts[0].trim(),
|
|
89
|
+
key: parts[1].trim(),
|
|
90
|
+
secret: parts[2].trim(),
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
// Auto-parse credentials from env variable
|
|
95
|
+
parseCredentials((_a = process.env.DCEKIT_CROSS_SERVER_CREDENTIALS) !== null && _a !== void 0 ? _a : '');
|
|
82
96
|
/*------------------------------------------------------------------------*/
|
|
83
97
|
/* ------------------------------- Helpers ------------------------------ */
|
|
84
98
|
/*------------------------------------------------------------------------*/
|
|
@@ -111,6 +125,8 @@ var getCrossServerCredential = function (host) {
|
|
|
111
125
|
* @param [opts.method=GET] http method to use
|
|
112
126
|
* @param [opts.params] body/data to include in the request
|
|
113
127
|
* @param [opts.responseType=JSON] expected response type
|
|
128
|
+
* @param [opts.dceKitCrossServerCredentials] additional cross-server credentials
|
|
129
|
+
* that aren't in the env var list
|
|
114
130
|
* @returns { body, status, headers } on success
|
|
115
131
|
*/
|
|
116
132
|
var sendServerToServerRequest = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -119,6 +135,10 @@ var sendServerToServerRequest = function (opts) { return __awaiter(void 0, void
|
|
|
119
135
|
return __generator(this, function (_b) {
|
|
120
136
|
switch (_b.label) {
|
|
121
137
|
case 0:
|
|
138
|
+
// If additional credentials were provided, parse them and add to the list
|
|
139
|
+
if (opts.dceKitCrossServerCredentials) {
|
|
140
|
+
parseCredentials(opts.dceKitCrossServerCredentials);
|
|
141
|
+
}
|
|
122
142
|
method = (opts.method || 'GET');
|
|
123
143
|
if (opts.params) {
|
|
124
144
|
params = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendServerToServerRequest.js","sourceRoot":"","sources":["../../../src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAc;AACd,0CAAoB;AAEpB,uBAAuB;AACvB,+CAEuB;AAEvB,qBAAqB;AACrB,4CAA4C;AAE5C,sBAAsB;AACtB,wFAAkE;AAElE,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;EAGE;AAEF,IAAM,WAAW,GAIX,
|
|
1
|
+
{"version":3,"file":"sendServerToServerRequest.js","sourceRoot":"","sources":["../../../src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAc;AACd,0CAAoB;AAEpB,uBAAuB;AACvB,+CAEuB;AAEvB,qBAAqB;AACrB,4CAA4C;AAE5C,sBAAsB;AACtB,wFAAkE;AAElE,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;EAGE;AAEF,IAAM,WAAW,GAIX,EAAE,CAAC;AAET,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;;;GAKG;AACH,IAAM,gBAAgB,GAAG,UAAC,cAAsB;IAC9C,cAAc;QACZ,uCAAuC;SACtC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;QACrB,aAAa;SACZ,KAAK,CAAC,GAAG,CAAC;QACX,uBAAuB;SACtB,MAAM,CAAC,UAAC,GAAG;QACV,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,CAAC,CAAC;QACF,0BAA0B;SACzB,OAAO,CAAC,UAAC,GAAG;QACX,aAAa;QACb,IAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE7B,mBAAmB;QACnB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,6BAAa,CACrB,yGAAyG,EACzG,6BAAmB,CAAC,mCAAmC,CACxD,CAA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C,GAAG,KAAK,CAAC;gBAC/B,CAAC,CAAC,CAAC;;;;gBAKG,YAAY,SAAK,CAAC;qBAEpB,CAAA,IAAI,CAAC,YAAY;uBACd,IAAI,CAAC,YAAY,KAAK,MAAM,CAAA,EAD/B,wBAC+B;gBAGhB,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;gBADpC,wBAAwB;gBACxB,YAAY,GAAG,SAAqB,CAAC;;oBAGtB,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;gBADpC,wBAAwB;gBACxB,YAAY,GAAG,SAAqB,CAAC;;;YAGvC,kBAAkB;YAClB,sBAAO;oBACL,IAAI,EAAE,YAAY;oBAClB,MAAM,EAAE,QAAQ,CAAC,MAAM;oBACvB,OAAO,EAAE,iBAAe;iBACzB,EAAC;;;gBAEF,MAAM,IAAI,6BAAa,CACrB,sCAA+B,IAAI,CAAC,YAAY,eAAM,KAAW,aAAX,KAAG,uBAAH,KAAG,CAAU,OAAO,CAAE,EAC5E,6BAAmB,CAAC,kBAAkB,CACvC,CAAC;;;;gBAGJ,iCAAiC;gBACjC,IAAI,MAAC,KAAW,aAAX,KAAG,uBAAH,KAAG,CAAU,OAAO,0CAAE,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAAC;oBAC/D,MAAM,IAAI,6BAAa,CACrB,iFAAiF,EACjF,6BAAmB,CAAC,UAAU,CAC/B,CAAC;gBACJ,CAAC;gBAED,gBAAgB;gBAChB,MAAM,IAAI,6BAAa,CACrB,0HAAoH,KAAW,aAAX,KAAG,uBAAH,KAAG,CAAU,OAAO,CAAE,EAC1I,6BAAmB,CAAC,YAAY,CACjC,CAAC;;;;KAEL,CAAC;AAEF,kBAAe,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -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,6 +41,7 @@ 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
|
|
@@ -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
|
|