@fnd-platform/api 1.0.0-alpha.2 → 1.0.0-alpha.3
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 +13 -11
- package/LICENSE +0 -21
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,18 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fnd-platform/api",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
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",
|
|
7
7
|
"files": [
|
|
8
8
|
"lib/"
|
|
9
9
|
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"test:watch": "vitest",
|
|
14
|
+
"test:coverage": "vitest run --coverage",
|
|
15
|
+
"lint": "eslint src/ test/"
|
|
16
|
+
},
|
|
10
17
|
"dependencies": {
|
|
18
|
+
"@aws-sdk/client-dynamodb": "^3.500.0",
|
|
11
19
|
"@aws-sdk/client-s3": "^3.500.0",
|
|
20
|
+
"@aws-sdk/lib-dynamodb": "^3.500.0",
|
|
12
21
|
"@aws-sdk/s3-request-presigner": "^3.500.0",
|
|
22
|
+
"@fnd-platform/core": "workspace:*",
|
|
13
23
|
"projen": "^0.91.0",
|
|
14
|
-
"zod": "^3.22.0"
|
|
15
|
-
"@fnd-platform/core": "1.0.0-alpha.2"
|
|
24
|
+
"zod": "^3.22.0"
|
|
16
25
|
},
|
|
17
26
|
"peerDependencies": {
|
|
18
27
|
"projen": "^0.91.0"
|
|
@@ -43,12 +52,5 @@
|
|
|
43
52
|
"type": "git",
|
|
44
53
|
"url": "https://github.com/your-org/fnd-platform",
|
|
45
54
|
"directory": "packages/api"
|
|
46
|
-
},
|
|
47
|
-
"scripts": {
|
|
48
|
-
"build": "tsc",
|
|
49
|
-
"test": "vitest run",
|
|
50
|
-
"test:watch": "vitest",
|
|
51
|
-
"test:coverage": "vitest run --coverage",
|
|
52
|
-
"lint": "eslint src/ test/"
|
|
53
55
|
}
|
|
54
|
-
}
|
|
56
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 fnd-platform contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|