From 95f3be9348b1021b34592992e910ba5de93ee8c0 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Fri, 13 Oct 2023 18:18:11 -0500 Subject: [PATCH 01/17] Add SDK deps --- package.json | 1 + yarn.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/package.json b/package.json index 45b5cf34..03652d04 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@aws-sdk/client-secrets-manager": "^3.428.0", "@xylabs/assert": "^2.12.24", "@xylabs/delay": "^2.12.24", + "@xylabs/exists": "^2.12.24", "@xylabs/forget": "^2.12.24", "@xylabs/sdk-api-express-ecs": "^1.4.0", "@xyo-network/account": "^2.76.0", diff --git a/yarn.lock b/yarn.lock index 8d3fbb94..75d8c7fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4726,6 +4726,7 @@ __metadata: "@xylabs/delay": ^2.12.24 "@xylabs/eslint-config": ^3.1.9 "@xylabs/eslint-config-react": ^3.1.9 + "@xylabs/exists": ^2.12.24 "@xylabs/forget": ^2.12.24 "@xylabs/jest-helpers": ^2.12.24 "@xylabs/sdk-api-express-ecs": ^1.4.0 From 0166ffc135b0f3b8bb91c34cb417b3a7a923a1ae Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Fri, 13 Oct 2023 18:22:47 -0500 Subject: [PATCH 02/17] Placeholder for helmet handler and config --- .../foreventory/configureForeventory.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts index cd6fed0f..d4628fed 100644 --- a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts +++ b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts @@ -1,5 +1,6 @@ import { assertEx } from '@xylabs/assert' import { delay } from '@xylabs/delay' +import { exists } from '@xylabs/exists' import { asyncHandler } from '@xylabs/sdk-api-express-ecs' import { RequestHandler } from 'express' import { existsSync, readFileSync } from 'fs' @@ -105,6 +106,19 @@ const imageHandler: RequestHandler = asyncHandler(async (req, res, next) => { next() }) +const getXyConfigHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware | undefined => { + const filePath = join(opts.baseDir, 'xy.config.json') + if (existsSync(filePath)) { + // Read file in + const xyConfig = readFileSync(filePath, { encoding: 'utf-8' }) + // TODO: Validate xyConfig + // TODO: Create regex from config + // TODO: Write helmet handler + return ['get', ['/*', (req, res, next) => next()]] + } + return undefined +} + /** * Middleware for augmenting HTML metadata for Foreventory shares */ @@ -114,4 +128,5 @@ const foreventorySharePageHandler = (opts: ApplicationMiddlewareOptions): MountP ] const foreventoryImageHandler = (): MountPathAndMiddleware => ['get', ['/netflix/insights/:hash/preview/:width/:height/img.png', imageHandler]] -export const foreventoryHandlers = (opts: ApplicationMiddlewareOptions) => [foreventorySharePageHandler(opts), foreventoryImageHandler()] +export const foreventoryHandlers = (opts: ApplicationMiddlewareOptions) => + [foreventorySharePageHandler(opts), foreventoryImageHandler(), getXyConfigHandler(opts)].filter(exists) From 8f022f04ec3c2e9c24726cc96e6e1eb262e5200a Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Sat, 14 Oct 2023 10:56:38 -0500 Subject: [PATCH 03/17] Add path-to-regexp for translating glob patterns --- package.json | 1 + yarn.lock | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/package.json b/package.json index 03652d04..9ecc4e34 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "lru-cache": "^10.0.1", "mime": "^3.0.0", "node-cache": "^5.1.2", + "path-to-regexp": "^6.2.1", "puppeteer": "^21.3.8", "rollbar": "^2.26.2", "serve-static": "^1.15.0", diff --git a/yarn.lock b/yarn.lock index 75d8c7fa..6ee8f735 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4761,6 +4761,7 @@ __metadata: mime: ^3.0.0 node-cache: ^5.1.2 nodemon: ^3.0.1 + path-to-regexp: ^6.2.1 puppeteer: ^21.3.8 rollbar: ^2.26.2 serve-static: ^1.15.0 @@ -14417,6 +14418,13 @@ __metadata: languageName: node linkType: hard +"path-to-regexp@npm:^6.2.1": + version: 6.2.1 + resolution: "path-to-regexp@npm:6.2.1" + checksum: f0227af8284ea13300f4293ba111e3635142f976d4197f14d5ad1f124aebd9118783dd2e5f1fe16f7273743cc3dbeddfb7493f237bb27c10fdae07020cc9b698 + languageName: node + linkType: hard + "path-type@npm:^3.0.0": version: 3.0.0 resolution: "path-type@npm:3.0.0" From f5127ec6a67b7aeae23cc41560da4dcf1ba53d1f Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Sat, 14 Oct 2023 11:11:02 -0500 Subject: [PATCH 04/17] Match glob include/exclude arrays --- cspell.config.yaml | 1 + .../foreventory/configureForeventory.ts | 45 ++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/cspell.config.yaml b/cspell.config.yaml index f1a16d02..4cb8fb17 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -19,6 +19,7 @@ words: - pako - printenv - proxied + - regexes - repost - sandboxing - snyk diff --git a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts index d4628fed..55ba815a 100644 --- a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts +++ b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts @@ -6,6 +6,7 @@ import { RequestHandler } from 'express' import { existsSync, readFileSync } from 'fs' import { ReasonPhrases, StatusCodes } from 'http-status-codes' import { extname, join } from 'path' +import { pathToRegexp } from 'path-to-regexp' import { getAdjustedPath, getUriBehindProxy, preCacheFacebookShare } from '../../lib' import { ApplicationMiddlewareOptions, MountPathAndMiddleware } from '../../types' @@ -35,6 +36,22 @@ const maxImageGenerationWait = 8000 const imageCache = getImageCache() +/** + * Function which checks if a route matches any of the included glob patterns + */ +type RouteMatcher = (route: string) => boolean + +/** + * Higher order function which creates precompiled RegEx matchers + * from a list of Glob Patterns + * @param patterns Glob patterns for route paths to match against + * @returns + */ +const createMatcher = (patterns: string[]): RouteMatcher => { + const regexes = patterns.map((pattern) => pathToRegexp(pattern)) + return (route: string) => regexes.some((regex) => regex.test(route)) +} + const getPageHandler = (baseDir: string) => { // Ensure file containing base HTML exists const filePath = join(baseDir, 'index.html') @@ -107,16 +124,30 @@ const imageHandler: RequestHandler = asyncHandler(async (req, res, next) => { }) const getXyConfigHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware | undefined => { - const filePath = join(opts.baseDir, 'xy.config.json') + const { baseDir } = opts + const filePath = join(baseDir, 'xy.config.json') if (existsSync(filePath)) { - // Read file in - const xyConfig = readFileSync(filePath, { encoding: 'utf-8' }) + // Read in config file + const xyConfig = JSON.parse(readFileSync(filePath, { encoding: 'utf-8' })) // TODO: Validate xyConfig - // TODO: Create regex from config - // TODO: Write helmet handler - return ['get', ['/*', (req, res, next) => next()]] + if (xyConfig.liveShare) { + const { include, exclude } = xyConfig.liveShare + const matchesIncluded: RouteMatcher = include ? createMatcher(include) : () => true + const matchesExcluded: RouteMatcher = exclude ? createMatcher(exclude) : () => false + + const handler: RequestHandler = asyncHandler(async (req, res, next) => { + const adjustedPath = getAdjustedPath(req) + await Promise.resolve() + if (matchesIncluded(adjustedPath) && !matchesExcluded(adjustedPath)) { + // TODO: Grab helmet head data + } else { + next() + } + }) + return ['get', ['/*', handler]] + } + return undefined } - return undefined } /** From 706d251912a76a2835de310e64d9ebcbaf4d6e84 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Sat, 14 Oct 2023 11:39:03 -0500 Subject: [PATCH 05/17] Bump node version, use Nodemon --- nodemon.json | 9 +++++++++ package.json | 23 ++++++++++++----------- yarn.lock | 6 +++--- 3 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 nodemon.json diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 00000000..8ed9ba8f --- /dev/null +++ b/nodemon.json @@ -0,0 +1,9 @@ +{ + "env": { + "NODE_ENV": "development" + }, + "exec": "ts-node-script ./src/bin/start-meta.ts", + "ext": ".ts", + "ignore": ["**/*.spec.ts"], + "watch": ["./src"] +} diff --git a/package.json b/package.json index 9ecc4e34..8a32c7f5 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,9 @@ "url": "https://github.com/xylabs/sdk-meta-server-nodejs/issues" }, "bin": { - "docker-build": "dist/cjs/bin/docker-build.js", - "generate-dotenv": "dist/cjs/bin/generate-dotenv.js", - "start-meta": "dist/cjs/bin/start-meta.js" + "docker-build": "dist/node/bin/docker-build.js", + "generate-dotenv": "dist/node/bin/generate-dotenv.js", + "start-meta": "dist/node/bin/start-meta.js" }, "dependencies": { "@aws-sdk/client-secrets-manager": "^3.428.0", @@ -83,12 +83,12 @@ ".": { "node": { "require": { - "types": "./dist/node/index.d.ts", - "default": "./dist/node/index.js" + "types": "./dist/node/index.d.cts", + "default": "./dist/node/index.cjs" }, "import": { "types": "./dist/node/index.d.mts", - "default": "./dist/node/index.mjs" + "default": "./dist/node/index.js" } } }, @@ -97,8 +97,8 @@ }, "./package.json": "./package.json" }, - "main": "dist/node/index.js", - "module": "dist/node/index.mjs", + "main": "dist/node/index.cjs", + "module": "dist/node/index.js", "homepage": "https://xylabs.com", "keywords": [ "xylabs", @@ -126,7 +126,7 @@ }, "scripts": { "coverage": "yarn jest --coverage", - "start": "node dist/cjs/bin/start-meta.js", + "start": "nodemon", "test": "yarn jest" }, "sideEffects": false, @@ -136,8 +136,9 @@ "node": ">=18.13.0" }, "volta": { - "node": "18.13.0", + "node": "18.17.1", "yarn": "1.22.19" }, - "packageManager": "yarn@3.6.1" + "packageManager": "yarn@3.6.1", + "type": "module" } diff --git a/yarn.lock b/yarn.lock index 6ee8f735..2cef68e8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4775,9 +4775,9 @@ __metadata: peerDependencies: axios: ^1 bin: - docker-build: dist/cjs/bin/docker-build.js - generate-dotenv: dist/cjs/bin/generate-dotenv.js - start-meta: dist/cjs/bin/start-meta.js + docker-build: dist/node/bin/docker-build.js + generate-dotenv: dist/node/bin/generate-dotenv.js + start-meta: dist/node/bin/start-meta.js languageName: unknown linkType: soft From 3bdb0b2ce291de678234cc31d8d970029a09816d Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Sat, 14 Oct 2023 11:39:14 -0500 Subject: [PATCH 06/17] Add outfiles for launch profile --- .vscode/launch.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 926e0600..5c44bb5b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,9 @@ "request": "launch", "name": "Debug", "program": "${workspaceFolder}/src/bin/start-meta.ts", - "outFiles": ["${workspaceFolder}/dist/**/*.js"], + "outFiles": [ + "${workspaceFolder}/dist/**/*.js" + ], "env": { "NODE_OPTIONS": "-r ts-node/register --loader ts-node/esm --max-old-space-size=8192" }, From fd27c420c698105a58155e64427994a5f0144ad0 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Sat, 14 Oct 2023 12:00:11 -0500 Subject: [PATCH 07/17] Start CJS/ESM commands --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 8a32c7f5..6df36b5f 100644 --- a/package.json +++ b/package.json @@ -127,6 +127,8 @@ "scripts": { "coverage": "yarn jest --coverage", "start": "nodemon", + "start-cjs": "node ./dist/node/bin/start-meta.js", + "start-esm": "node ./dist/node/bin/start-meta.mjs", "test": "yarn jest" }, "sideEffects": false, From 7cc4ffd9753458dbd7ab1b96c8512231c447edb6 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Sat, 14 Oct 2023 12:02:15 -0500 Subject: [PATCH 08/17] Comment out handler for now --- .../foreventory/configureForeventory.ts | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts index 55ba815a..5008164b 100644 --- a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts +++ b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts @@ -123,32 +123,33 @@ const imageHandler: RequestHandler = asyncHandler(async (req, res, next) => { next() }) -const getXyConfigHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware | undefined => { - const { baseDir } = opts - const filePath = join(baseDir, 'xy.config.json') - if (existsSync(filePath)) { - // Read in config file - const xyConfig = JSON.parse(readFileSync(filePath, { encoding: 'utf-8' })) - // TODO: Validate xyConfig - if (xyConfig.liveShare) { - const { include, exclude } = xyConfig.liveShare - const matchesIncluded: RouteMatcher = include ? createMatcher(include) : () => true - const matchesExcluded: RouteMatcher = exclude ? createMatcher(exclude) : () => false +// const liveShareHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware | undefined => { +// const { baseDir } = opts +// const filePath = join(baseDir, 'xy.config.json') +// if (existsSync(filePath)) { +// // Read in config file +// const xyConfig = JSON.parse(readFileSync(filePath, { encoding: 'utf-8' })) +// // TODO: Validate xyConfig +// if (xyConfig.liveShare) { +// const { include, exclude } = xyConfig.liveShare +// const matchesIncluded: RouteMatcher = include ? createMatcher(include) : () => true +// const matchesExcluded: RouteMatcher = exclude ? createMatcher(exclude) : () => false - const handler: RequestHandler = asyncHandler(async (req, res, next) => { - const adjustedPath = getAdjustedPath(req) - await Promise.resolve() - if (matchesIncluded(adjustedPath) && !matchesExcluded(adjustedPath)) { - // TODO: Grab helmet head data - } else { - next() - } - }) - return ['get', ['/*', handler]] - } - return undefined - } -} +// const handler: RequestHandler = asyncHandler(async (req, res, next) => { +// const adjustedPath = getAdjustedPath(req) +// await Promise.resolve() +// if (matchesIncluded(adjustedPath) && !matchesExcluded(adjustedPath)) { +// // TODO: Grab helmet head data, next for now +// next() +// } else { +// next() +// } +// }) +// return ['get', ['/*', handler]] +// } +// return undefined +// } +// } /** * Middleware for augmenting HTML metadata for Foreventory shares @@ -160,4 +161,5 @@ const foreventorySharePageHandler = (opts: ApplicationMiddlewareOptions): MountP const foreventoryImageHandler = (): MountPathAndMiddleware => ['get', ['/netflix/insights/:hash/preview/:width/:height/img.png', imageHandler]] export const foreventoryHandlers = (opts: ApplicationMiddlewareOptions) => - [foreventorySharePageHandler(opts), foreventoryImageHandler(), getXyConfigHandler(opts)].filter(exists) + // [foreventorySharePageHandler(opts), foreventoryImageHandler(), liveShareHandler(opts)].filter(exists) + [foreventorySharePageHandler(opts), foreventoryImageHandler()].filter(exists) From 725b1aba1ccb33475ab8a3d6679b66bd8d52e63b Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Mon, 16 Oct 2023 10:09:25 -0700 Subject: [PATCH 09/17] build fixed --- package.json | 21 +- .../archivistBlock/lib/setHtmlMetaData.ts | 2 +- .../lib/file/isKnownFileExtension.ts | 4 +- xy.config.ts | 3 +- yarn.lock | 179 ++++++++++-------- 5 files changed, 112 insertions(+), 97 deletions(-) diff --git a/package.json b/package.json index 6df36b5f..af149808 100644 --- a/package.json +++ b/package.json @@ -60,11 +60,11 @@ "@xylabs/eslint-config": "^3.1.9", "@xylabs/eslint-config-react": "^3.1.9", "@xylabs/jest-helpers": "^2.12.24", - "@xylabs/ts-scripts-yarn3": "^3.1.9", - "@xylabs/tsconfig": "^3.1.9", - "@xylabs/tsconfig-dom": "^3.1.9", - "@xylabs/tsconfig-dom-jest": "^3.1.9", - "@xylabs/tsconfig-jest": "^3.1.9", + "@xylabs/ts-scripts-yarn3": "^3.1.12", + "@xylabs/tsconfig": "^3.1.12", + "@xylabs/tsconfig-dom": "^3.1.12", + "@xylabs/tsconfig-dom-jest": "^3.1.12", + "@xylabs/tsconfig-jest": "^3.1.12", "axios": "^1.5.1", "eslint": "^8.51.0", "jest": "^29.7.0", @@ -84,7 +84,7 @@ "node": { "require": { "types": "./dist/node/index.d.cts", - "default": "./dist/node/index.cjs" + "default": "./dist/node/index.js" }, "import": { "types": "./dist/node/index.d.mts", @@ -97,8 +97,8 @@ }, "./package.json": "./package.json" }, - "main": "dist/node/index.cjs", - "module": "dist/node/index.js", + "main": "dist/node/index.js", + "module": "dist/node/index.mjs", "homepage": "https://xylabs.com", "keywords": [ "xylabs", @@ -141,6 +141,5 @@ "node": "18.17.1", "yarn": "1.22.19" }, - "packageManager": "yarn@3.6.1", - "type": "module" -} + "packageManager": "yarn@3.6.1" +} \ No newline at end of file diff --git a/src/modules/metaServer/contentHandlers/archivistBlock/lib/setHtmlMetaData.ts b/src/modules/metaServer/contentHandlers/archivistBlock/lib/setHtmlMetaData.ts index 2fb54c07..518f432e 100644 --- a/src/modules/metaServer/contentHandlers/archivistBlock/lib/setHtmlMetaData.ts +++ b/src/modules/metaServer/contentHandlers/archivistBlock/lib/setHtmlMetaData.ts @@ -1,7 +1,7 @@ +import { cloneDeep } from '@xylabs/lodash' import { BoundWitnessSchema } from '@xyo-network/boundwitness-model' import { PayloadWrapper } from '@xyo-network/payload-wrapper' import { Meta, metaBuilder } from '@xyo-network/sdk-meta' -import cloneDeep from 'lodash/cloneDeep' import { getArchivistForDomain } from '../../../lib' import { PayloadInfo } from '../../../types' diff --git a/src/modules/metaServer/lib/file/isKnownFileExtension.ts b/src/modules/metaServer/lib/file/isKnownFileExtension.ts index 4fc6167f..9672ee82 100644 --- a/src/modules/metaServer/lib/file/isKnownFileExtension.ts +++ b/src/modules/metaServer/lib/file/isKnownFileExtension.ts @@ -1,7 +1,7 @@ -import { getType } from 'mime' +import mime from 'mime' export const isKnownFileExtension = (filePath: string): boolean => { // const extension = extname(filePath).toLowerCase() // return knownFileExtensions[extension] ?? false - return getType(filePath) ? true : false + return mime.getType(filePath) ? true : false } diff --git a/xy.config.ts b/xy.config.ts index 9482f6a2..90e9cff6 100644 --- a/xy.config.ts +++ b/xy.config.ts @@ -4,8 +4,9 @@ const config: XyTsupConfig = { browser: { src: false, }, + entryMode: 'all', node: { - src: true, + src: {}, }, }, } diff --git a/yarn.lock b/yarn.lock index 2cef68e8..d400a833 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2942,7 +2942,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.13, @jridgewell/sourcemap-codec@npm:^1.4.15": +"@jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.15": version: 1.4.15 resolution: "@jridgewell/sourcemap-codec@npm:1.4.15" checksum: b881c7e503db3fc7f3c1f35a1dd2655a188cc51a3612d76efc8a6eb74728bef5606e6758ee77423e564092b4a518aba569bbb21c9bac5ab7a35b0c6ae7e344c8 @@ -3160,26 +3160,26 @@ __metadata: languageName: node linkType: hard -"@rollup/plugin-commonjs@npm:^25.0.4": - version: 25.0.5 - resolution: "@rollup/plugin-commonjs@npm:25.0.5" +"@rollup/plugin-commonjs@npm:^25.0.7": + version: 25.0.7 + resolution: "@rollup/plugin-commonjs@npm:25.0.7" dependencies: "@rollup/pluginutils": ^5.0.1 commondir: ^1.0.1 estree-walker: ^2.0.2 glob: ^8.0.3 is-reference: 1.2.1 - magic-string: ^0.27.0 + magic-string: ^0.30.3 peerDependencies: rollup: ^2.68.0||^3.0.0||^4.0.0 peerDependenciesMeta: rollup: optional: true - checksum: 37cb6ce5188448250c2a97775c5879814119ff9fb3576d35089b7c00fed1a2b46b78d74a1377027cca26d0d984cfe99f450bfc0da561d596447ab6064adb4f08 + checksum: 052e11839a9edc556eda5dcc759ab816dcc57e9f0f905a1e6e14fff954eaa6b1e2d0d544f5bd18d863993c5eba43d8ac9c19d9bb53b1c3b1213f32cfc9d50b2e languageName: node linkType: hard -"@rollup/plugin-json@npm:^6.0.0": +"@rollup/plugin-json@npm:^6.0.1": version: 6.0.1 resolution: "@rollup/plugin-json@npm:6.0.1" dependencies: @@ -3193,7 +3193,7 @@ __metadata: languageName: node linkType: hard -"@rollup/plugin-typescript@npm:^11.1.4": +"@rollup/plugin-typescript@npm:^11.1.5": version: 11.1.5 resolution: "@rollup/plugin-typescript@npm:11.1.5" dependencies: @@ -4092,12 +4092,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:^20.7.2, @types/node@npm:^20.8.4, @types/node@npm:^20.8.5": - version: 20.8.5 - resolution: "@types/node@npm:20.8.5" +"@types/node@npm:*, @types/node@npm:^20.8.5, @types/node@npm:^20.8.6": + version: 20.8.6 + resolution: "@types/node@npm:20.8.6" dependencies: undici-types: ~5.25.1 - checksum: 4bca4e4f6307a6f5dc78812015eca9c5a998b35fcf3ba4058c9851d3dde2b22c914fa25a85b804eab5af2ab95375d15943dce8e9ba5e01d15f4bf516ca0d2816 + checksum: ccfb7ac482c5a96edeb239893c5c099f5257fcc2ed9ae62fefdfbc782b79e16dbc2af9a85b379665237bf759904b44ca2be68e75d239e0297882aad42f61905c languageName: node linkType: hard @@ -4222,7 +4222,7 @@ __metadata: languageName: node linkType: hard -"@types/yargs@npm:^17.0.26, @types/yargs@npm:^17.0.8": +"@types/yargs@npm:^17.0.28, @types/yargs@npm:^17.0.8": version: 17.0.28 resolution: "@types/yargs@npm:17.0.28" dependencies: @@ -4264,7 +4264,7 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:^6.7.3": +"@typescript-eslint/eslint-plugin@npm:^6.7.3, @typescript-eslint/eslint-plugin@npm:^6.7.5": version: 6.7.5 resolution: "@typescript-eslint/eslint-plugin@npm:6.7.5" dependencies: @@ -4317,7 +4317,7 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/parser@npm:^6.7.3": +"@typescript-eslint/parser@npm:^6.7.3, @typescript-eslint/parser@npm:^6.7.5": version: 6.7.5 resolution: "@typescript-eslint/parser@npm:6.7.5" dependencies: @@ -4730,11 +4730,11 @@ __metadata: "@xylabs/forget": ^2.12.24 "@xylabs/jest-helpers": ^2.12.24 "@xylabs/sdk-api-express-ecs": ^1.4.0 - "@xylabs/ts-scripts-yarn3": ^3.1.9 - "@xylabs/tsconfig": ^3.1.9 - "@xylabs/tsconfig-dom": ^3.1.9 - "@xylabs/tsconfig-dom-jest": ^3.1.9 - "@xylabs/tsconfig-jest": ^3.1.9 + "@xylabs/ts-scripts-yarn3": ^3.1.12 + "@xylabs/tsconfig": ^3.1.12 + "@xylabs/tsconfig-dom": ^3.1.12 + "@xylabs/tsconfig-dom-jest": ^3.1.12 + "@xylabs/tsconfig-jest": ^3.1.12 "@xyo-network/account": ^2.76.0 "@xyo-network/archivist-model": ^2.76.0 "@xyo-network/axios": ^2.76.0 @@ -4813,40 +4813,42 @@ __metadata: languageName: node linkType: hard -"@xylabs/ts-scripts-yarn3@npm:^3.1.9": - version: 3.1.9 - resolution: "@xylabs/ts-scripts-yarn3@npm:3.1.9" +"@xylabs/ts-scripts-yarn3@npm:^3.1.12": + version: 3.1.12 + resolution: "@xylabs/ts-scripts-yarn3@npm:3.1.12" dependencies: - "@rollup/plugin-commonjs": ^25.0.4 - "@rollup/plugin-json": ^6.0.0 - "@rollup/plugin-typescript": ^11.1.4 - "@types/node": ^20.7.2 - "@types/yargs": ^17.0.26 - "@typescript-eslint/eslint-plugin": ^6.7.3 - "@typescript-eslint/parser": ^6.7.3 - "@xylabs/tsconfig": ~3.1.9 + "@rollup/plugin-commonjs": ^25.0.7 + "@rollup/plugin-json": ^6.0.1 + "@rollup/plugin-typescript": ^11.1.5 + "@types/node": ^20.8.6 + "@types/yargs": ^17.0.28 + "@typescript-eslint/eslint-plugin": ^6.7.5 + "@typescript-eslint/parser": ^6.7.5 + "@xylabs/tsconfig": ~3.1.12 + async-mutex: ^0.4.0 chalk: ^4.1.2 cosmiconfig: ^8.3.6 + cosmiconfig-typescript-loader: ^5.0.0 cpy: ^8.1.2 depcheck: ^1.4.6 - eslint: ^8.50.0 + eslint: ^8.51.0 eslint-config-prettier: ^9.0.0 - eslint-plugin-prettier: ^5.0.0 + eslint-plugin-prettier: ^5.0.1 eslint-plugin-sonarjs: ^0.21.0 glob: ^10.3.10 jest: ^29.7.0 - jest-extended: ^4.0.1 + jest-extended: ^4.0.2 jest-mock-extended: ^3.0.5 jest-sorted: ^1.0.14 license-checker: ^25.0.1 lodash: ^4.17.21 node-cmd: ^5.0.0 - npm-check-updates: ^16.14.4 + npm-check-updates: ^16.14.6 npm-package-json-lint: ^7.0.0 npm-package-json-lint-config-default: ^6.0.0 parse-git-config: ^3.0.0 prettier: ^3.0.3 - publint: ^0.2.3 + publint: ^0.2.4 reflect-metadata: ^0.1.13 rimraf: ^4.4.1 rollup: ^3.29.4 @@ -4859,7 +4861,7 @@ __metadata: tsc-prog: ^2.3.0 tslib: ^2.6.2 tsup: ^7.2.0 - typedoc: ^0.25.1 + typedoc: ^0.25.2 types-package-json: ^2.0.39 yargs: ^17.7.2 peerDependencies: @@ -4910,50 +4912,50 @@ __metadata: xy: dist/bin/xy.js xy-ts: src/bin/xy-ts.ts yarn3only: dist/bin/yarn3only.js - checksum: 2bb1beb1bdd1be1243747c61c1324eae569a9754a642edbf8c90bedf34b1d40f1c9f85609c75b41ecef315eda0aa0a44bd8d165478de0705840dbe7d8e40a8c4 + checksum: 9f56757671cd20727e11fa6a201916d4bbad51b806dff2be6b636b85b509bdfa6facf7c12c0b3d8c8d4a19bea7740320950d9eca4f05431673d4cfa4f3cae105 languageName: node linkType: hard -"@xylabs/tsconfig-dom-jest@npm:^3.1.9": - version: 3.1.9 - resolution: "@xylabs/tsconfig-dom-jest@npm:3.1.9" +"@xylabs/tsconfig-dom-jest@npm:^3.1.12": + version: 3.1.12 + resolution: "@xylabs/tsconfig-dom-jest@npm:3.1.12" dependencies: "@types/jest": ^29.5.5 - "@types/node": ^20.8.4 + "@types/node": ^20.8.6 "@types/reflect-metadata": ^0.1.0 - "@xylabs/tsconfig-dom": ~3.1.9 - jest-extended: ^4.0.1 + "@xylabs/tsconfig-dom": ~3.1.12 + jest-extended: ^4.0.2 jest-sorted: ^1.0.14 - checksum: 45e5fd18b6348af3a4728683313dbe057986b9aad0ef258b69e2fa2a891d36befc54fe931077a9809836ec2d3c7e31c79774a8fa0b2702e88a66e94ea6788a5d + checksum: e84550a97acac2e19921e4f1c4c9321b27d00a8f721374a47a24b0c3d7ab2a44074a5339c974f65e4f97c9a73894ef45fe8d8d198a1dbaec0418961cedabed1d languageName: node linkType: hard -"@xylabs/tsconfig-dom@npm:^3.1.9, @xylabs/tsconfig-dom@npm:~3.1.9": - version: 3.1.9 - resolution: "@xylabs/tsconfig-dom@npm:3.1.9" +"@xylabs/tsconfig-dom@npm:^3.1.12, @xylabs/tsconfig-dom@npm:~3.1.12": + version: 3.1.12 + resolution: "@xylabs/tsconfig-dom@npm:3.1.12" dependencies: - "@xylabs/tsconfig": ~3.1.9 - checksum: dcecf95d1beac2ddc6a38d39373eae9e5c01191f780b696edf63d416f9ca383f950e14f6add8fc2f115fc96f6bd4c63c52e7836e403821ef296a859391789dc9 + "@xylabs/tsconfig": ~3.1.12 + checksum: 0d747bb5966943b9e3ab8e0ab84359557026a371c450ef89347c70a6d3c447dcfb62a75c6c89119db95ba70435fd8e5bfaafb1f63a712eacf391d96bbf54ceea languageName: node linkType: hard -"@xylabs/tsconfig-jest@npm:^3.1.9": - version: 3.1.9 - resolution: "@xylabs/tsconfig-jest@npm:3.1.9" +"@xylabs/tsconfig-jest@npm:^3.1.12": + version: 3.1.12 + resolution: "@xylabs/tsconfig-jest@npm:3.1.12" dependencies: - "@xylabs/tsconfig": ~3.1.9 - jest-extended: ^4.0.1 + "@xylabs/tsconfig": ~3.1.12 + jest-extended: ^4.0.2 jest-sorted: ^1.0.14 peerDependencies: typescript: ^5 - checksum: 339883caf740ce7c3d694d819ca71e02bdc70aa070daca12beb6b73ace520db7d7b7bfeff64e977f7f04b80ecc2892fb06d3160ac642de3c6ed4fb90e977fc30 + checksum: 937a20ba56dc5ff08631d4b09b05f8caa24b7408818ffb4f3c7c71f446ad39f9d83c0ad4c6bcf87c886b8e119d5db2a06996b5446e669b06c7970b228190d3ca languageName: node linkType: hard -"@xylabs/tsconfig@npm:^3.1.9, @xylabs/tsconfig@npm:~3.1.9": - version: 3.1.9 - resolution: "@xylabs/tsconfig@npm:3.1.9" - checksum: b85349b901a5986833ea9f30e580a2ae828a3e9a7282306c72438ef1a6a222ad46ac562eb5cb1e1a889c6b7ac6463b6ba15b3065cb3e5e9f9996e8429471dad7 +"@xylabs/tsconfig@npm:^3.1.12, @xylabs/tsconfig@npm:~3.1.12": + version: 3.1.12 + resolution: "@xylabs/tsconfig@npm:3.1.12" + checksum: 51bba0fb62461416b459f17bc21db3ded4964c87380b21f1a2a6974a5645b351a9d3a237f8f513829fd8978c3c6bf73c1e63598faac26bb0405bad9069b89a79 languageName: node linkType: hard @@ -7453,6 +7455,19 @@ __metadata: languageName: node linkType: hard +"cosmiconfig-typescript-loader@npm:^5.0.0": + version: 5.0.0 + resolution: "cosmiconfig-typescript-loader@npm:5.0.0" + dependencies: + jiti: ^1.19.1 + peerDependencies: + "@types/node": "*" + cosmiconfig: ">=8.2" + typescript: ">=4" + checksum: 7b614313f2cc2ecbe17270de570a511aa7c974bf14a749d7ed4f4d0f4a9ed02ee7ae87d710e294204abb00bb6bb0cca53795208bb1435815d143b43c6626ec74 + languageName: node + linkType: hard + "cosmiconfig@npm:8.3.6, cosmiconfig@npm:^8.2.0, cosmiconfig@npm:^8.3.6": version: 8.3.6 resolution: "cosmiconfig@npm:8.3.6" @@ -8707,9 +8722,9 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-prettier@npm:^5.0.0": - version: 5.0.0 - resolution: "eslint-plugin-prettier@npm:5.0.0" +"eslint-plugin-prettier@npm:^5.0.0, eslint-plugin-prettier@npm:^5.0.1": + version: 5.0.1 + resolution: "eslint-plugin-prettier@npm:5.0.1" dependencies: prettier-linter-helpers: ^1.0.0 synckit: ^0.8.5 @@ -8722,7 +8737,7 @@ __metadata: optional: true eslint-config-prettier: optional: true - checksum: 84e88744b9050f2d5ef31b94e85294dda16f3a53c2449f9d33eac8ae6264889b459bf35a68e438fb6b329c2a1d6491aac4bfa00d86317e7009de3dad0311bec6 + checksum: c2261033b97bafe99ccb7cc47c2fac6fa85b8bbc8b128042e52631f906b69e12afed2cdd9d7e3021cc892ee8dd4204a3574e1f32a0b718b4bb3b440944b6983b languageName: node linkType: hard @@ -8908,7 +8923,7 @@ __metadata: languageName: node linkType: hard -"eslint@npm:^8.50.0, eslint@npm:^8.51.0": +"eslint@npm:^8.51.0": version: 8.51.0 resolution: "eslint@npm:8.51.0" dependencies: @@ -11517,7 +11532,7 @@ __metadata: languageName: node linkType: hard -"jest-extended@npm:^4.0.1, jest-extended@npm:^4.0.2": +"jest-extended@npm:^4.0.2": version: 4.0.2 resolution: "jest-extended@npm:4.0.2" dependencies: @@ -11869,6 +11884,15 @@ __metadata: languageName: node linkType: hard +"jiti@npm:^1.19.1": + version: 1.20.0 + resolution: "jiti@npm:1.20.0" + bin: + jiti: bin/jiti.js + checksum: 7924062b5675142e3e272a27735be84b7bfc0a0eb73217fc2dcafa034f37c4f7b4b9ffc07dd98bcff0f739a8811ce1544db205ae7e97b1c86f0df92c65ce3c72 + languageName: node + linkType: hard + "jju@npm:^1.1.0": version: 1.4.0 resolution: "jju@npm:1.4.0" @@ -12408,21 +12432,12 @@ __metadata: languageName: node linkType: hard -"magic-string@npm:^0.27.0": - version: 0.27.0 - resolution: "magic-string@npm:0.27.0" - dependencies: - "@jridgewell/sourcemap-codec": ^1.4.13 - checksum: 273faaa50baadb7a2df6e442eac34ad611304fc08fe16e24fe2e472fd944bfcb73ffb50d2dc972dc04e92784222002af46868cb9698b1be181c81830fd95a13e - languageName: node - linkType: hard - -"magic-string@npm:^0.30.0": - version: 0.30.1 - resolution: "magic-string@npm:0.30.1" +"magic-string@npm:^0.30.0, magic-string@npm:^0.30.3": + version: 0.30.5 + resolution: "magic-string@npm:0.30.5" dependencies: "@jridgewell/sourcemap-codec": ^1.4.15 - checksum: 7bc7e4493e32a77068f3753bf8652d4ab44142122eb7fb9fa871af83bef2cd2c57518a6769701cd5d0379bd624a13bc8c72ca25ac5655b27e5a61adf1fd38db2 + checksum: da10fecff0c0a7d3faf756913ce62bd6d5e7b0402be48c3b27bfd651b90e29677e279069a63b764bcdc1b8ecdcdb898f29a5c5ec510f2323e8d62ee057a6eb18 languageName: node linkType: hard @@ -13623,7 +13638,7 @@ __metadata: languageName: node linkType: hard -"npm-check-updates@npm:^16.14.4": +"npm-check-updates@npm:^16.14.6": version: 16.14.6 resolution: "npm-check-updates@npm:16.14.6" dependencies: @@ -14757,7 +14772,7 @@ __metadata: languageName: node linkType: hard -"publint@npm:^0.2.3": +"publint@npm:^0.2.4": version: 0.2.4 resolution: "publint@npm:0.2.4" dependencies: @@ -18472,7 +18487,7 @@ __metadata: languageName: node linkType: hard -"typedoc@npm:^0.25.1": +"typedoc@npm:^0.25.2": version: 0.25.2 resolution: "typedoc@npm:0.25.2" dependencies: From 828ab9a21451be4c22ece605491add0e9ea3d8f9 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Mon, 16 Oct 2023 12:25:00 -0500 Subject: [PATCH 10/17] Add missing deps --- package.json | 4 ++-- yarn.lock | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index af149808..a9d727b6 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@xylabs/delay": "^2.12.24", "@xylabs/exists": "^2.12.24", "@xylabs/forget": "^2.12.24", + "@xylabs/lodash": "^2.12.24", "@xylabs/sdk-api-express-ecs": "^1.4.0", "@xyo-network/account": "^2.76.0", "@xyo-network/archivist-model": "^2.76.0", @@ -53,7 +54,6 @@ "@types/express": "^4.17.19", "@types/jest": "^29.5.5", "@types/jest-image-snapshot": "^6.2.1", - "@types/lodash": "^4.14.199", "@types/node": "^20.8.5", "@types/serve-static": "^1.15.3", "@types/supertest": "^2.0.14", @@ -142,4 +142,4 @@ "yarn": "1.22.19" }, "packageManager": "yarn@3.6.1" -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index d400a833..edeff37d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4718,7 +4718,6 @@ __metadata: "@types/express": ^4.17.19 "@types/jest": ^29.5.5 "@types/jest-image-snapshot": ^6.2.1 - "@types/lodash": ^4.14.199 "@types/node": ^20.8.5 "@types/serve-static": ^1.15.3 "@types/supertest": ^2.0.14 @@ -4729,6 +4728,7 @@ __metadata: "@xylabs/exists": ^2.12.24 "@xylabs/forget": ^2.12.24 "@xylabs/jest-helpers": ^2.12.24 + "@xylabs/lodash": ^2.12.24 "@xylabs/sdk-api-express-ecs": ^1.4.0 "@xylabs/ts-scripts-yarn3": ^3.1.12 "@xylabs/tsconfig": ^3.1.12 From fd2af1148a2215ff05961187921dde39f90167e3 Mon Sep 17 00:00:00 2001 From: Arie Trouw Date: Mon, 16 Oct 2023 10:33:43 -0700 Subject: [PATCH 11/17] esm export path --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a9d727b6..1e06b1e1 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ }, "import": { "types": "./dist/node/index.d.mts", - "default": "./dist/node/index.js" + "default": "./dist/node/index.mjs" } } }, @@ -142,4 +142,4 @@ "yarn": "1.22.19" }, "packageManager": "yarn@3.6.1" -} +} \ No newline at end of file From dc6a50e9e36b4fb2449bf7f628c7aa9e4464f67e Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Mon, 16 Oct 2023 12:35:19 -0500 Subject: [PATCH 12/17] Use minimatch for regex --- package.json | 3 +- .../foreventory/configureForeventory.ts | 60 +++++++++---------- yarn.lock | 1 + 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 1e06b1e1..eaa6f9a1 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "lodash": "^4.17.21", "lru-cache": "^10.0.1", "mime": "^3.0.0", + "minimatch": "^9.0.3", "node-cache": "^5.1.2", "path-to-regexp": "^6.2.1", "puppeteer": "^21.3.8", @@ -142,4 +143,4 @@ "yarn": "1.22.19" }, "packageManager": "yarn@3.6.1" -} \ No newline at end of file +} diff --git a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts index 5008164b..c2fbbf57 100644 --- a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts +++ b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts @@ -5,8 +5,8 @@ import { asyncHandler } from '@xylabs/sdk-api-express-ecs' import { RequestHandler } from 'express' import { existsSync, readFileSync } from 'fs' import { ReasonPhrases, StatusCodes } from 'http-status-codes' +import { makeRe, MMRegExp } from 'minimatch' import { extname, join } from 'path' -import { pathToRegexp } from 'path-to-regexp' import { getAdjustedPath, getUriBehindProxy, preCacheFacebookShare } from '../../lib' import { ApplicationMiddlewareOptions, MountPathAndMiddleware } from '../../types' @@ -48,7 +48,8 @@ type RouteMatcher = (route: string) => boolean * @returns */ const createMatcher = (patterns: string[]): RouteMatcher => { - const regexes = patterns.map((pattern) => pathToRegexp(pattern)) + const regexesOrFalse = patterns.map((pattern) => makeRe(pattern)) + const regexes = regexesOrFalse.filter((regex): regex is MMRegExp => regex !== false) return (route: string) => regexes.some((regex) => regex.test(route)) } @@ -123,33 +124,33 @@ const imageHandler: RequestHandler = asyncHandler(async (req, res, next) => { next() }) -// const liveShareHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware | undefined => { -// const { baseDir } = opts -// const filePath = join(baseDir, 'xy.config.json') -// if (existsSync(filePath)) { -// // Read in config file -// const xyConfig = JSON.parse(readFileSync(filePath, { encoding: 'utf-8' })) -// // TODO: Validate xyConfig -// if (xyConfig.liveShare) { -// const { include, exclude } = xyConfig.liveShare -// const matchesIncluded: RouteMatcher = include ? createMatcher(include) : () => true -// const matchesExcluded: RouteMatcher = exclude ? createMatcher(exclude) : () => false +const liveShareHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware | undefined => { + const { baseDir } = opts + const filePath = join(baseDir, 'xy.config.json') + if (existsSync(filePath)) { + // Read in config file + const xyConfig = JSON.parse(readFileSync(filePath, { encoding: 'utf-8' })) + // TODO: Validate xyConfig + if (xyConfig.liveShare) { + const { include, exclude } = xyConfig.liveShare + const matchesIncluded: RouteMatcher = include ? createMatcher(include) : () => true + const matchesExcluded: RouteMatcher = exclude ? createMatcher(exclude) : () => false -// const handler: RequestHandler = asyncHandler(async (req, res, next) => { -// const adjustedPath = getAdjustedPath(req) -// await Promise.resolve() -// if (matchesIncluded(adjustedPath) && !matchesExcluded(adjustedPath)) { -// // TODO: Grab helmet head data, next for now -// next() -// } else { -// next() -// } -// }) -// return ['get', ['/*', handler]] -// } -// return undefined -// } -// } + const handler: RequestHandler = asyncHandler(async (req, res, next) => { + const adjustedPath = getAdjustedPath(req) + await Promise.resolve() + if (matchesIncluded(adjustedPath) && !matchesExcluded(adjustedPath)) { + // TODO: Grab helmet head data, next for now + next() + } else { + next() + } + }) + return ['get', ['/*', handler]] + } + return undefined + } +} /** * Middleware for augmenting HTML metadata for Foreventory shares @@ -161,5 +162,4 @@ const foreventorySharePageHandler = (opts: ApplicationMiddlewareOptions): MountP const foreventoryImageHandler = (): MountPathAndMiddleware => ['get', ['/netflix/insights/:hash/preview/:width/:height/img.png', imageHandler]] export const foreventoryHandlers = (opts: ApplicationMiddlewareOptions) => - // [foreventorySharePageHandler(opts), foreventoryImageHandler(), liveShareHandler(opts)].filter(exists) - [foreventorySharePageHandler(opts), foreventoryImageHandler()].filter(exists) + [foreventorySharePageHandler(opts), foreventoryImageHandler(), liveShareHandler(opts)].filter(exists) diff --git a/yarn.lock b/yarn.lock index edeff37d..40c37227 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4759,6 +4759,7 @@ __metadata: lodash: ^4.17.21 lru-cache: ^10.0.1 mime: ^3.0.0 + minimatch: ^9.0.3 node-cache: ^5.1.2 nodemon: ^3.0.1 path-to-regexp: ^6.2.1 From 6608c1de73b4bb1ec49ec1fff57a4787a16b4618 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Mon, 16 Oct 2023 12:37:16 -0500 Subject: [PATCH 13/17] Remove path-to-regexp --- package.json | 1 - .../contentHandlers/foreventory/configureForeventory.ts | 2 +- yarn.lock | 8 -------- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/package.json b/package.json index eaa6f9a1..1c19882a 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "mime": "^3.0.0", "minimatch": "^9.0.3", "node-cache": "^5.1.2", - "path-to-regexp": "^6.2.1", "puppeteer": "^21.3.8", "rollbar": "^2.26.2", "serve-static": "^1.15.0", diff --git a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts index c2fbbf57..97251212 100644 --- a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts +++ b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts @@ -49,7 +49,7 @@ type RouteMatcher = (route: string) => boolean */ const createMatcher = (patterns: string[]): RouteMatcher => { const regexesOrFalse = patterns.map((pattern) => makeRe(pattern)) - const regexes = regexesOrFalse.filter((regex): regex is MMRegExp => regex !== false) + const regexes = regexesOrFalse.filter((regex): regex is MMRegExp => assertEx(regex !== false, 'Invalid glob pattern')) return (route: string) => regexes.some((regex) => regex.test(route)) } diff --git a/yarn.lock b/yarn.lock index 40c37227..f9f3ba9a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4762,7 +4762,6 @@ __metadata: minimatch: ^9.0.3 node-cache: ^5.1.2 nodemon: ^3.0.1 - path-to-regexp: ^6.2.1 puppeteer: ^21.3.8 rollbar: ^2.26.2 serve-static: ^1.15.0 @@ -14434,13 +14433,6 @@ __metadata: languageName: node linkType: hard -"path-to-regexp@npm:^6.2.1": - version: 6.2.1 - resolution: "path-to-regexp@npm:6.2.1" - checksum: f0227af8284ea13300f4293ba111e3635142f976d4197f14d5ad1f124aebd9118783dd2e5f1fe16f7273743cc3dbeddfb7493f237bb27c10fdae07020cc9b698 - languageName: node - linkType: hard - "path-type@npm:^3.0.0": version: 3.0.0 resolution: "path-type@npm:3.0.0" From 3d2d2efe501a16cdadbbc72dc28af091447dd7d1 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Mon, 16 Oct 2023 12:52:56 -0500 Subject: [PATCH 14/17] Error messages when invalid glob patterns --- .../contentHandlers/foreventory/configureForeventory.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts index 97251212..f799b71c 100644 --- a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts +++ b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts @@ -49,7 +49,12 @@ type RouteMatcher = (route: string) => boolean */ const createMatcher = (patterns: string[]): RouteMatcher => { const regexesOrFalse = patterns.map((pattern) => makeRe(pattern)) - const regexes = regexesOrFalse.filter((regex): regex is MMRegExp => assertEx(regex !== false, 'Invalid glob pattern')) + const invalidGlobPatternIndexes = regexesOrFalse.reduce((acc, curr, idx) => { + if (curr === false) acc.push(idx) + return acc + }, []) + assertEx(invalidGlobPatternIndexes.length === 0, `Invalid glob pattern(s): ${invalidGlobPatternIndexes.map((i) => patterns[i]).join(', ')}`) + const regexes = regexesOrFalse.filter((regex): regex is MMRegExp => assertEx(regex !== false)) return (route: string) => regexes.some((regex) => regex.test(route)) } From 7f8d799f5455094a51506ebfbaee1d9f88c060bf Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Mon, 16 Oct 2023 12:55:04 -0500 Subject: [PATCH 15/17] Rename handlers to enable migration/deprecation --- .../contentHandlers/foreventory/configureForeventory.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts index f799b71c..b13f1e43 100644 --- a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts +++ b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts @@ -129,7 +129,7 @@ const imageHandler: RequestHandler = asyncHandler(async (req, res, next) => { next() }) -const liveShareHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware | undefined => { +const liveSharePageHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware | undefined => { const { baseDir } = opts const filePath = join(baseDir, 'xy.config.json') if (existsSync(filePath)) { @@ -160,11 +160,11 @@ const liveShareHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddl /** * Middleware for augmenting HTML metadata for Foreventory shares */ -const foreventorySharePageHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware => [ +const netflixInsightsSharePageHandler = (opts: ApplicationMiddlewareOptions): MountPathAndMiddleware => [ 'get', ['/netflix/insights/:hash', getPageHandler(opts.baseDir)], ] -const foreventoryImageHandler = (): MountPathAndMiddleware => ['get', ['/netflix/insights/:hash/preview/:width/:height/img.png', imageHandler]] +const netflixInsightsImageHandler = (): MountPathAndMiddleware => ['get', ['/netflix/insights/:hash/preview/:width/:height/img.png', imageHandler]] export const foreventoryHandlers = (opts: ApplicationMiddlewareOptions) => - [foreventorySharePageHandler(opts), foreventoryImageHandler(), liveShareHandler(opts)].filter(exists) + [netflixInsightsSharePageHandler(opts), netflixInsightsImageHandler(), liveSharePageHandler(opts)].filter(exists) From be3b83c59ba4c5187368bb873de4406c7ef23798 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Mon, 16 Oct 2023 15:04:41 -0500 Subject: [PATCH 16/17] Setup launch config for debug --- .vscode/launch.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5c44bb5b..279befd4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,8 +9,12 @@ "request": "launch", "name": "Debug", "program": "${workspaceFolder}/src/bin/start-meta.ts", + "args": [ + "ts-node-script", + "${workspaceFolder}/src/bin/start-meta.ts" + ], "outFiles": [ - "${workspaceFolder}/dist/**/*.js" + "${workspaceFolder}/dist/**/*.*", ], "env": { "NODE_OPTIONS": "-r ts-node/register --loader ts-node/esm --max-old-space-size=8192" From 60a540b3913b2f27ea6e6f48b726094cfacfec76 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Mon, 16 Oct 2023 15:05:00 -0500 Subject: [PATCH 17/17] Use glob matchers to handle path --- .../contentHandlers/foreventory/configureForeventory.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts index b13f1e43..1d3ed6dd 100644 --- a/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts +++ b/src/modules/metaServer/contentHandlers/foreventory/configureForeventory.ts @@ -142,9 +142,12 @@ const liveSharePageHandler = (opts: ApplicationMiddlewareOptions): MountPathAndM const matchesExcluded: RouteMatcher = exclude ? createMatcher(exclude) : () => false const handler: RequestHandler = asyncHandler(async (req, res, next) => { - const adjustedPath = getAdjustedPath(req) + // Exclude query string from glob via req.path + const uri = req.path + // // NOTE: Uncomment if we want to also include query string + // const uri = req.originalUrl await Promise.resolve() - if (matchesIncluded(adjustedPath) && !matchesExcluded(adjustedPath)) { + if (matchesIncluded(uri) && !matchesExcluded(uri)) { // TODO: Grab helmet head data, next for now next() } else {