@commercetools-backend/express 21.0.0 → 21.3.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/README.md +1 -1
- package/dist/commercetools-backend-express.cjs.dev.js +14 -7
- package/dist/commercetools-backend-express.cjs.prod.js +14 -7
- package/dist/commercetools-backend-express.esm.js +14 -7
- package/dist/declarations/src/auth.d.ts +3 -5
- package/dist/declarations/src/middlewares/session-middleware.d.ts +3 -3
- package/dist/declarations/src/types.d.ts +7 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ app.use((request, response, next) => {
|
|
|
41
41
|
|
|
42
42
|
- `audience` (_string_): The public-facing URL of your API server. The value should only contain the origin URL (protocol, hostname, port), the request path is inferred from the incoming request.
|
|
43
43
|
|
|
44
|
-
- `issuer` (_string_): Either a cloud identifier or a valid URL to the Merchant Center API Gateway. The cloud identifier maps to the Merchant Center API URL of the related [cloud region](https://docs.commercetools.com/custom-applications/
|
|
44
|
+
- `issuer` (_string_): Either a cloud identifier or a valid URL to the Merchant Center API Gateway. The cloud identifier maps to the Merchant Center API URL of the related [cloud region](https://docs.commercetools.com/custom-applications/concepts/merchant-center-api#cloud-regions).
|
|
45
45
|
|
|
46
46
|
- `gcp-au`: `https://mc-api.australia-southeast1.gcp.commercetools.com`
|
|
47
47
|
- `gcp-eu`: `https://mc-api.europe-west1.gcp.commercetools.com`
|
|
@@ -86,7 +86,7 @@ var writeSessionContext = function writeSessionContext(request) {
|
|
|
86
86
|
}; // Given a cloud identifier, try to map it to one of the supported
|
|
87
87
|
// environments and return the MC API URL for that environment.
|
|
88
88
|
// The URL points to the new hostnames.
|
|
89
|
-
// https://docs.commercetools.com/custom-applications/
|
|
89
|
+
// https://docs.commercetools.com/custom-applications/concepts/merchant-center-api#hostnames
|
|
90
90
|
|
|
91
91
|
|
|
92
92
|
var mapCloudIdentifierToIssuer = function mapCloudIdentifierToIssuer(issuer) {
|
|
@@ -111,7 +111,6 @@ var mapCloudIdentifierToIssuer = function mapCloudIdentifierToIssuer(issuer) {
|
|
|
111
111
|
}
|
|
112
112
|
}; // Given a cloud identifier, try to map it to a legacy hostname.
|
|
113
113
|
// This is for backwards compatibility.
|
|
114
|
-
// https://docs.commercetools.com/custom-applications/main-concepts/api-gateway#legacy-hostnames
|
|
115
114
|
|
|
116
115
|
|
|
117
116
|
var mapToLegacyIssuer = function mapToLegacyIssuer(cloudIdentifier) {
|
|
@@ -132,7 +131,7 @@ var throwIfIssuerIsNotAValidUrl = function throwIfIssuerIsNotAValidUrl(issuer) {
|
|
|
132
131
|
try {
|
|
133
132
|
new _URL__default["default"](issuer);
|
|
134
133
|
} catch (error) {
|
|
135
|
-
throw new Error("Invalid issuer URL \"".concat(issuer, "\". Expected a valid URL to the Merchant Center API Gateway, or a cloud identifier to one of the available cloud regions. See https://docs.commercetools.com/custom-applications/
|
|
134
|
+
throw new Error("Invalid issuer URL \"".concat(issuer, "\". Expected a valid URL to the Merchant Center API Gateway, or a cloud identifier to one of the available cloud regions. See https://docs.commercetools.com/custom-applications/concepts/merchant-center-api#hostnames."));
|
|
136
135
|
}
|
|
137
136
|
}; // Validates required option values.
|
|
138
137
|
|
|
@@ -200,10 +199,18 @@ function createSessionAuthVerifier(options) {
|
|
|
200
199
|
if (proxyForwardVersion === 'v1') {
|
|
201
200
|
// Fall back to legacy issuer domains
|
|
202
201
|
issuer = (_mapToLegacyIssuer = mapToLegacyIssuer(cloudIdentifierHeader)) !== null && _mapToLegacyIssuer !== void 0 ? _mapToLegacyIssuer : issuer;
|
|
203
|
-
}
|
|
202
|
+
}
|
|
204
203
|
|
|
204
|
+
requestUrlPath = options.getRequestUrl ? options.getRequestUrl(request) : (_request$originalUrl = request.originalUrl) !== null && _request$originalUrl !== void 0 ? _request$originalUrl : request.url;
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
if (requestUrlPath) {
|
|
207
|
+
_context3.next = 7;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
throw new Error('Invalid request URI path. Please make sure that the `request` object has either a property `originalUrl` or `url`. If not, you should implement the `getRequestUrl` function. More info at https://docs.commercetools.com/custom-applications/concepts/integrate-with-your-own-api#validating-the-json-web-token');
|
|
212
|
+
|
|
213
|
+
case 7:
|
|
207
214
|
audience = getConfiguredAudience(options, requestUrlPath);
|
|
208
215
|
return _context3.abrupt("return", new _Promise__default["default"](function (resolve, reject) {
|
|
209
216
|
expressJwtMiddleware__default["default"]({
|
|
@@ -224,7 +231,7 @@ function createSessionAuthVerifier(options) {
|
|
|
224
231
|
issuer: issuer,
|
|
225
232
|
algorithms: ['RS256'] // @ts-ignore: the middleware expects an Express.js Request/Response objects
|
|
226
233
|
|
|
227
|
-
})(request, response, function (error) {
|
|
234
|
+
})(request, response !== null && response !== void 0 ? response : {}, function (error) {
|
|
228
235
|
if (error) {
|
|
229
236
|
reject(error);
|
|
230
237
|
} else {
|
|
@@ -236,7 +243,7 @@ function createSessionAuthVerifier(options) {
|
|
|
236
243
|
});
|
|
237
244
|
}));
|
|
238
245
|
|
|
239
|
-
case
|
|
246
|
+
case 9:
|
|
240
247
|
case "end":
|
|
241
248
|
return _context3.stop();
|
|
242
249
|
}
|
|
@@ -86,7 +86,7 @@ var writeSessionContext = function writeSessionContext(request) {
|
|
|
86
86
|
}; // Given a cloud identifier, try to map it to one of the supported
|
|
87
87
|
// environments and return the MC API URL for that environment.
|
|
88
88
|
// The URL points to the new hostnames.
|
|
89
|
-
// https://docs.commercetools.com/custom-applications/
|
|
89
|
+
// https://docs.commercetools.com/custom-applications/concepts/merchant-center-api#hostnames
|
|
90
90
|
|
|
91
91
|
|
|
92
92
|
var mapCloudIdentifierToIssuer = function mapCloudIdentifierToIssuer(issuer) {
|
|
@@ -111,7 +111,6 @@ var mapCloudIdentifierToIssuer = function mapCloudIdentifierToIssuer(issuer) {
|
|
|
111
111
|
}
|
|
112
112
|
}; // Given a cloud identifier, try to map it to a legacy hostname.
|
|
113
113
|
// This is for backwards compatibility.
|
|
114
|
-
// https://docs.commercetools.com/custom-applications/main-concepts/api-gateway#legacy-hostnames
|
|
115
114
|
|
|
116
115
|
|
|
117
116
|
var mapToLegacyIssuer = function mapToLegacyIssuer(cloudIdentifier) {
|
|
@@ -132,7 +131,7 @@ var throwIfIssuerIsNotAValidUrl = function throwIfIssuerIsNotAValidUrl(issuer) {
|
|
|
132
131
|
try {
|
|
133
132
|
new _URL__default["default"](issuer);
|
|
134
133
|
} catch (error) {
|
|
135
|
-
throw new Error("Invalid issuer URL \"".concat(issuer, "\". Expected a valid URL to the Merchant Center API Gateway, or a cloud identifier to one of the available cloud regions. See https://docs.commercetools.com/custom-applications/
|
|
134
|
+
throw new Error("Invalid issuer URL \"".concat(issuer, "\". Expected a valid URL to the Merchant Center API Gateway, or a cloud identifier to one of the available cloud regions. See https://docs.commercetools.com/custom-applications/concepts/merchant-center-api#hostnames."));
|
|
136
135
|
}
|
|
137
136
|
}; // Validates required option values.
|
|
138
137
|
|
|
@@ -200,10 +199,18 @@ function createSessionAuthVerifier(options) {
|
|
|
200
199
|
if (proxyForwardVersion === 'v1') {
|
|
201
200
|
// Fall back to legacy issuer domains
|
|
202
201
|
issuer = (_mapToLegacyIssuer = mapToLegacyIssuer(cloudIdentifierHeader)) !== null && _mapToLegacyIssuer !== void 0 ? _mapToLegacyIssuer : issuer;
|
|
203
|
-
}
|
|
202
|
+
}
|
|
204
203
|
|
|
204
|
+
requestUrlPath = options.getRequestUrl ? options.getRequestUrl(request) : (_request$originalUrl = request.originalUrl) !== null && _request$originalUrl !== void 0 ? _request$originalUrl : request.url;
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
if (requestUrlPath) {
|
|
207
|
+
_context3.next = 7;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
throw new Error('Invalid request URI path. Please make sure that the `request` object has either a property `originalUrl` or `url`. If not, you should implement the `getRequestUrl` function. More info at https://docs.commercetools.com/custom-applications/concepts/integrate-with-your-own-api#validating-the-json-web-token');
|
|
212
|
+
|
|
213
|
+
case 7:
|
|
207
214
|
audience = getConfiguredAudience(options, requestUrlPath);
|
|
208
215
|
return _context3.abrupt("return", new _Promise__default["default"](function (resolve, reject) {
|
|
209
216
|
expressJwtMiddleware__default["default"]({
|
|
@@ -224,7 +231,7 @@ function createSessionAuthVerifier(options) {
|
|
|
224
231
|
issuer: issuer,
|
|
225
232
|
algorithms: ['RS256'] // @ts-ignore: the middleware expects an Express.js Request/Response objects
|
|
226
233
|
|
|
227
|
-
})(request, response, function (error) {
|
|
234
|
+
})(request, response !== null && response !== void 0 ? response : {}, function (error) {
|
|
228
235
|
if (error) {
|
|
229
236
|
reject(error);
|
|
230
237
|
} else {
|
|
@@ -236,7 +243,7 @@ function createSessionAuthVerifier(options) {
|
|
|
236
243
|
});
|
|
237
244
|
}));
|
|
238
245
|
|
|
239
|
-
case
|
|
246
|
+
case 9:
|
|
240
247
|
case "end":
|
|
241
248
|
return _context3.stop();
|
|
242
249
|
}
|
|
@@ -64,7 +64,7 @@ var writeSessionContext = function writeSessionContext(request) {
|
|
|
64
64
|
}; // Given a cloud identifier, try to map it to one of the supported
|
|
65
65
|
// environments and return the MC API URL for that environment.
|
|
66
66
|
// The URL points to the new hostnames.
|
|
67
|
-
// https://docs.commercetools.com/custom-applications/
|
|
67
|
+
// https://docs.commercetools.com/custom-applications/concepts/merchant-center-api#hostnames
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
var mapCloudIdentifierToIssuer = function mapCloudIdentifierToIssuer(issuer) {
|
|
@@ -89,7 +89,6 @@ var mapCloudIdentifierToIssuer = function mapCloudIdentifierToIssuer(issuer) {
|
|
|
89
89
|
}
|
|
90
90
|
}; // Given a cloud identifier, try to map it to a legacy hostname.
|
|
91
91
|
// This is for backwards compatibility.
|
|
92
|
-
// https://docs.commercetools.com/custom-applications/main-concepts/api-gateway#legacy-hostnames
|
|
93
92
|
|
|
94
93
|
|
|
95
94
|
var mapToLegacyIssuer = function mapToLegacyIssuer(cloudIdentifier) {
|
|
@@ -110,7 +109,7 @@ var throwIfIssuerIsNotAValidUrl = function throwIfIssuerIsNotAValidUrl(issuer) {
|
|
|
110
109
|
try {
|
|
111
110
|
new _URL(issuer);
|
|
112
111
|
} catch (error) {
|
|
113
|
-
throw new Error("Invalid issuer URL \"".concat(issuer, "\". Expected a valid URL to the Merchant Center API Gateway, or a cloud identifier to one of the available cloud regions. See https://docs.commercetools.com/custom-applications/
|
|
112
|
+
throw new Error("Invalid issuer URL \"".concat(issuer, "\". Expected a valid URL to the Merchant Center API Gateway, or a cloud identifier to one of the available cloud regions. See https://docs.commercetools.com/custom-applications/concepts/merchant-center-api#hostnames."));
|
|
114
113
|
}
|
|
115
114
|
}; // Validates required option values.
|
|
116
115
|
|
|
@@ -178,10 +177,18 @@ function createSessionAuthVerifier(options) {
|
|
|
178
177
|
if (proxyForwardVersion === 'v1') {
|
|
179
178
|
// Fall back to legacy issuer domains
|
|
180
179
|
issuer = (_mapToLegacyIssuer = mapToLegacyIssuer(cloudIdentifierHeader)) !== null && _mapToLegacyIssuer !== void 0 ? _mapToLegacyIssuer : issuer;
|
|
181
|
-
}
|
|
180
|
+
}
|
|
182
181
|
|
|
182
|
+
requestUrlPath = options.getRequestUrl ? options.getRequestUrl(request) : (_request$originalUrl = request.originalUrl) !== null && _request$originalUrl !== void 0 ? _request$originalUrl : request.url;
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
if (requestUrlPath) {
|
|
185
|
+
_context3.next = 7;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
throw new Error('Invalid request URI path. Please make sure that the `request` object has either a property `originalUrl` or `url`. If not, you should implement the `getRequestUrl` function. More info at https://docs.commercetools.com/custom-applications/concepts/integrate-with-your-own-api#validating-the-json-web-token');
|
|
190
|
+
|
|
191
|
+
case 7:
|
|
185
192
|
audience = getConfiguredAudience(options, requestUrlPath);
|
|
186
193
|
return _context3.abrupt("return", new _Promise(function (resolve, reject) {
|
|
187
194
|
expressJwtMiddleware({
|
|
@@ -202,7 +209,7 @@ function createSessionAuthVerifier(options) {
|
|
|
202
209
|
issuer: issuer,
|
|
203
210
|
algorithms: ['RS256'] // @ts-ignore: the middleware expects an Express.js Request/Response objects
|
|
204
211
|
|
|
205
|
-
})(request, response, function (error) {
|
|
212
|
+
})(request, response !== null && response !== void 0 ? response : {}, function (error) {
|
|
206
213
|
if (error) {
|
|
207
214
|
reject(error);
|
|
208
215
|
} else {
|
|
@@ -214,7 +221,7 @@ function createSessionAuthVerifier(options) {
|
|
|
214
221
|
});
|
|
215
222
|
}));
|
|
216
223
|
|
|
217
|
-
case
|
|
224
|
+
case 9:
|
|
218
225
|
case "end":
|
|
219
226
|
return _context3.stop();
|
|
220
227
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const getConfiguredAudience: (options: TSessionMiddlewareOptions, requestPath: string) => string;
|
|
5
|
-
declare function createSessionAuthVerifier<Request extends IncomingMessage, Response extends ServerResponse>(options: TSessionMiddlewareOptions): (request: Request, response: Response) => Promise<void>;
|
|
1
|
+
import type { TSessionMiddlewareOptions, TBaseRequest } from './types';
|
|
2
|
+
export declare const getConfiguredAudience: <Request_1 extends TBaseRequest>(options: TSessionMiddlewareOptions<Request_1>, requestPath: string) => string;
|
|
3
|
+
declare function createSessionAuthVerifier<Request extends TBaseRequest>(options: TSessionMiddlewareOptions<Request>): (request: Request, response?: unknown) => Promise<void>;
|
|
6
4
|
export { createSessionAuthVerifier };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TSessionMiddlewareOptions } from '../types';
|
|
3
|
-
declare function createSessionMiddleware(options: TSessionMiddlewareOptions): (request: Request, response: Response, next: NextFunction) => Promise<void>;
|
|
1
|
+
import type { Response, NextFunction } from 'express';
|
|
2
|
+
import type { TBaseRequest, TSessionMiddlewareOptions } from '../types';
|
|
3
|
+
declare function createSessionMiddleware<Request extends TBaseRequest>(options: TSessionMiddlewareOptions<Request>): (request: Request, response: Response, next: NextFunction) => Promise<void>;
|
|
4
4
|
export default createSessionMiddleware;
|
|
@@ -3,11 +3,17 @@ import { CLOUD_IDENTIFIERS } from './constants';
|
|
|
3
3
|
export declare type TAudience = string;
|
|
4
4
|
export declare type TIssuer = string;
|
|
5
5
|
export declare type TCloudIdentifier = typeof CLOUD_IDENTIFIERS[keyof typeof CLOUD_IDENTIFIERS];
|
|
6
|
-
export
|
|
6
|
+
export interface TBaseRequest {
|
|
7
|
+
headers: Record<string, string | string[] | undefined>;
|
|
8
|
+
url?: string;
|
|
9
|
+
originalUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare type TSessionMiddlewareOptions<Request extends TBaseRequest> = {
|
|
7
12
|
audience: TAudience;
|
|
8
13
|
issuer: TCloudIdentifier | TIssuer;
|
|
9
14
|
inferIssuer?: boolean;
|
|
10
15
|
jwks?: Omit<ExpressJwtOptions, 'jwksUri'>;
|
|
16
|
+
getRequestUrl?: (request: Request) => string;
|
|
11
17
|
};
|
|
12
18
|
export declare type TSession = {
|
|
13
19
|
userId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-backend/express",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.3.0",
|
|
4
4
|
"description": "Zero-config HTTP server as Express.js to facilitate development",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"module": "dist/commercetools-backend-express.esm.js",
|
|
19
19
|
"files": ["dist", "package.json", "LICENSE", "README.md"],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/runtime": "^7.
|
|
22
|
-
"@babel/runtime-corejs3": "^7.
|
|
23
|
-
"@types/node": "16.11.
|
|
24
|
-
"express": "4.17.
|
|
25
|
-
"express-jwt": "6.1.
|
|
21
|
+
"@babel/runtime": "^7.17.8",
|
|
22
|
+
"@babel/runtime-corejs3": "^7.17.8",
|
|
23
|
+
"@types/node": "16.11.26",
|
|
24
|
+
"express": "4.17.3",
|
|
25
|
+
"express-jwt": "6.1.1",
|
|
26
26
|
"jwks-rsa": "2.0.5"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"jose": "2.0.5",
|
|
30
|
-
"msw": "0.
|
|
30
|
+
"msw": "0.39.2"
|
|
31
31
|
}
|
|
32
32
|
}
|