From b4cf02b8ff7d31445d90c99b8a390ce293473ca6 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Tue, 25 Aug 2020 21:02:28 +0800 Subject: [PATCH 01/13] Added preview mode support. --- .../next-aws-cloudfront.response.test.js | 10 ++++ .../next-aws-cloudfront.js | 1 + .../lambda-at-edge/src/default-handler.ts | 41 ++++++++++++-- .../default-build-manifest.json | 3 +- .../default-handler/default-handler.test.ts | 54 +++++++++++++++++++ .../default-handler/prerender-manifest.json | 5 ++ .../built-artifact/pages/preview.js | 14 +++++ .../libs/lambda-at-edge/tests/test-utils.ts | 7 ++- 8 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 packages/libs/lambda-at-edge/tests/shared-fixtures/built-artifact/pages/preview.js diff --git a/packages/compat-layers/lambda-at-edge-compat/__tests__/next-aws-cloudfront.response.test.js b/packages/compat-layers/lambda-at-edge-compat/__tests__/next-aws-cloudfront.response.test.js index 46d914ba85..bd552e8787 100644 --- a/packages/compat-layers/lambda-at-edge-compat/__tests__/next-aws-cloudfront.response.test.js +++ b/packages/compat-layers/lambda-at-edge-compat/__tests__/next-aws-cloudfront.response.test.js @@ -144,6 +144,16 @@ describe("Response Tests", () => { }); }); + it("writeHead can be chained", () => { + const { res, responsePromise } = create({ + request: { uri: "/", headers: {} } + }); + + res.writeHead(200, { "Content-Length": "1234" }).end(); + + return responsePromise; + }); + it("setHeader (multiple headers with same name)", () => { const { res, responsePromise } = create({ request: { diff --git a/packages/compat-layers/lambda-at-edge-compat/next-aws-cloudfront.js b/packages/compat-layers/lambda-at-edge-compat/next-aws-cloudfront.js index 0e04fa616a..dbacc28b8e 100644 --- a/packages/compat-layers/lambda-at-edge-compat/next-aws-cloudfront.js +++ b/packages/compat-layers/lambda-at-edge-compat/next-aws-cloudfront.js @@ -214,6 +214,7 @@ const handler = (event) => { if (headers) { res.headers = Object.assign(res.headers, headers); } + return res; }; res.write = (chunk) => { if (!response.body) { diff --git a/packages/libs/lambda-at-edge/src/default-handler.ts b/packages/libs/lambda-at-edge/src/default-handler.ts index 3dd1a62705..5505f7f726 100644 --- a/packages/libs/lambda-at-edge/src/default-handler.ts +++ b/packages/libs/lambda-at-edge/src/default-handler.ts @@ -22,6 +22,24 @@ import S3 from "aws-sdk/clients/s3"; import { performance } from "perf_hooks"; import { ServerResponse } from "http"; +const parseCookieValue = (cookie: string) => { + return cookie.split(";").reduce<{ [key: string]: string }>((acc, curr) => { + const [key, value] = curr.split("="); + acc[key.trim()] = value.trim(); + return acc; + }, {}); +}; + +const checkPreviewRequest = (request: CloudFrontRequest) => { + const targetCookie = request.headers.cookie || []; + return targetCookie.some((cookieObj) => { + const cookieValue = parseCookieValue(cookieObj.value); + return ( + cookieValue["__next_preview_data"] && cookieValue["__prerender_bypass"] + ); + }); +}; + const perfLogger = (logLambdaExecutionTimes: boolean): PerfLogger => { if (logLambdaExecutionTimes) { return { @@ -211,11 +229,16 @@ const handleOriginRequest = async ({ const normalisedS3DomainName = normaliseS3OriginDomain(s3Origin); const hasFallback = hasFallbackForUri(uri, prerenderManifest); const { now, log } = perfLogger(manifest.logLambdaExecutionTimes); + const isPreviewRequest = checkPreviewRequest(request); s3Origin.domainName = normalisedS3DomainName; - // Check if we can serve request from S3 - S3Check: if (isHTMLPage || isPublicFile || hasFallback || isDataReq) { + S3Check: if ( + isPublicFile || + (isHTMLPage && !isPreviewRequest) || + (hasFallback && !isPreviewRequest) || + (isDataReq && !isPreviewRequest) + ) { if (isHTMLPage || hasFallback) { s3Origin.path = `${basePath}/static-pages`; const pageName = uri === "/" ? "/index" : uri; @@ -249,7 +272,7 @@ const handleOriginRequest = async ({ const pagePath = router(manifest)(uri); - if (pagePath.endsWith(".html")) { + if (pagePath.endsWith(".html") && !isPreviewRequest) { s3Origin.path = `${basePath}/static-pages`; request.uri = pagePath.replace("pages", ""); addS3HostHeader(request, normalisedS3DomainName); @@ -272,7 +295,17 @@ const handleOriginRequest = async ({ } // Render page - await page.render(req, res); + if (isDataRequest(uri)) { + const { renderOpts } = await page.renderReqToHTML( + req, + res, + "passthrough" + ); + res.setHeader("Content-Type", "application/json"); + res.end(JSON.stringify(renderOpts.pageData)); + } else { + await page.render(req, res); + } } catch (error) { // Set status to 500 so _error.js will render a 500 page console.error( diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-build-manifest.json b/packages/libs/lambda-at-edge/tests/default-handler/default-build-manifest.json index bf1eb90356..6b86ee0adf 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-build-manifest.json +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-build-manifest.json @@ -35,7 +35,8 @@ "/api/getCustomers": "pages/api/getCustomers.js", "/_error": "pages/_error.js", "/erroredPage": "pages/erroredPage.js", - "/404": "pages/404.html" + "/404": "pages/404.html", + "/preview": "pages/preview.js" } }, "html": { diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts index ffe31dd718..4b87d4c08b 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts @@ -186,6 +186,31 @@ describe("Lambda@Edge", () => { expect(response.status).toEqual("200"); }); + + it("handles preview mode", async () => { + const event = createCloudFrontEvent({ + uri: "/preview", + host: "mydistribution.cloudfront.net", + requestHeaders: { + cookie: [ + { + key: "Cookie", + value: "__next_preview_data=abc; __prerender_bypass=def" + } + ] + } + }); + + mockPageRequire("pages/preview.js"); + const result = await handler(event); + const response = result as CloudFrontResultResponse; + const decodedBody = new Buffer( + response.body as string, + "base64" + ).toString("utf8"); + expect(decodedBody).toBe("pages/preview.js"); + expect(response.status).toBe(200); + }); }); describe("Public files routing", () => { @@ -369,6 +394,35 @@ describe("Lambda@Edge", () => { await runRedirectTest(path, expectedRedirect); } ); + + it("handles preview mode", async () => { + const event = createCloudFrontEvent({ + uri: "/_next/data/build-id/preview.json", + host: "mydistribution.cloudfront.net", + requestHeaders: { + cookie: [ + { + key: "Cookie", + value: "__next_preview_data=abc; __prerender_bypass=def" + } + ] + } + }); + + mockPageRequire("/pages/preview.js"); + const result = await handler(event); + const response = result as CloudFrontResultResponse; + const decodedBody = new Buffer( + response.body as string, + "base64" + ).toString("utf8"); + expect(decodedBody).toBe( + JSON.stringify({ + page: "pages/preview.js" + }) + ); + expect(response.status).toBe(200); + }); }); it("uses default s3 endpoint when bucket region is us-east-1", async () => { diff --git a/packages/libs/lambda-at-edge/tests/default-handler/prerender-manifest.json b/packages/libs/lambda-at-edge/tests/default-handler/prerender-manifest.json index 4ada609388..8b20be6def 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/prerender-manifest.json +++ b/packages/libs/lambda-at-edge/tests/default-handler/prerender-manifest.json @@ -5,6 +5,11 @@ "initialRevalidateSeconds": false, "srcRoute": "/tests/prerender-manifest/[staticPageName]", "dataRoute": "/_next/data/test-build-id/tests/prerender-manifest/example-static-page.json" + }, + "/preview": { + "initialRevalidateSeconds": false, + "srcRoute": null, + "dataRoute": "/_next/data/build-id/preview.json" } }, "dynamicRoutes": { diff --git a/packages/libs/lambda-at-edge/tests/shared-fixtures/built-artifact/pages/preview.js b/packages/libs/lambda-at-edge/tests/shared-fixtures/built-artifact/pages/preview.js new file mode 100644 index 0000000000..b5937334d4 --- /dev/null +++ b/packages/libs/lambda-at-edge/tests/shared-fixtures/built-artifact/pages/preview.js @@ -0,0 +1,14 @@ +module.exports = { + render: (req, res) => { + res.end("pages/preview.js"); + }, + renderReqToHTML: (req, res) => { + return { + renderOpts: { + pageData: { + page: "pages/preview.js" + } + } + }; + } +}; diff --git a/packages/libs/lambda-at-edge/tests/test-utils.ts b/packages/libs/lambda-at-edge/tests/test-utils.ts index 941cb4066a..44331a317f 100644 --- a/packages/libs/lambda-at-edge/tests/test-utils.ts +++ b/packages/libs/lambda-at-edge/tests/test-utils.ts @@ -26,6 +26,7 @@ type CloudFrontEventOptions = { config?: CloudFrontEvent["config"]; response?: CloudFrontResponse; querystring?: string; + requestHeaders?: { [name: string]: { key: string; value: string }[] }; }; export const createCloudFrontEvent = ({ @@ -35,7 +36,8 @@ export const createCloudFrontEvent = ({ s3Region, config = {} as any, response, - querystring + querystring, + requestHeaders = {} }: CloudFrontEventOptions): OriginRequestEvent => ({ Records: [ { @@ -52,7 +54,8 @@ export const createCloudFrontEvent = ({ key: "host", value: host } - ] + ], + ...requestHeaders }, origin: { s3: { From b0d997df54082af132800d03d6128248719626b8 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Thu, 27 Aug 2020 09:09:20 +0800 Subject: [PATCH 02/13] Rebased and updated tests. --- ...lt-build-manifest-with-trailing-slash.json | 3 ++- .../default-handler/default-handler.test.ts | 22 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-build-manifest-with-trailing-slash.json b/packages/libs/lambda-at-edge/tests/default-handler/default-build-manifest-with-trailing-slash.json index 07d7b625d6..cbcf0f2b91 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-build-manifest-with-trailing-slash.json +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-build-manifest-with-trailing-slash.json @@ -35,7 +35,8 @@ "/api/getCustomers": "pages/api/getCustomers.js", "/_error": "pages/_error.js", "/erroredPage": "pages/erroredPage.js", - "/404": "pages/404.html" + "/404": "pages/404.html", + "/preview": "pages/preview.js" } }, "html": { diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts index 4b87d4c08b..cf5403ec77 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts @@ -201,15 +201,19 @@ describe("Lambda@Edge", () => { } }); - mockPageRequire("pages/preview.js"); - const result = await handler(event); - const response = result as CloudFrontResultResponse; - const decodedBody = new Buffer( - response.body as string, - "base64" - ).toString("utf8"); - expect(decodedBody).toBe("pages/preview.js"); - expect(response.status).toBe(200); + if (trailingSlash) { + await runRedirectTest("/preview", "/preview/"); + } else { + mockPageRequire("pages/preview.js"); + const result = await handler(event); + const response = result as CloudFrontResultResponse; + const decodedBody = new Buffer( + response.body as string, + "base64" + ).toString("utf8"); + expect(decodedBody).toBe("pages/preview.js"); + expect(response.status).toBe(200); + } }); }); From aadbc82a1132d17d317cddb3f366158d08f8986c Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Sun, 30 Aug 2020 16:07:54 +0800 Subject: [PATCH 03/13] - Added rollup and bundle default handler - Fixed expected uri in origin response. - Added util to rollup externals as it was breaking. --- packages/libs/lambda-at-edge/.gitignore | 2 +- packages/libs/lambda-at-edge/package.json | 12 +- packages/libs/lambda-at-edge/rollup.config.js | 26 ++ packages/libs/lambda-at-edge/src/build.ts | 8 - .../lambda-at-edge/src/default-handler.ts | 44 +++- .../lambda-at-edge/tests/build/build.test.ts | 11 +- .../default-handler/default-handler.test.ts | 4 + .../libs/lambda-at-edge/tsconfig.build.json | 3 +- .../libs/lambda-at-edge/tsconfig.bundle.json | 14 + packages/libs/lambda-at-edge/types.d.ts | 2 + packages/libs/lambda-at-edge/yarn.lock | 239 +++++++++++++++++- yarn.lock | 5 + 12 files changed, 330 insertions(+), 40 deletions(-) create mode 100644 packages/libs/lambda-at-edge/rollup.config.js create mode 100644 packages/libs/lambda-at-edge/tsconfig.bundle.json diff --git a/packages/libs/lambda-at-edge/.gitignore b/packages/libs/lambda-at-edge/.gitignore index 073f18ee8d..bf28b6480f 100644 --- a/packages/libs/lambda-at-edge/.gitignore +++ b/packages/libs/lambda-at-edge/.gitignore @@ -1,2 +1,2 @@ !tests/** -dist/ +dist/ \ No newline at end of file diff --git a/packages/libs/lambda-at-edge/package.json b/packages/libs/lambda-at-edge/package.json index 4a330a458d..4f7b2d04f5 100644 --- a/packages/libs/lambda-at-edge/package.json +++ b/packages/libs/lambda-at-edge/package.json @@ -9,7 +9,7 @@ "types": "dist/index.d.ts", "scripts": { "prepare": "yarn build", - "build": "tsc -p tsconfig.build.json" + "build": "rollup --config && tsc -p tsconfig.build.json" }, "files": [ "dist" @@ -31,18 +31,26 @@ }, "homepage": "https://github.com/danielcondemarin/serverless-next.js#readme", "devDependencies": { + "@rollup/plugin-commonjs": "^15.0.0", + "@rollup/plugin-node-resolve": "^9.0.0", + "@rollup/plugin-typescript": "^5.0.2", "@types/aws-lambda": "^8.10.57", + "@types/cookie": "^0.4.0", "@types/execa": "^2.0.0", "@types/fs-extra": "^9.0.1", + "@types/jsonwebtoken": "^8.5.0", "@types/node": "^14.0.14", "@types/path-to-regexp": "^1.7.0", + "path-to-regexp": "^6.1.0", + "rollup": "^2.26.6", "ts-loader": "^7.0.5", "typescript": "^3.9.6" }, "dependencies": { "@zeit/node-file-trace": "^0.6.5", + "cookie": "^0.4.1", "execa": "^4.0.2", "fs-extra": "^9.0.1", - "path-to-regexp": "^6.1.0" + "jsonwebtoken": "^8.5.1" } } diff --git a/packages/libs/lambda-at-edge/rollup.config.js b/packages/libs/lambda-at-edge/rollup.config.js new file mode 100644 index 0000000000..a9f963c4fa --- /dev/null +++ b/packages/libs/lambda-at-edge/rollup.config.js @@ -0,0 +1,26 @@ +import commonjs from "@rollup/plugin-commonjs"; +import typescript from "@rollup/plugin-typescript"; +import { nodeResolve } from "@rollup/plugin-node-resolve"; + +export default { + input: "./src/default-handler.ts", + output: { + file: "dist/default-handler.js", + format: "cjs" + }, + plugins: [ + commonjs(), + nodeResolve(), + typescript({ + tsconfig: "tsconfig.bundle.json" + }) + ], + external: [ + "util", + "aws-lambda", + "./manifest.json", + "aws-sdk/clients/s3", + "./routes-manifest.json", + "./prerender-manifest.json" + ] +}; diff --git a/packages/libs/lambda-at-edge/src/build.ts b/packages/libs/lambda-at-edge/src/build.ts index 2f7cddccbf..a1680a50b6 100644 --- a/packages/libs/lambda-at-edge/src/build.ts +++ b/packages/libs/lambda-at-edge/src/build.ts @@ -175,14 +175,6 @@ class Builder { join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "manifest.json"), buildManifest ), - fse.copy( - require.resolve("@sls-next/next-aws-cloudfront"), - join( - this.outputDir, - DEFAULT_LAMBDA_CODE_DIR, - "node_modules/@sls-next/next-aws-cloudfront/index.js" - ) - ), fse.copy( join(this.serverlessDir, "pages"), join(this.outputDir, DEFAULT_LAMBDA_CODE_DIR, "pages"), diff --git a/packages/libs/lambda-at-edge/src/default-handler.ts b/packages/libs/lambda-at-edge/src/default-handler.ts index 5505f7f726..28041f4ce3 100644 --- a/packages/libs/lambda-at-edge/src/default-handler.ts +++ b/packages/libs/lambda-at-edge/src/default-handler.ts @@ -5,6 +5,7 @@ import Manifest from "./manifest.json"; // @ts-ignore import { basePath } from "./routes-manifest.json"; import lambdaAtEdgeCompat from "@sls-next/next-aws-cloudfront"; +import cookie from "cookie"; import { CloudFrontRequest, CloudFrontS3Origin, @@ -21,23 +22,26 @@ import { import S3 from "aws-sdk/clients/s3"; import { performance } from "perf_hooks"; import { ServerResponse } from "http"; +import jsonwebtoken from "jsonwebtoken"; -const parseCookieValue = (cookie: string) => { - return cookie.split(";").reduce<{ [key: string]: string }>((acc, curr) => { - const [key, value] = curr.split("="); - acc[key.trim()] = value.trim(); - return acc; - }, {}); -}; +const NEXT_PREVIEW_DATA_COOKIE = "__next_preview_data"; +const NEXT_PRERENDER_BYPASS_COOKIE = "__prerender_bypass"; -const checkPreviewRequest = (request: CloudFrontRequest) => { +const getPreviewCookies = (request: CloudFrontRequest) => { const targetCookie = request.headers.cookie || []; - return targetCookie.some((cookieObj) => { - const cookieValue = parseCookieValue(cookieObj.value); + const previewCookie = targetCookie.find((cookieObj) => { + const cookieValue = cookie.parse(cookieObj.value); return ( - cookieValue["__next_preview_data"] && cookieValue["__prerender_bypass"] + cookieValue[NEXT_PREVIEW_DATA_COOKIE] && + cookieValue[NEXT_PRERENDER_BYPASS_COOKIE] ); }); + if (previewCookie) { + return cookie.parse(previewCookie.value) as { + [NEXT_PREVIEW_DATA_COOKIE]: string; + [NEXT_PRERENDER_BYPASS_COOKIE]: string; + }; + } }; const perfLogger = (logLambdaExecutionTimes: boolean): PerfLogger => { @@ -229,7 +233,21 @@ const handleOriginRequest = async ({ const normalisedS3DomainName = normaliseS3OriginDomain(s3Origin); const hasFallback = hasFallbackForUri(uri, prerenderManifest); const { now, log } = perfLogger(manifest.logLambdaExecutionTimes); - const isPreviewRequest = checkPreviewRequest(request); + const isPreviewRequest = getPreviewCookies(request); + + if (isPreviewRequest) { + try { + jsonwebtoken.verify( + isPreviewRequest[NEXT_PREVIEW_DATA_COOKIE], + prerenderManifest.preview.previewModeSigningKey + ); + } catch (e) { + return { + status: "403", + statusDescription: "Forbidden" + }; + } + } s3Origin.domainName = normalisedS3DomainName; @@ -295,7 +313,7 @@ const handleOriginRequest = async ({ } // Render page - if (isDataRequest(uri)) { + if (isDataReq) { const { renderOpts } = await page.renderReqToHTML( req, res, diff --git a/packages/libs/lambda-at-edge/tests/build/build.test.ts b/packages/libs/lambda-at-edge/tests/build/build.test.ts index 5ee545133c..b5b88f5334 100644 --- a/packages/libs/lambda-at-edge/tests/build/build.test.ts +++ b/packages/libs/lambda-at-edge/tests/build/build.test.ts @@ -156,7 +156,7 @@ describe("Builder Tests", () => { describe("Default Handler Artefact Files", () => { it("copies build files", async () => { - expect.assertions(7); + expect.assertions(6); const files = await fse.readdir( join(outputDir, `${DEFAULT_LAMBDA_CODE_DIR}`) @@ -170,24 +170,15 @@ describe("Builder Tests", () => { const apiDirExists = await fse.pathExists( join(outputDir, `${DEFAULT_LAMBDA_CODE_DIR}/pages/api`) ); - const compatLayerIncluded = await fse.pathExists( - join( - outputDir, - `${DEFAULT_LAMBDA_CODE_DIR}/node_modules/@sls-next/next-aws-cloudfront/index.js` - ) - ); expect(files).toEqual([ "index.js", "manifest.json", - "node_modules", "pages", "prerender-manifest.json", "routes-manifest.json" ]); - expect(compatLayerIncluded).toEqual(true); - // api pages should not be included in the default lambda expect(apiDirExists).toEqual(false); diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts index cf5403ec77..3fa6561148 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts @@ -5,6 +5,10 @@ import { CloudFrontOrigin } from "aws-lambda"; +jest.mock("jsonwebtoken", () => ({ + verify: jest.fn() +})); + jest.mock( "../../src/prerender-manifest.json", () => require("./prerender-manifest.json"), diff --git a/packages/libs/lambda-at-edge/tsconfig.build.json b/packages/libs/lambda-at-edge/tsconfig.build.json index e72163e6d4..408578d054 100644 --- a/packages/libs/lambda-at-edge/tsconfig.build.json +++ b/packages/libs/lambda-at-edge/tsconfig.build.json @@ -4,5 +4,6 @@ "sourceMap": false, "removeComments": true }, - "include": ["./src/"] + "include": ["./src/"], + "exclude": ["node_modules", "./src/default-handler.ts"] } diff --git a/packages/libs/lambda-at-edge/tsconfig.bundle.json b/packages/libs/lambda-at-edge/tsconfig.bundle.json new file mode 100644 index 0000000000..eac46a2a6e --- /dev/null +++ b/packages/libs/lambda-at-edge/tsconfig.bundle.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "module": "ESNext", + "target": "es2019", + "moduleResolution": "node", + "noImplicitAny": true, + "sourceMap": true, + "strict": true, + "allowJs": true + }, + "include": ["./src/default-handler.ts"] +} diff --git a/packages/libs/lambda-at-edge/types.d.ts b/packages/libs/lambda-at-edge/types.d.ts index f8b474dc93..84264fd1c1 100644 --- a/packages/libs/lambda-at-edge/types.d.ts +++ b/packages/libs/lambda-at-edge/types.d.ts @@ -80,6 +80,8 @@ export type PreRenderedManifest = { }; preview: { previewModeId: string; + previewModeSigningKey: string; + previewModeEncryptionKey: string; }; }; diff --git a/packages/libs/lambda-at-edge/yarn.lock b/packages/libs/lambda-at-edge/yarn.lock index 6f4d7fd424..ee732acfae 100644 --- a/packages/libs/lambda-at-edge/yarn.lock +++ b/packages/libs/lambda-at-edge/yarn.lock @@ -2,11 +2,68 @@ # yarn lockfile v1 +"@rollup/plugin-commonjs@^15.0.0": + version "15.0.0" + resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-15.0.0.tgz#690d15a9d54ba829db93555bff9b98ff34e08574" + integrity sha512-8uAdikHqVyrT32w1zB9VhW6uGwGjhKgnDNP4pQJsjdnyF4FgCj6/bmv24c7v2CuKhq32CcyCwRzMPEElaKkn0w== + dependencies: + "@rollup/pluginutils" "^3.1.0" + commondir "^1.0.1" + estree-walker "^2.0.1" + glob "^7.1.6" + is-reference "^1.2.1" + magic-string "^0.25.7" + resolve "^1.17.0" + +"@rollup/plugin-node-resolve@^9.0.0": + version "9.0.0" + resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-9.0.0.tgz#39bd0034ce9126b39c1699695f440b4b7d2b62e6" + integrity sha512-gPz+utFHLRrd41WMP13Jq5mqqzHL3OXrfj3/MkSyB6UBIcuNt9j60GCbarzMzdf1VHFpOxfQh/ez7wyadLMqkg== + dependencies: + "@rollup/pluginutils" "^3.1.0" + "@types/resolve" "1.17.1" + builtin-modules "^3.1.0" + deepmerge "^4.2.2" + is-module "^1.0.0" + resolve "^1.17.0" + +"@rollup/plugin-typescript@^5.0.2": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-5.0.2.tgz#e879b73354851868b805bbd43f15c229123b8a71" + integrity sha512-CkS028Itwjqm1uLbFVfpJgtVtnNvZ+og/m6UlNRR5wOOnNTWPcVQzOu5xGdEX+WWJxdvWIqUq2uR/RBt2ZipWg== + dependencies: + "@rollup/pluginutils" "^3.0.1" + resolve "^1.14.1" + +"@rollup/pluginutils@^3.0.1", "@rollup/pluginutils@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" + integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== + dependencies: + "@types/estree" "0.0.39" + estree-walker "^1.0.1" + picomatch "^2.2.2" + "@types/aws-lambda@^8.10.57": version "8.10.61" resolved "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.61.tgz#7471e08843dbdcf09b2494ac5b34c4d1a391e6d0" integrity sha512-+FeZ/52VG4rBSJ0cRE/aB6hMKQzjIgpiSQrGq0eR8ZrXWee7Z2zoGeJzTHVcOeZNawLb+5zvwZNIRGC7X+kQ7Q== +"@types/cookie@^0.4.0": + version "0.4.0" + resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.4.0.tgz#14f854c0f93d326e39da6e3b6f34f7d37513d108" + integrity sha512-y7mImlc/rNkvCRmg8gC3/lj87S7pTUIJ6QGjwHR9WQJcFs+ZMTOaoPrkdFA/YdbuqVEmEbb5RdhVxMkAcgOnpg== + +"@types/estree@*": + version "0.0.45" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz#e9387572998e5ecdac221950dab3e8c3b16af884" + integrity sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g== + +"@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + "@types/execa@^2.0.0": version "2.0.0" resolved "https://registry.npmjs.org/@types/execa/-/execa-2.0.0.tgz#4dd5523520c51834bf8d0c280f460814e5238281" @@ -21,6 +78,13 @@ dependencies: "@types/node" "*" +"@types/jsonwebtoken@^8.5.0": + version "8.5.0" + resolved "https://registry.yarnpkg.com/@types/jsonwebtoken/-/jsonwebtoken-8.5.0.tgz#2531d5e300803aa63279b232c014acf780c981c5" + integrity sha512-9bVao7LvyorRGZCw0VmH/dr7Og+NdjYSsKAxB43OQoComFbBgsEpoR9JW6+qSq/ogwVBg8GI2MfAlk4SYI4OLg== + dependencies: + "@types/node" "*" + "@types/node@*", "@types/node@^14.0.14": version "14.0.27" resolved "https://registry.npmjs.org/@types/node/-/node-14.0.27.tgz#a151873af5a5e851b51b3b065c9e63390a9e0eb1" @@ -33,6 +97,13 @@ dependencies: path-to-regexp "*" +"@types/resolve@1.17.1": + version "1.17.1" + resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" + integrity sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw== + dependencies: + "@types/node" "*" + "@zeit/node-file-trace@^0.6.5": version "0.6.5" resolved "https://registry.npmjs.org/@zeit/node-file-trace/-/node-file-trace-0.6.5.tgz#ffd443e4648eb88591c53b1a871a47bff651b62e" @@ -166,9 +237,19 @@ braces@^3.0.1: dependencies: fill-range "^7.0.1" +buffer-equal-constant-time@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819" + integrity sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk= + +builtin-modules@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.1.0.tgz#aad97c15131eb76b65b50ef208e7584cd76a7484" + integrity sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw== + chalk@^2.3.0: version "2.4.2" - resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== dependencies: ansi-styles "^3.2.1" @@ -197,6 +278,11 @@ color-name@1.1.3: resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= +commondir@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" + integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs= + concat-map@0.0.1: version "0.0.1" resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -207,6 +293,11 @@ console-control-strings@^1.0.0, console-control-strings@~1.1.0: resolved "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" integrity sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4= +cookie@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1" + integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA== + core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -233,6 +324,11 @@ deep-extend@^0.6.0: resolved "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== +deepmerge@^4.2.2: + version "4.2.2" + resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955" + integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== + delegates@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" @@ -243,6 +339,13 @@ detect-libc@^1.0.2: resolved "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= +ecdsa-sig-formatter@1.0.11: + version "1.0.11" + resolved "https://registry.yarnpkg.com/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz#ae0f0fa2d85045ef14a817daa3ce9acd0489e5bf" + integrity sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ== + dependencies: + safe-buffer "^5.0.1" + emojis-list@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78" @@ -281,6 +384,16 @@ estree-walker@^0.6.0, estree-walker@^0.6.1: resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362" integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w== +estree-walker@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" + integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== + +estree-walker@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.1.tgz#f8e030fb21cefa183b44b7ad516b747434e7a3e0" + integrity sha512-tF0hv+Yi2Ot1cwj9eYHtxC0jB9bmjacjQs6ZBTj82H8JwUywFuc+7E83NWfNMwHXZc11mjfFcVXPe9gEP4B8dg== + execa@*, execa@^4.0.2: version "4.0.3" resolved "https://registry.npmjs.org/execa/-/execa-4.0.3.tgz#0a34dabbad6d66100bd6f2c576c8669403f317f2" @@ -330,6 +443,11 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= +fsevents@~2.1.2: + version "2.1.3" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.3.tgz#fb738703ae8d2f9fe900c33836ddebee8b97f23e" + integrity sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ== + gauge@~2.7.3: version "2.7.4" resolved "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" @@ -351,7 +469,7 @@ get-stream@^5.0.0: dependencies: pump "^3.0.0" -glob@^7.1.3: +glob@^7.1.3, glob@^7.1.6: version "7.1.6" resolved "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== @@ -427,11 +545,23 @@ is-fullwidth-code-point@^2.0.0: resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8= +is-module@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591" + integrity sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE= + is-number@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== +is-reference@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.2.1.tgz#8b2dac0b371f4bc994fdeaba9eb542d03002d0b7" + integrity sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ== + dependencies: + "@types/estree" "*" + is-stream@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3" @@ -463,6 +593,39 @@ jsonfile@^6.0.1: optionalDependencies: graceful-fs "^4.1.6" +jsonwebtoken@^8.5.1: + version "8.5.1" + resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d" + integrity sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w== + dependencies: + jws "^3.2.2" + lodash.includes "^4.3.0" + lodash.isboolean "^3.0.3" + lodash.isinteger "^4.0.4" + lodash.isnumber "^3.0.3" + lodash.isplainobject "^4.0.6" + lodash.isstring "^4.0.1" + lodash.once "^4.0.0" + ms "^2.1.1" + semver "^5.6.0" + +jwa@^1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/jwa/-/jwa-1.4.1.tgz#743c32985cb9e98655530d53641b66c8645b039a" + integrity sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA== + dependencies: + buffer-equal-constant-time "1.0.1" + ecdsa-sig-formatter "1.0.11" + safe-buffer "^5.0.1" + +jws@^3.2.2: + version "3.2.2" + resolved "https://registry.yarnpkg.com/jws/-/jws-3.2.2.tgz#001099f3639468c9414000e99995fa52fb478304" + integrity sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA== + dependencies: + jwa "^1.4.1" + safe-buffer "^5.0.1" + loader-utils@^1.0.2: version "1.4.0" resolved "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz#c579b5e34cb34b1a74edc6c1fb36bfa371d5a613" @@ -472,6 +635,48 @@ loader-utils@^1.0.2: emojis-list "^3.0.0" json5 "^1.0.1" +lodash.includes@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f" + integrity sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8= + +lodash.isboolean@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" + integrity sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY= + +lodash.isinteger@^4.0.4: + version "4.0.4" + resolved "https://registry.yarnpkg.com/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343" + integrity sha1-YZwK89A/iwTDH1iChAt3sRzWg0M= + +lodash.isnumber@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc" + integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w= + +lodash.isplainobject@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" + integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs= + +lodash.isstring@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" + integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE= + +lodash.once@^4.0.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" + integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w= + +magic-string@^0.25.7: + version "0.25.7" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051" + integrity sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA== + dependencies: + sourcemap-codec "^1.4.4" + memory-fs@^0.5.0: version "0.5.0" resolved "https://registry.npmjs.org/memory-fs/-/memory-fs-0.5.0.tgz#324c01288b88652966d161db77838720845a8e3c" @@ -665,12 +870,17 @@ path-key@^3.0.0, path-key@^3.1.0: resolved "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== +path-parse@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" + integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + path-to-regexp@*, path-to-regexp@^6.1.0: version "6.1.0" resolved "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.1.0.tgz#0b18f88b7a0ce0bfae6a25990c909ab86f512427" integrity sha512-h9DqehX3zZZDCEm+xbfU0ZmwCGFCAAraPJWMXJ4+v32NjZJilVg3k1TcKsRgIb8IQ/izZSaydDc1OhJCZvs2Dw== -picomatch@^2.0.5: +picomatch@^2.0.5, picomatch@^2.2.2: version "2.2.2" resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad" integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg== @@ -721,6 +931,13 @@ resolve-from@^5.0.0: resolved "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== +resolve@^1.14.1, resolve@^1.17.0: + version "1.17.0" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444" + integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w== + dependencies: + path-parse "^1.0.6" + rimraf@^2.6.1: version "2.7.1" resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" @@ -735,7 +952,14 @@ rollup-pluginutils@^2.8.2: dependencies: estree-walker "^0.6.1" -safe-buffer@^5.1.2: +rollup@^2.26.6: + version "2.26.6" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.26.6.tgz#0b460c1da224c6af12a1e948a28c513aa11f2b93" + integrity sha512-iSB7eE3k/VNQHnI7ckS++4yIqTamoUCB1xo7MswhJ/fg22oFYR5+xCrUZVviBj97jvc5A31MPbVMw1Wc3jWxmw== + optionalDependencies: + fsevents "~2.1.2" + +safe-buffer@^5.0.1, safe-buffer@^5.1.2: version "5.2.1" resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== @@ -755,7 +979,7 @@ sax@^1.2.4: resolved "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== -semver@^5.3.0: +semver@^5.3.0, semver@^5.6.0: version "5.7.1" resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== @@ -787,6 +1011,11 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: resolved "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== +sourcemap-codec@^1.4.4: + version "1.4.8" + resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" + integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== + string-width@^1.0.1: version "1.0.2" resolved "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" diff --git a/yarn.lock b/yarn.lock index 89ace88869..80639e3037 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5199,6 +5199,11 @@ convert-source-map@^0.3.3: resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-0.3.5.tgz#f1d802950af7dd2631a1febe0596550c86ab3190" integrity sha1-8dgClQr33SYxof6+BZZVDIarMZA= +cookie@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1" + integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA== + cookiejar@^2.1.0: version "2.1.2" resolved "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz#dd8a235530752f988f9a0844f3fc589e3111125c" From 59af91f629e6dad6b2a6119c015a89b82a3abade Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Mon, 31 Aug 2020 16:25:41 +0800 Subject: [PATCH 04/13] Rebased and updated tests --- .../tests/default-handler/default-handler.test.ts | 6 +++++- .../tests/shared-fixtures/built-artifact/pages/_error.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts index 3fa6561148..ef012fe9b8 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts @@ -563,7 +563,11 @@ describe("Lambda@Edge", () => { const body = response.body as string; const decodedBody = new Buffer(body, "base64").toString("utf8"); - expect(decodedBody).toEqual("pages/_error.js - 404"); + expect(decodedBody).toEqual( + JSON.stringify({ + page: "pages/_error.js - 404" + }) + ); expect(response.status).toEqual("404"); } ); diff --git a/packages/libs/lambda-at-edge/tests/shared-fixtures/built-artifact/pages/_error.js b/packages/libs/lambda-at-edge/tests/shared-fixtures/built-artifact/pages/_error.js index de8ec35666..447499c8dc 100644 --- a/packages/libs/lambda-at-edge/tests/shared-fixtures/built-artifact/pages/_error.js +++ b/packages/libs/lambda-at-edge/tests/shared-fixtures/built-artifact/pages/_error.js @@ -4,5 +4,14 @@ module.exports = { // the Next.js default _error.js page shows different text based on the status // that is used when rendering the page. res.end(`pages/_error.js - ${res.statusCode}`); + }, + renderReqToHTML: (req, res) => { + return { + renderOpts: { + pageData: { + page: `pages/_error.js - ${res.statusCode}` + } + } + }; } }; From 9f684308e6a15f3d038b7eef280f51375c650fb5 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Mon, 31 Aug 2020 17:08:23 +0800 Subject: [PATCH 05/13] Updated another test --- .../default-handler/default-handler-with-basepath.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler-with-basepath.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler-with-basepath.test.ts index 368b38b263..047d609918 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler-with-basepath.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler-with-basepath.test.ts @@ -537,7 +537,11 @@ describe("Lambda@Edge", () => { const body = response.body as string; const decodedBody = new Buffer(body, "base64").toString("utf8"); - expect(decodedBody).toEqual("pages/_error.js - 404"); + expect(decodedBody).toEqual( + JSON.stringify({ + page: "pages/_error.js - 404" + }) + ); expect(response.status).toEqual("404"); } ); From c8b12a893a462ed6c7090e20e305824cbce641d2 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Mon, 31 Aug 2020 18:44:02 +0800 Subject: [PATCH 06/13] - Add API Lambda to rollup - Fixed some erroneous logic in the router, since it's now being used in the response handler - Mocked console errors in tests --- packages/libs/lambda-at-edge/package.json | 1 + packages/libs/lambda-at-edge/rollup.config.js | 30 +++++++----- packages/libs/lambda-at-edge/src/build.ts | 8 ---- .../lambda-at-edge/src/default-handler.ts | 19 +++++--- .../lambda-at-edge/tests/build/build.test.ts | 11 +---- .../default-handler-with-basepath.test.ts | 9 ++++ .../default-handler/default-handler.test.ts | 9 ++++ .../libs/lambda-at-edge/tsconfig.build.json | 6 ++- .../libs/lambda-at-edge/tsconfig.bundle.json | 6 +-- packages/libs/lambda-at-edge/yarn.lock | 46 +++++++++++++++++++ 10 files changed, 104 insertions(+), 41 deletions(-) diff --git a/packages/libs/lambda-at-edge/package.json b/packages/libs/lambda-at-edge/package.json index 4f7b2d04f5..d75c526c21 100644 --- a/packages/libs/lambda-at-edge/package.json +++ b/packages/libs/lambda-at-edge/package.json @@ -43,6 +43,7 @@ "@types/path-to-regexp": "^1.7.0", "path-to-regexp": "^6.1.0", "rollup": "^2.26.6", + "rollup-plugin-node-externals": "^2.2.0", "ts-loader": "^7.0.5", "typescript": "^3.9.6" }, diff --git a/packages/libs/lambda-at-edge/rollup.config.js b/packages/libs/lambda-at-edge/rollup.config.js index a9f963c4fa..a4a7f2fa83 100644 --- a/packages/libs/lambda-at-edge/rollup.config.js +++ b/packages/libs/lambda-at-edge/rollup.config.js @@ -1,26 +1,32 @@ import commonjs from "@rollup/plugin-commonjs"; import typescript from "@rollup/plugin-typescript"; import { nodeResolve } from "@rollup/plugin-node-resolve"; +import externals from "rollup-plugin-node-externals"; -export default { - input: "./src/default-handler.ts", +const LOCAL_EXTERNALS = [ + "./manifest.json", + "./routes-manifest.json", + "./prerender-manifest.json" +]; +const NPM_EXTERNALS = ["aws-lambda", "aws-sdk/clients/s3"]; + +const generateConfig = (filename) => ({ + input: `./src/${filename}.ts`, output: { - file: "dist/default-handler.js", + file: `./dist/${filename}.js`, format: "cjs" }, plugins: [ commonjs(), + externals({ + exclude: "@sls-next/next-aws-cloudfront" + }), nodeResolve(), typescript({ tsconfig: "tsconfig.bundle.json" }) ], - external: [ - "util", - "aws-lambda", - "./manifest.json", - "aws-sdk/clients/s3", - "./routes-manifest.json", - "./prerender-manifest.json" - ] -}; + external: [...NPM_EXTERNALS, ...LOCAL_EXTERNALS] +}); + +export default ["default-handler", "api-handler"].map(generateConfig); diff --git a/packages/libs/lambda-at-edge/src/build.ts b/packages/libs/lambda-at-edge/src/build.ts index a1680a50b6..b310d94b24 100644 --- a/packages/libs/lambda-at-edge/src/build.ts +++ b/packages/libs/lambda-at-edge/src/build.ts @@ -237,14 +237,6 @@ class Builder { require.resolve("@sls-next/lambda-at-edge/dist/api-handler.js"), join(this.outputDir, API_LAMBDA_CODE_DIR, "index.js") ), - fse.copy( - require.resolve("@sls-next/next-aws-cloudfront"), - join( - this.outputDir, - API_LAMBDA_CODE_DIR, - "node_modules/@sls-next/next-aws-cloudfront/index.js" - ) - ), fse.copy( join(this.serverlessDir, "pages/api"), join(this.outputDir, API_LAMBDA_CODE_DIR, "pages/api") diff --git a/packages/libs/lambda-at-edge/src/default-handler.ts b/packages/libs/lambda-at-edge/src/default-handler.ts index 28041f4ce3..4e6f120bfa 100644 --- a/packages/libs/lambda-at-edge/src/default-handler.ts +++ b/packages/libs/lambda-at-edge/src/default-handler.ts @@ -108,10 +108,12 @@ const router = ( manifest: OriginRequestDefaultHandlerManifest ): ((uri: string) => string) => { const { - pages: { ssr, html } + pages: { ssr, html }, + publicFiles } = manifest; const allDynamicRoutes = { ...ssr.dynamic, ...html.dynamic }; + const allNonDynamicRoutes = { ...ssr.nonDynamic, ...html.nonDynamic }; return (uri: string): string => { let normalisedUri = uri; @@ -120,15 +122,18 @@ const router = ( normalisedUri = uri .replace(`/_next/data/${manifest.buildId}`, "") .replace(".json", ""); + } + // Normalise to "/" for index + normalisedUri = ["/index", ""].includes(normalisedUri) + ? "/" + : normalisedUri; - // Normalise to "/" for index data request - normalisedUri = ["/index", ""].includes(normalisedUri) - ? "/" - : normalisedUri; + if (allNonDynamicRoutes[normalisedUri]) { + return allNonDynamicRoutes[normalisedUri]; } - if (ssr.nonDynamic[normalisedUri]) { - return ssr.nonDynamic[normalisedUri]; + if (publicFiles[normalisedUri]) { + return publicFiles[normalisedUri]; } for (const route in allDynamicRoutes) { diff --git a/packages/libs/lambda-at-edge/tests/build/build.test.ts b/packages/libs/lambda-at-edge/tests/build/build.test.ts index b5b88f5334..5fb2b0763a 100644 --- a/packages/libs/lambda-at-edge/tests/build/build.test.ts +++ b/packages/libs/lambda-at-edge/tests/build/build.test.ts @@ -194,7 +194,7 @@ describe("Builder Tests", () => { describe("API Handler Artefact Files", () => { it("copies build files", async () => { - expect.assertions(3); + expect.assertions(2); const files = await fse.readdir( join(outputDir, `${API_LAMBDA_CODE_DIR}`) @@ -203,18 +203,9 @@ describe("Builder Tests", () => { join(outputDir, `${API_LAMBDA_CODE_DIR}/pages`) ); - const compatLayerIncluded = await fse.pathExists( - join( - outputDir, - `${API_LAMBDA_CODE_DIR}/node_modules/@sls-next/next-aws-cloudfront/index.js` - ) - ); - - expect(compatLayerIncluded).toEqual(true); expect(files).toEqual([ "index.js", "manifest.json", - "node_modules", "pages", "routes-manifest.json" ]); diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler-with-basepath.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler-with-basepath.test.ts index 047d609918..67b65a5bd3 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler-with-basepath.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler-with-basepath.test.ts @@ -32,6 +32,15 @@ const mockPageRequire = (mockPagePath: string): void => { }; describe("Lambda@Edge", () => { + let consoleWarnSpy: jest.SpyInstance; + + beforeEach(() => { + consoleWarnSpy = jest.spyOn(console, "error").mockReturnValue(); + }); + + afterEach(() => { + consoleWarnSpy.mockRestore(); + }); describe.each` trailingSlash ${false} diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts index ef012fe9b8..3a527fb16f 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts @@ -36,6 +36,15 @@ const mockPageRequire = (mockPagePath: string): void => { }; describe("Lambda@Edge", () => { + let consoleWarnSpy: jest.SpyInstance; + + beforeEach(() => { + consoleWarnSpy = jest.spyOn(console, "error").mockReturnValue(); + }); + + afterEach(() => { + consoleWarnSpy.mockRestore(); + }); describe.each` trailingSlash ${false} diff --git a/packages/libs/lambda-at-edge/tsconfig.build.json b/packages/libs/lambda-at-edge/tsconfig.build.json index 408578d054..b1de996030 100644 --- a/packages/libs/lambda-at-edge/tsconfig.build.json +++ b/packages/libs/lambda-at-edge/tsconfig.build.json @@ -5,5 +5,9 @@ "removeComments": true }, "include": ["./src/"], - "exclude": ["node_modules", "./src/default-handler.ts"] + "exclude": [ + "node_modules", + "./src/api-handler.ts", + "./src/default-handler.ts" + ] } diff --git a/packages/libs/lambda-at-edge/tsconfig.bundle.json b/packages/libs/lambda-at-edge/tsconfig.bundle.json index eac46a2a6e..efe611bfeb 100644 --- a/packages/libs/lambda-at-edge/tsconfig.bundle.json +++ b/packages/libs/lambda-at-edge/tsconfig.bundle.json @@ -6,9 +6,9 @@ "target": "es2019", "moduleResolution": "node", "noImplicitAny": true, - "sourceMap": true, + "sourceMap": false, "strict": true, "allowJs": true }, - "include": ["./src/default-handler.ts"] -} + "include": ["./src/default-handler.ts", "./src/api-handler.ts"] +} \ No newline at end of file diff --git a/packages/libs/lambda-at-edge/yarn.lock b/packages/libs/lambda-at-edge/yarn.lock index ee732acfae..44eeb8e2d3 100644 --- a/packages/libs/lambda-at-edge/yarn.lock +++ b/packages/libs/lambda-at-edge/yarn.lock @@ -421,6 +421,14 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" +find-up@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" + integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw== + dependencies: + locate-path "^5.0.0" + path-exists "^4.0.0" + fs-extra@^9.0.1: version "9.0.1" resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc" @@ -635,6 +643,13 @@ loader-utils@^1.0.2: emojis-list "^3.0.0" json5 "^1.0.1" +locate-path@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0" + integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g== + dependencies: + p-locate "^4.1.0" + lodash.includes@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f" @@ -860,6 +875,30 @@ osenv@^0.1.4: os-homedir "^1.0.0" os-tmpdir "^1.0.0" +p-limit@^2.2.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" + integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w== + dependencies: + p-try "^2.0.0" + +p-locate@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07" + integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A== + dependencies: + p-limit "^2.2.0" + +p-try@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6" + integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ== + +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -945,6 +984,13 @@ rimraf@^2.6.1: dependencies: glob "^7.1.3" +rollup-plugin-node-externals@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-node-externals/-/rollup-plugin-node-externals-2.2.0.tgz#23946e8c0fdd0e321cc3f225d4cebc3d819d17c4" + integrity sha512-WM7TtQ76GdsLceEGmZzQzn1afj8JgOQT5VLs1Y9RMqowM/8eK2mBj/Lv7hoE833U75QsUZIRirYUtFatu51RJA== + dependencies: + find-up "^4.1.0" + rollup-pluginutils@^2.8.2: version "2.8.2" resolved "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e" From 938e21d685a0c49784eb6e50ef3bee52e562d44d Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Mon, 31 Aug 2020 18:53:29 +0800 Subject: [PATCH 07/13] Revert some changes which were superseded by @dphang's changes. --- .../lambda-at-edge/src/default-handler.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/libs/lambda-at-edge/src/default-handler.ts b/packages/libs/lambda-at-edge/src/default-handler.ts index 4e6f120bfa..28041f4ce3 100644 --- a/packages/libs/lambda-at-edge/src/default-handler.ts +++ b/packages/libs/lambda-at-edge/src/default-handler.ts @@ -108,12 +108,10 @@ const router = ( manifest: OriginRequestDefaultHandlerManifest ): ((uri: string) => string) => { const { - pages: { ssr, html }, - publicFiles + pages: { ssr, html } } = manifest; const allDynamicRoutes = { ...ssr.dynamic, ...html.dynamic }; - const allNonDynamicRoutes = { ...ssr.nonDynamic, ...html.nonDynamic }; return (uri: string): string => { let normalisedUri = uri; @@ -122,18 +120,15 @@ const router = ( normalisedUri = uri .replace(`/_next/data/${manifest.buildId}`, "") .replace(".json", ""); - } - // Normalise to "/" for index - normalisedUri = ["/index", ""].includes(normalisedUri) - ? "/" - : normalisedUri; - if (allNonDynamicRoutes[normalisedUri]) { - return allNonDynamicRoutes[normalisedUri]; + // Normalise to "/" for index data request + normalisedUri = ["/index", ""].includes(normalisedUri) + ? "/" + : normalisedUri; } - if (publicFiles[normalisedUri]) { - return publicFiles[normalisedUri]; + if (ssr.nonDynamic[normalisedUri]) { + return ssr.nonDynamic[normalisedUri]; } for (const route in allDynamicRoutes) { From 6b95135137a0024a195c6996c2386ad4741be1e1 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Mon, 31 Aug 2020 19:06:17 +0800 Subject: [PATCH 08/13] Fixed integration test --- .../serverless-trace-with-dynamic-import.test.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/libs/lambda-at-edge/tests/integration/serverless-trace-with-dynamic-import/serverless-trace-with-dynamic-import.test.ts b/packages/libs/lambda-at-edge/tests/integration/serverless-trace-with-dynamic-import/serverless-trace-with-dynamic-import.test.ts index 950f84d3a9..f3c10a9686 100644 --- a/packages/libs/lambda-at-edge/tests/integration/serverless-trace-with-dynamic-import/serverless-trace-with-dynamic-import.test.ts +++ b/packages/libs/lambda-at-edge/tests/integration/serverless-trace-with-dynamic-import/serverless-trace-with-dynamic-import.test.ts @@ -40,12 +40,7 @@ describe("Serverless Trace With Dynamic Import", () => { const nodeModules = await readdir( path.join(outputDir, "api-lambda/node_modules") ); - expect(nodeModules).toEqual(["@sls-next", "next"]); - - const slsNextNodeModules = await readdir( - path.join(outputDir, "api-lambda/node_modules/@sls-next") - ); - expect(slsNextNodeModules).toContain("next-aws-cloudfront"); + expect(nodeModules).toEqual(["next"]); }); it("copies dynamic chunk to default lambda artefact", async () => { From 12efe580b7214a410601a5f2e358246dc1b2ad15 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Tue, 1 Sep 2020 09:58:21 +0800 Subject: [PATCH 09/13] Updated tests --- .../default-handler/default-handler.test.ts | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts index 3a527fb16f..7ee2bb1943 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts @@ -128,6 +128,7 @@ describe("Lambda@Edge", () => { ${"/john/123"} | ${"/[username]/[id].html"} ${"/tests/prerender-manifest/example-static-page"} | ${"/tests/prerender-manifest/example-static-page.html"} ${"/tests/prerender-manifest-fallback/not-yet-built"} | ${"/tests/prerender-manifest-fallback/not-yet-built.html"} + ${"/preview"} | ${"/preview.html"} `( "serves page $expectedPage from S3 for path $path", async ({ path, expectedPage }) => { @@ -199,10 +200,10 @@ describe("Lambda@Edge", () => { expect(response.status).toEqual("200"); }); - + it("handles preview mode", async () => { const event = createCloudFrontEvent({ - uri: "/preview", + uri: `/preview${trailingSlash ? "/" : ""}`, host: "mydistribution.cloudfront.net", requestHeaders: { cookie: [ @@ -214,19 +215,15 @@ describe("Lambda@Edge", () => { } }); - if (trailingSlash) { - await runRedirectTest("/preview", "/preview/"); - } else { - mockPageRequire("pages/preview.js"); - const result = await handler(event); - const response = result as CloudFrontResultResponse; - const decodedBody = new Buffer( - response.body as string, - "base64" - ).toString("utf8"); - expect(decodedBody).toBe("pages/preview.js"); - expect(response.status).toBe(200); - } + mockPageRequire("pages/preview.js"); + const result = await handler(event); + const response = result as CloudFrontResultResponse; + const decodedBody = new Buffer( + response.body as string, + "base64" + ).toString("utf8"); + expect(decodedBody).toBe("pages/preview.js"); + expect(response.status).toBe(200); }); }); From 0cb6377d2aad20f5f38ff6bba712f76f003b4973 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Tue, 1 Sep 2020 10:00:34 +0800 Subject: [PATCH 10/13] Added explicit return to getPreviewCookies --- packages/libs/lambda-at-edge/src/default-handler.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/libs/lambda-at-edge/src/default-handler.ts b/packages/libs/lambda-at-edge/src/default-handler.ts index 28041f4ce3..23df5314c0 100644 --- a/packages/libs/lambda-at-edge/src/default-handler.ts +++ b/packages/libs/lambda-at-edge/src/default-handler.ts @@ -41,6 +41,11 @@ const getPreviewCookies = (request: CloudFrontRequest) => { [NEXT_PREVIEW_DATA_COOKIE]: string; [NEXT_PRERENDER_BYPASS_COOKIE]: string; }; + } else { + return { + [NEXT_PRERENDER_BYPASS_COOKIE]: "", + [NEXT_PREVIEW_DATA_COOKIE]: "" + }; } }; @@ -233,12 +238,15 @@ const handleOriginRequest = async ({ const normalisedS3DomainName = normaliseS3OriginDomain(s3Origin); const hasFallback = hasFallbackForUri(uri, prerenderManifest); const { now, log } = perfLogger(manifest.logLambdaExecutionTimes); - const isPreviewRequest = getPreviewCookies(request); + const previewCookies = getPreviewCookies(request); + const isPreviewRequest = + previewCookies[NEXT_PREVIEW_DATA_COOKIE] && + previewCookies[NEXT_PRERENDER_BYPASS_COOKIE]; if (isPreviewRequest) { try { jsonwebtoken.verify( - isPreviewRequest[NEXT_PREVIEW_DATA_COOKIE], + previewCookies[NEXT_PREVIEW_DATA_COOKIE], prerenderManifest.preview.previewModeSigningKey ); } catch (e) { From c5d662c44ffecf33d73dd4c1fef1ef891812bbd7 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Tue, 1 Sep 2020 10:04:30 +0800 Subject: [PATCH 11/13] Added error logging to preview token verification catch block. --- packages/libs/lambda-at-edge/src/default-handler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/libs/lambda-at-edge/src/default-handler.ts b/packages/libs/lambda-at-edge/src/default-handler.ts index 23df5314c0..c587b926ae 100644 --- a/packages/libs/lambda-at-edge/src/default-handler.ts +++ b/packages/libs/lambda-at-edge/src/default-handler.ts @@ -250,6 +250,7 @@ const handleOriginRequest = async ({ prerenderManifest.preview.previewModeSigningKey ); } catch (e) { + console.error("Failed preview mode verification for URI:", request.uri); return { status: "403", statusDescription: "Forbidden" From 131913cd7e058e4c9b69af7ddf04c401fa3e6e64 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Tue, 1 Sep 2020 11:57:20 +0800 Subject: [PATCH 12/13] Added preview path test case to redirect --- .../lambda-at-edge/tests/default-handler/default-handler.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts index 7ee2bb1943..449fed93b8 100644 --- a/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts +++ b/packages/libs/lambda-at-edge/tests/default-handler/default-handler.test.ts @@ -170,6 +170,7 @@ describe("Lambda@Edge", () => { ${"/john/123"} ${"/tests/prerender-manifest/example-static-page"} ${"/tests/prerender-manifest-fallback/not-yet-built"} + ${"/preview"} `( `path $path redirects if it ${ trailingSlash ? "does not have" : "has" From e477354a719bb41c5c8f076be518828c18f3b8a3 Mon Sep 17 00:00:00 2001 From: Thomas Chia Date: Wed, 2 Sep 2020 16:47:29 +0800 Subject: [PATCH 13/13] Optimised getPreviewCookies function. --- .../lambda-at-edge/src/default-handler.ts | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/libs/lambda-at-edge/src/default-handler.ts b/packages/libs/lambda-at-edge/src/default-handler.ts index c587b926ae..78747969b4 100644 --- a/packages/libs/lambda-at-edge/src/default-handler.ts +++ b/packages/libs/lambda-at-edge/src/default-handler.ts @@ -26,27 +26,24 @@ import jsonwebtoken from "jsonwebtoken"; const NEXT_PREVIEW_DATA_COOKIE = "__next_preview_data"; const NEXT_PRERENDER_BYPASS_COOKIE = "__prerender_bypass"; +const defaultPreviewCookies = { + [NEXT_PRERENDER_BYPASS_COOKIE]: "", + [NEXT_PREVIEW_DATA_COOKIE]: "" +}; const getPreviewCookies = (request: CloudFrontRequest) => { const targetCookie = request.headers.cookie || []; - const previewCookie = targetCookie.find((cookieObj) => { + return targetCookie.reduce((previewCookies, cookieObj) => { const cookieValue = cookie.parse(cookieObj.value); - return ( + if ( cookieValue[NEXT_PREVIEW_DATA_COOKIE] && cookieValue[NEXT_PRERENDER_BYPASS_COOKIE] - ); - }); - if (previewCookie) { - return cookie.parse(previewCookie.value) as { - [NEXT_PREVIEW_DATA_COOKIE]: string; - [NEXT_PRERENDER_BYPASS_COOKIE]: string; - }; - } else { - return { - [NEXT_PRERENDER_BYPASS_COOKIE]: "", - [NEXT_PREVIEW_DATA_COOKIE]: "" - }; - } + ) { + return cookieValue as typeof defaultPreviewCookies; + } else { + return previewCookies; + } + }, defaultPreviewCookies); }; const perfLogger = (logLambdaExecutionTimes: boolean): PerfLogger => {