diff --git a/cloudfront/index.js b/cloudfront/index.js index be05df1..0a9cecf 100644 --- a/cloudfront/index.js +++ b/cloudfront/index.js @@ -10,6 +10,7 @@ /** * @typedef {import("aws-lambda").CloudFrontFunctionsEvent} CloudFrontFunctionsEvent * @typedef {import("aws-lambda").CloudFrontFunctionsQuerystring} CloudFrontFunctionsQuerystring + * @typedef {import("aws-lambda").CloudFrontFunctionsEvent.request} CloudFrontFunctionsRequest */ /** @@ -17,7 +18,7 @@ * ie. POST request with query string "?/action" * CloudFront does not allow query string with "/". It needs to be encoded. * @param {CloudFrontFunctionsEvent} event - Cloudfront functions event - * @returns {any} - Cloudfront function event request + * @returns {CloudFrontFunctionsRequest} - Cloudfront function event request */ function handler(event) { var request = event.request; diff --git a/handler/binary.js b/handler/binary.js index 5b88b6b..e80117d 100644 --- a/handler/binary.js +++ b/handler/binary.js @@ -64,7 +64,7 @@ const commonBinaryMimeTypes = new Set([ /** * Determines if the given content type is a binary type. - * @param {string|null} contentType - The MIME type to check. + * @param {string | null} contentType - The MIME type to check. * @returns {boolean} - Returns true if the content type is a binary type, false otherwise. */ export function isBinaryContentType(contentType = null) { diff --git a/handler/event-mapper.js b/handler/event-mapper.js index 8e787fe..3c9637e 100644 --- a/handler/event-mapper.js +++ b/handler/event-mapper.js @@ -15,7 +15,7 @@ import { debug } from './logger.js'; /** * Represents an internal event type. * @typedef {object} InternalEvent - * @property {"v1"|"v2"|"cf"} type The type of the event. + * @property {"v1" | "v2" | "cf"} type The type of the event. * @property {string} method HTTP method used in the event. * @property {string} rawPath The raw path accessed in the event. * @property {string} url The full URL accessed in the event. @@ -27,7 +27,7 @@ import { debug } from './logger.js'; /** * Represents an internal result format. * @typedef {object} InternalResult - * @property {"v1"|"v2"|"cf"} type The type of the result. + * @property {"v1" | "v2" | "cf"} type The type of the result. * @property {number} statusCode HTTP status code. * @property {Record} headers Headers to send in the response. * @property {string} body The response body as a string. @@ -36,7 +36,7 @@ import { debug } from './logger.js'; /** * Checks if the event is an API Gateway V2 event. - * @param {any} event The event to check. + * @param {APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent} event The event to check. * @returns {event is APIGatewayProxyEventV2} True if it's an API Gateway V2 event. */ export function isAPIGatewayProxyEventV2(event) { @@ -45,7 +45,7 @@ export function isAPIGatewayProxyEventV2(event) { /** * Checks if the event is an API Gateway V1 event. - * @param {any} event The event to check. + * @param {APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent} event The event to check. * @returns {event is APIGatewayProxyEvent} True if it's an API Gateway V1 event. */ export function isAPIGatewayProxyEvent(event) { @@ -54,7 +54,7 @@ export function isAPIGatewayProxyEvent(event) { /** * Checks if the event is a CloudFront request event. - * @param {any} event The event to check. + * @param {APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent} event The event to check. * @returns {event is CloudFrontRequestEvent} True if it's a CloudFront request event. */ export function isCloudFrontRequestEvent(event) { @@ -63,7 +63,7 @@ export function isCloudFrontRequestEvent(event) { /** * Converts an API Gateway or CloudFront event to an internal event format. - * @param {APIGatewayProxyEventV2|APIGatewayProxyEvent|CloudFrontRequestEvent} event The event to convert. + * @param {APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent} event The event to convert. * @returns {InternalEvent} The internal event. */ export function convertFrom(event) { @@ -80,7 +80,7 @@ export function convertFrom(event) { /** * Converts an internal result to a corresponding AWS API Gateway or CloudFront result. * @param {InternalResult} result The internal result to convert. - * @returns {APIGatewayProxyResultV2|APIGatewayProxyResult|CloudFrontRequestResult} The API Gateway or CloudFront result. + * @returns {APIGatewayProxyResultV2 | APIGatewayProxyResult | CloudFrontRequestResult} The API Gateway or CloudFront result. */ export function convertTo(result) { if (result.type === 'v2') { diff --git a/handler/index.js b/handler/index.js index 4b80cb3..2b6aaad 100644 --- a/handler/index.js +++ b/handler/index.js @@ -38,8 +38,8 @@ app.init({ env: /** @type {Record} */ (process.env) }); /** * Handles incoming requests from AWS API Gateway or CloudFront and responds appropriately. - * @param {APIGatewayProxyEventV2 | CloudFrontRequestEvent | APIGatewayProxyEvent} event - The incoming event from AWS Lambda. - * @returns {Promise} The response to be returned to AWS Lambda. + * @param {APIGatewayProxyEvent | APIGatewayProxyEventV2 | CloudFrontRequestEvent} event - The incoming event from AWS Lambda. + * @returns {Promise} - The response to be returned to AWS Lambda. */ export async function handler(event) { debug('event', event); @@ -106,16 +106,19 @@ export async function handler(event) { body }); } - return { + + /** @type {CloudFrontRequestResult} */ + const notFoundResp = { statusCode: 404, body: 'Not found.' }; + return notFoundResp; } /** * Checks if the URI corresponds to a prerendered file. * @param {string} uri - The URI to check. - * @returns {string|undefined} The filepath if it is a prerendered file, otherwise undefined. + * @returns {string | undefined} The filepath if it is a prerendered file, otherwise undefined. */ function isPrerenderedFile(uri) { // remove leading and trailing slashes diff --git a/handler/logger.js b/handler/logger.js index 4458c46..f8a7e42 100644 --- a/handler/logger.js +++ b/handler/logger.js @@ -3,6 +3,7 @@ /** * Logs debug information to the console if the DEBUG environment variable is set. * @param {...any} args - Arguments to be logged. + * @returns {void} */ export function debug(...args) { if (process.env.DEBUG) { diff --git a/index.js b/index.js index 045b58d..30deb7a 100644 --- a/index.js +++ b/index.js @@ -55,6 +55,7 @@ export default function (options = {}) { /** * Adapts the project for deployment. * @param {Builder} builder - The builder instance from SvelteKit + * @returns {Promise} */ async adapt(builder) { const tmp = path.join('.svelte-kit', name); diff --git a/jsr.json b/jsr.json index 2dd351b..60fda2c 100644 --- a/jsr.json +++ b/jsr.json @@ -1,5 +1,5 @@ { "name": "@hearchco/sveltekit-adapter-aws", - "version": "0.1.11", + "version": "0.1.12", "exports": "./index.js" } diff --git a/package.json b/package.json index 82ae064..558f0bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hearchco/sveltekit-adapter-aws", - "version": "0.1.11", + "version": "0.1.12", "description": "SvelteKit AWS universal adapter for creating necessary assets and code which can later be deployed using a custom IaC pipeline", "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json index 917bc74..6ff072a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,11 @@ { "compilerOptions": { - "allowJs": true, - "checkJs": true, + // "allowJs": true, + // "checkJs": true, "strict": true, "declaration": true, "emitDeclarationOnly": true, + "isolatedDeclarations": true, "outDir": ".", "noImplicitAny": true, "target": "ES2022",