From 641f40095e5138bcda6794e5c51fbe8fc0988e28 Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Tue, 26 Nov 2024 12:48:34 -0700 Subject: [PATCH 1/9] fix: metadata plugin export --- packages/gasket-plugin-metadata/lib/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/gasket-plugin-metadata/lib/index.d.ts b/packages/gasket-plugin-metadata/lib/index.d.ts index 824cd5057..49a7acc44 100644 --- a/packages/gasket-plugin-metadata/lib/index.d.ts +++ b/packages/gasket-plugin-metadata/lib/index.d.ts @@ -128,9 +128,9 @@ declare module '@gasket/core' { } } -const plugin: Plugin = { +export default { name: '@gasket/plugin-metadata', + version: '', + description: '', hooks: {} }; - -export = plugin; From 685c2ddd0aa852210ab71f6c58e28b6785f51d19 Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Tue, 26 Nov 2024 13:35:45 -0700 Subject: [PATCH 2/9] fix: server template --- packages/gasket-plugin-nextjs/generator/next/server.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/gasket-plugin-nextjs/generator/next/server.js b/packages/gasket-plugin-nextjs/generator/next/server.js index ff0a67b78..632655882 100644 --- a/packages/gasket-plugin-nextjs/generator/next/server.js +++ b/packages/gasket-plugin-nextjs/generator/next/server.js @@ -1,6 +1,5 @@ import gasket from './gasket.js'; -{{/if}} -{{#if nextDevProxy }} +{{#if nextDevProxy}} gasket.actions.startProxyServer(); {{else}} gasket.actions.startServer(); From e6518c69fd10847086a8a891bf6b3663a478fceb Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Tue, 26 Nov 2024 13:41:22 -0700 Subject: [PATCH 3/9] fix: align packages --- packages/gasket-plugin-command/package.json | 1 + packages/gasket-plugin-https-proxy/package.json | 8 +++++--- packages/gasket-plugin-metadata/package.json | 2 +- packages/gasket-request/package.json | 6 +++--- scripts/align-packages.js | 1 + 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/gasket-plugin-command/package.json b/packages/gasket-plugin-command/package.json index c45d67bfe..4d21dbf4a 100644 --- a/packages/gasket-plugin-command/package.json +++ b/packages/gasket-plugin-command/package.json @@ -3,6 +3,7 @@ "version": "7.0.15", "description": "Plugin to enable other plugins to inject new gasket commands", "type": "module", + "main": "lib/index.js", "types": "lib/index.d.ts", "files": [ "lib" diff --git a/packages/gasket-plugin-https-proxy/package.json b/packages/gasket-plugin-https-proxy/package.json index 8344b56b9..83613f584 100644 --- a/packages/gasket-plugin-https-proxy/package.json +++ b/packages/gasket-plugin-https-proxy/package.json @@ -2,12 +2,12 @@ "name": "@gasket/plugin-https-proxy", "version": "7.0.0-canary.0", "description": "Adds support for running an https proxy", + "type": "module", "main": "lib/index.js", "types": "lib/index.d.ts", "files": [ "lib" ], - "type": "module", "scripts": { "lint": "eslint .", "lint:fix": "npm run lint -- --fix", @@ -55,10 +55,12 @@ "eslintConfig": { "extends": [ "godaddy", - "plugin:jest/recommended" + "plugin:jest/recommended", + "plugin:jsdoc/recommended-typescript-flavor" ], "plugins": [ - "unicorn" + "unicorn", + "jsdoc" ], "rules": { "unicorn/filename-case": "error" diff --git a/packages/gasket-plugin-metadata/package.json b/packages/gasket-plugin-metadata/package.json index 1949e0fa5..a40b05972 100644 --- a/packages/gasket-plugin-metadata/package.json +++ b/packages/gasket-plugin-metadata/package.json @@ -2,12 +2,12 @@ "name": "@gasket/plugin-metadata", "version": "7.0.15", "description": "Adds metadata to gasket lifecycles", + "type": "module", "main": "lib/index.js", "types": "lib/index.d.ts", "files": [ "lib" ], - "type": "module", "scripts": { "lint": "eslint .", "lint:fix": "npm run lint -- --fix", diff --git a/packages/gasket-request/package.json b/packages/gasket-request/package.json index a1fa63168..8744b857d 100644 --- a/packages/gasket-request/package.json +++ b/packages/gasket-request/package.json @@ -28,10 +28,10 @@ "typecheck:watch": "tsc --watch", "build": "swc lib -d cjs --delete-dir-on-start --strip-leading-paths --out-file-extension cjs", "build:watch": "npm run build -- --watch", - "postbuild:replace": "replace '.js' '.cjs' cjs/*", - "postbuild:package": "node -e \"require('fs').writeFileSync('cjs/package.json', '{}')\"", "postbuild": "npm run postbuild:package && npm run postbuild:replace", - "prepublishOnly": "npm run build" + "prepublishOnly": "npm run build", + "postbuild:package": "node -e \"require('fs').writeFileSync('cjs/package.json', '{}')\"", + "postbuild:replace": "replace '.js' '.cjs' cjs/*" }, "repository": { "type": "git", diff --git a/scripts/align-packages.js b/scripts/align-packages.js index 0784d43bb..87f85743d 100644 --- a/scripts/align-packages.js +++ b/scripts/align-packages.js @@ -127,6 +127,7 @@ const scriptsOrder = [ 'typecheck:watch', 'build', 'build:watch', + 'postbuild', 'prepack', 'postpack', 'prepublish', From 8ec58984dfa1acc05dd26b5c8adf6bb41ed10578 Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Tue, 26 Nov 2024 15:09:37 -0700 Subject: [PATCH 4/9] fix: fixes and tune-up for next15 async request support --- .../lib/layout/with-gasket-data.js | 4 ++-- .../test/layout/with-gasket-data.test.js | 2 +- packages/gasket-request/lib/request.js | 5 +++-- packages/gasket-request/test/request.test.js | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/gasket-nextjs/lib/layout/with-gasket-data.js b/packages/gasket-nextjs/lib/layout/with-gasket-data.js index b690f95f6..046002572 100644 --- a/packages/gasket-nextjs/lib/layout/with-gasket-data.js +++ b/packages/gasket-nextjs/lib/layout/with-gasket-data.js @@ -1,4 +1,4 @@ -import { request } from '../server'; +import { request } from '../request'; import { injectGasketData } from '../inject-gasket-data.js' import NextScript from 'next/script'; @@ -29,7 +29,7 @@ function lookupIndex(bodyChildren, index = -1) { export function withGasketData(gasket, options = { index: -1 }) { const { index } = options; return layout => async props => { - const req = request(); + const req = await request(); const gasketData = req ? await gasket.actions.getPublicGasketData?.(req) ?? {} : {}; const html = await layout({ ...props }); return injectGasketData(html, gasketData, lookupIndex, index); diff --git a/packages/gasket-nextjs/test/layout/with-gasket-data.test.js b/packages/gasket-nextjs/test/layout/with-gasket-data.test.js index 086f49fb6..f92e1c91f 100644 --- a/packages/gasket-nextjs/test/layout/with-gasket-data.test.js +++ b/packages/gasket-nextjs/test/layout/with-gasket-data.test.js @@ -1,7 +1,7 @@ import { jest, expect } from '@jest/globals'; import { createElement, Children } from 'react'; -jest.unstable_mockModule('../../lib/server/request.js', () => ({ +jest.unstable_mockModule('../../lib/request/index.js', () => ({ request: jest.fn().mockReturnValue({}) })); diff --git a/packages/gasket-request/lib/request.js b/packages/gasket-request/lib/request.js index 051dab588..185a1a72c 100644 --- a/packages/gasket-request/lib/request.js +++ b/packages/gasket-request/lib/request.js @@ -5,6 +5,7 @@ import { WeakPromiseKeeper } from './keeper.js'; */ export class GasketRequest { constructor(normalizedRequest) { + console.log('normalizedRequest:', normalizedRequest); this.headers = normalizedRequest.headers; this.cookies = normalizedRequest.cookies; this.query = normalizedRequest.query; @@ -66,8 +67,8 @@ export async function makeGasketRequest(requestLike) { path ??= ''; return new GasketRequest(Object.seal({ - headers: headers.constructor.prototype.entries ? Object.fromEntries(headers.entries()) : headers, - cookies: cookies.constructor.prototype.getAll ? await objectFromCookieStore(cookies) : cookies, + headers: 'entries' in headers ? Object.fromEntries(headers.entries()) : headers, + cookies: 'getAll' in cookies ? await objectFromCookieStore(cookies) : cookies, query: query instanceof URLSearchParams ? Object.fromEntries(query) : query, path })); diff --git a/packages/gasket-request/test/request.test.js b/packages/gasket-request/test/request.test.js index 1fab3bfd8..5317db960 100644 --- a/packages/gasket-request/test/request.test.js +++ b/packages/gasket-request/test/request.test.js @@ -102,6 +102,23 @@ describe('makeGasketRequest', () => { expect(result.cookies).toEqual({ cookie1: 'value1', cookie2: 'value2' }); }); + it('handles cookie store shapes getAll', async () => { + const headers = new Map([['header1', 'value1'], ['header2', 'value2']]); + const cookieStore = { + getAll() { + return [ + { name: 'cookie1', value: 'value1' }, + { name: 'cookie2', value: 'value2' } + ]; + } + }; + const requestLike = { headers, cookies: cookieStore }; + + const result = await makeGasketRequest(requestLike); + + expect(result.cookies).toEqual({ cookie1: 'value1', cookie2: 'value2' }); + }); + it('handles no cookies', async () => { const headers = new Map([['header1', 'value1'], ['header2', 'value2']]); const requestLike = { headers }; From 3e24650211322291fb8b0a8966cc6e170c4c9ddc Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Tue, 26 Nov 2024 15:16:57 -0700 Subject: [PATCH 5/9] fix: clarify tests --- packages/gasket-request/test/request.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gasket-request/test/request.test.js b/packages/gasket-request/test/request.test.js index 5317db960..0bac03aed 100644 --- a/packages/gasket-request/test/request.test.js +++ b/packages/gasket-request/test/request.test.js @@ -89,7 +89,7 @@ describe('makeGasketRequest', () => { expect(result.query).toEqual({}); }); - it('handles CookieStore for cookies', async () => { + it('handles Next15 style CookieStore for cookies', async () => { const headers = new Map([['header1', 'value1'], ['header2', 'value2']]); const cookieStore = new MockCookieStore([ { name: 'cookie1', value: 'value1' }, @@ -102,7 +102,7 @@ describe('makeGasketRequest', () => { expect(result.cookies).toEqual({ cookie1: 'value1', cookie2: 'value2' }); }); - it('handles cookie store shapes getAll', async () => { + it('handles Next14 style CookieStore for cookies', async () => { const headers = new Map([['header1', 'value1'], ['header2', 'value2']]); const cookieStore = { getAll() { From 6028ded3a70fe46c551da46dbc7f54693309c4b6 Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Tue, 26 Nov 2024 15:47:17 -0700 Subject: [PATCH 6/9] fix: cleanup test console --- packages/gasket-request/lib/request.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/gasket-request/lib/request.js b/packages/gasket-request/lib/request.js index 185a1a72c..655950917 100644 --- a/packages/gasket-request/lib/request.js +++ b/packages/gasket-request/lib/request.js @@ -5,7 +5,6 @@ import { WeakPromiseKeeper } from './keeper.js'; */ export class GasketRequest { constructor(normalizedRequest) { - console.log('normalizedRequest:', normalizedRequest); this.headers = normalizedRequest.headers; this.cookies = normalizedRequest.cookies; this.query = normalizedRequest.query; From b4579bab61d8e702ee758eeaa2d80ea7a1bc2dec Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Wed, 27 Nov 2024 15:10:03 -0700 Subject: [PATCH 7/9] fix: correct req type order --- packages/gasket-request/lib/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gasket-request/lib/index.d.ts b/packages/gasket-request/lib/index.d.ts index 15a6664b1..1ba83708b 100644 --- a/packages/gasket-request/lib/index.d.ts +++ b/packages/gasket-request/lib/index.d.ts @@ -44,8 +44,8 @@ export class WeakPromiseKeeper { */ export async function makeGasketRequest(req: RequestLike): Promise; -type RequestActionFn> = (gasket: Gasket, req: RequestLike, ...args: Args) => Promise; -type RequestActionWrapperFn> = (gasket: Gasket, req: GasketRequest, ...args: Args) => Promise; +type RequestActionFn> = (gasket: Gasket, req: GasketRequest, ...args: Args) => Promise; +type RequestActionWrapperFn> = (gasket: Gasket, req: RequestLike, ...args: Args) => Promise; export function withGasketRequest>(actionFn: RequestActionFn): RequestActionWrapperFn; export function withGasketRequestCache>(actionFn: RequestActionFn): RequestActionWrapperFn; From d255bd12d2d326049564dba5aef6e6db1202e429 Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Mon, 2 Dec 2024 15:47:16 -0700 Subject: [PATCH 8/9] fix: align dep versions --- packages/gasket-preset-nextjs/lib/preset-config.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/gasket-preset-nextjs/lib/preset-config.js b/packages/gasket-preset-nextjs/lib/preset-config.js index aaafe308d..936c21f76 100644 --- a/packages/gasket-preset-nextjs/lib/preset-config.js +++ b/packages/gasket-preset-nextjs/lib/preset-config.js @@ -28,9 +28,7 @@ export default async function presetConfig(gasket, context) { plugins.push(pluginHttps); plugins.push(frameworkPlugin.default || frameworkPlugin); - } - - if (context.nextDevProxy) { + } else if (context.nextDevProxy) { plugins.push(pluginHttpsProxy); } From 3426d93a315bffa956c9c8f35120e0726e9eed53 Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Thu, 5 Dec 2024 18:04:17 -0700 Subject: [PATCH 9/9] fix: handle URLSearchParams array values --- packages/gasket-request/lib/index.d.ts | 7 +++++++ packages/gasket-request/lib/request.js | 15 ++++++++++++++- packages/gasket-request/test/request.test.js | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/gasket-request/lib/index.d.ts b/packages/gasket-request/lib/index.d.ts index 1ba83708b..f2c212787 100644 --- a/packages/gasket-request/lib/index.d.ts +++ b/packages/gasket-request/lib/index.d.ts @@ -15,6 +15,13 @@ export type RequestLike = { */ async function objectFromCookieStore(cookieStore: CookieStore): Promise>; +/** + * Capture the search params as a key/value object + * Necessary to capture array values + * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams + */ +async function objectFromSearchParams(searchParams: URLSearchParams): Record; + /** * Expected request shape for GasketActions */ diff --git a/packages/gasket-request/lib/request.js b/packages/gasket-request/lib/request.js index 655950917..767123023 100644 --- a/packages/gasket-request/lib/request.js +++ b/packages/gasket-request/lib/request.js @@ -28,6 +28,19 @@ async function objectFromCookieStore(cookieStore) { }, {}); } +/** + * @type {import('./index.js').objectFromSearchParams} + */ +function objectFromSearchParams(searchParams) { + const entries = Object.fromEntries(searchParams); + const keys = Object.keys(entries); + return keys.reduce((acc, key) => { + const value = searchParams.getAll(key); + acc[key] = value.length === 1 ? value[0] : value; + return acc; + }, {}); +} + /** * @type {import('./index.js').makeGasketRequest} */ @@ -68,7 +81,7 @@ export async function makeGasketRequest(requestLike) { return new GasketRequest(Object.seal({ headers: 'entries' in headers ? Object.fromEntries(headers.entries()) : headers, cookies: 'getAll' in cookies ? await objectFromCookieStore(cookies) : cookies, - query: query instanceof URLSearchParams ? Object.fromEntries(query) : query, + query: query instanceof URLSearchParams ? objectFromSearchParams(query) : query, path })); }; diff --git a/packages/gasket-request/test/request.test.js b/packages/gasket-request/test/request.test.js index 0bac03aed..1e993922e 100644 --- a/packages/gasket-request/test/request.test.js +++ b/packages/gasket-request/test/request.test.js @@ -80,6 +80,22 @@ describe('makeGasketRequest', () => { expect(result.query).toEqual({ query1: 'value1', query2: 'value2' }); }); + it('handles URLSearchParams array values', async () => { + const headers = new Map([['header1', 'value1'], ['header2', 'value2']]); + const query = new URLSearchParams({ query1: 'value1', query2: 'value2' }); + query.append('query3', 'value3'); + query.append('query3', 'value4'); + const requestLike = { headers, cookies: {}, query }; + + const result = await makeGasketRequest(requestLike); + + expect(result.query).toEqual({ + query1: 'value1', + query2: 'value2', + query3: ['value3', 'value4'] + }); + }); + it('handles no query', async () => { const headers = new Map([['header1', 'value1'], ['header2', 'value2']]); const requestLike = { headers, cookies: {} };