@fnd-platform/api 1.0.0-alpha.2 → 1.0.0-alpha.4
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/api-project.d.ts +76 -64
- package/lib/api-project.d.ts.map +1 -1
- package/lib/api-project.js +595 -1
- package/lib/api-project.js.map +1 -1
- package/lib/handlers/content.d.ts +25 -9
- package/lib/handlers/content.d.ts.map +1 -1
- package/lib/handlers/content.js +270 -52
- package/lib/handlers/content.js.map +1 -1
- package/lib/handlers/health.js +10 -10
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/lib/errors.js +56 -62
- package/lib/lib/keys.d.ts +122 -0
- package/lib/lib/keys.d.ts.map +1 -0
- package/lib/lib/keys.js +116 -0
- package/lib/lib/keys.js.map +1 -0
- package/lib/middleware/auth.js +25 -25
- package/lib/middleware/cors.js +29 -34
- package/lib/middleware/error-handler.js +22 -21
- package/lib/middleware/index.js +14 -44
- package/lib/middleware/logging.js +26 -30
- package/lib/middleware/validation.js +30 -29
- package/lib/options.js +3 -3
- package/package.json +4 -2
package/lib/middleware/index.js
CHANGED
|
@@ -1,49 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Middleware exports for @fnd-platform/api.
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
*/
|
|
7
|
-
Object.defineProperty(exports,
|
|
8
|
-
exports.withLogging =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
var auth_1 = require('./auth');
|
|
22
|
-
Object.defineProperty(exports, 'withAuth', {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function () {
|
|
25
|
-
return auth_1.withAuth;
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
var validation_1 = require('./validation');
|
|
29
|
-
Object.defineProperty(exports, 'withValidation', {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function () {
|
|
32
|
-
return validation_1.withValidation;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
var cors_1 = require('./cors');
|
|
36
|
-
Object.defineProperty(exports, 'withCors', {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return cors_1.withCors;
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
var logging_1 = require('./logging');
|
|
43
|
-
Object.defineProperty(exports, 'withLogging', {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return logging_1.withLogging;
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
//# sourceMappingURL=index.js.map
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.withLogging = exports.withCors = exports.withValidation = exports.withAuth = exports.withErrorHandler = void 0;
|
|
9
|
+
var error_handler_1 = require("./error-handler");
|
|
10
|
+
Object.defineProperty(exports, "withErrorHandler", { enumerable: true, get: function () { return error_handler_1.withErrorHandler; } });
|
|
11
|
+
var auth_1 = require("./auth");
|
|
12
|
+
Object.defineProperty(exports, "withAuth", { enumerable: true, get: function () { return auth_1.withAuth; } });
|
|
13
|
+
var validation_1 = require("./validation");
|
|
14
|
+
Object.defineProperty(exports, "withValidation", { enumerable: true, get: function () { return validation_1.withValidation; } });
|
|
15
|
+
var cors_1 = require("./cors");
|
|
16
|
+
Object.defineProperty(exports, "withCors", { enumerable: true, get: function () { return cors_1.withCors; } });
|
|
17
|
+
var logging_1 = require("./logging");
|
|
18
|
+
Object.defineProperty(exports, "withLogging", { enumerable: true, get: function () { return logging_1.withLogging; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Logging middleware for Lambda handlers.
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
*/
|
|
7
|
-
Object.defineProperty(exports,
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.withLogging = withLogging;
|
|
9
9
|
/**
|
|
10
10
|
* Middleware that logs request and response metadata.
|
|
@@ -27,32 +27,28 @@ exports.withLogging = withLogging;
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
function withLogging(options = {}) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return response;
|
|
56
|
-
};
|
|
30
|
+
const { logRequest = true, logResponse = true } = options;
|
|
31
|
+
return (handler) => async (event, context) => {
|
|
32
|
+
const startTime = Date.now();
|
|
33
|
+
const requestId = context.awsRequestId;
|
|
34
|
+
if (logRequest) {
|
|
35
|
+
console.log(JSON.stringify({
|
|
36
|
+
type: 'REQUEST',
|
|
37
|
+
requestId,
|
|
38
|
+
method: event.httpMethod,
|
|
39
|
+
path: event.path,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
const response = await handler(event, context);
|
|
43
|
+
if (logResponse) {
|
|
44
|
+
console.log(JSON.stringify({
|
|
45
|
+
type: 'RESPONSE',
|
|
46
|
+
requestId,
|
|
47
|
+
statusCode: response.statusCode,
|
|
48
|
+
duration: Date.now() - startTime,
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
return response;
|
|
52
|
+
};
|
|
57
53
|
}
|
|
58
|
-
//# sourceMappingURL=logging.js.map
|
|
54
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Request validation middleware for Lambda handlers.
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
*/
|
|
7
|
-
Object.defineProperty(exports,
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.withValidation = withValidation;
|
|
9
|
-
const response_1 = require(
|
|
9
|
+
const response_1 = require("../lib/response");
|
|
10
10
|
/**
|
|
11
11
|
* Format Zod validation errors into a human-readable string.
|
|
12
12
|
*
|
|
@@ -14,12 +14,12 @@ const response_1 = require('../lib/response');
|
|
|
14
14
|
* @returns Formatted error message
|
|
15
15
|
*/
|
|
16
16
|
function formatZodError(error) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
return error.errors
|
|
18
|
+
.map((e) => {
|
|
19
|
+
const path = e.path.length > 0 ? e.path.join('.') : 'body';
|
|
20
|
+
return `${path}: ${e.message}`;
|
|
21
21
|
})
|
|
22
|
-
|
|
22
|
+
.join(', ');
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Middleware that validates request body against a Zod schema.
|
|
@@ -51,26 +51,27 @@ function formatZodError(error) {
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
function withValidation(schema) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
54
|
+
return (handler) => async (event, context) => {
|
|
55
|
+
// Parse body
|
|
56
|
+
let body;
|
|
57
|
+
try {
|
|
58
|
+
body = event.body ? JSON.parse(event.body) : {};
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return (0, response_1.badRequest)('Invalid JSON in request body');
|
|
62
|
+
}
|
|
63
|
+
// Validate against schema
|
|
64
|
+
const result = schema.safeParse(body);
|
|
65
|
+
if (!result.success) {
|
|
66
|
+
const details = formatZodError(result.error);
|
|
67
|
+
return (0, response_1.badRequest)(`Validation failed: ${details}`);
|
|
68
|
+
}
|
|
69
|
+
// Add validated body to event
|
|
70
|
+
const validatedEvent = {
|
|
71
|
+
...event,
|
|
72
|
+
validatedBody: result.data,
|
|
73
|
+
};
|
|
74
|
+
return handler(validatedEvent, context);
|
|
72
75
|
};
|
|
73
|
-
return handler(validatedEvent, context);
|
|
74
|
-
};
|
|
75
76
|
}
|
|
76
|
-
//# sourceMappingURL=validation.js.map
|
|
77
|
+
//# sourceMappingURL=validation.js.map
|
package/lib/options.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
//# sourceMappingURL=options.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=options.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fnd-platform/api",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"description": "Projen project class for generating Lambda API packages in fnd-platform",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
"lib/"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"@aws-sdk/client-dynamodb": "^3.500.0",
|
|
11
12
|
"@aws-sdk/client-s3": "^3.500.0",
|
|
13
|
+
"@aws-sdk/lib-dynamodb": "^3.500.0",
|
|
12
14
|
"@aws-sdk/s3-request-presigner": "^3.500.0",
|
|
13
15
|
"projen": "^0.91.0",
|
|
14
16
|
"zod": "^3.22.0",
|
|
15
|
-
"@fnd-platform/core": "1.0.0-alpha.2"
|
|
17
|
+
"@fnd-platform/core": "^1.0.0-alpha.2"
|
|
16
18
|
},
|
|
17
19
|
"peerDependencies": {
|
|
18
20
|
"projen": "^0.91.0"
|