@joystick.js/node-canary 0.0.0-canary.4 → 0.0.0-canary.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { isObject } from "../../validation/lib/typeValidators";
2
+ import escapeKeyValuePair from "../../lib/escapeKeyValuePair.js";
2
3
  var getBrowserSafeUser_default = (user = null) => {
3
4
  if (!user || !isObject(user)) {
4
5
  return null;
@@ -16,7 +17,7 @@ var getBrowserSafeUser_default = (user = null) => {
16
17
  return fields;
17
18
  }
18
19
  }, {});
19
- return browserSafeUser;
20
+ return escapeKeyValuePair(browserSafeUser);
20
21
  };
21
22
  export {
22
23
  getBrowserSafeUser_default as default
@@ -1,8 +1,9 @@
1
1
  import getBrowserSafeUser from "./accounts/getBrowserSafeUser";
2
+ import escapeKeyValuePair from "../lib/escapeKeyValuePair.js";
2
3
  var getBrowserSafeRequest_default = (req = {}) => {
3
4
  const browserSafeRequest = {};
4
- browserSafeRequest.params = req.params;
5
- browserSafeRequest.query = req.query;
5
+ browserSafeRequest.params = escapeKeyValuePair(req.params);
6
+ browserSafeRequest.query = escapeKeyValuePair(req.query);
6
7
  browserSafeRequest.context = {
7
8
  user: getBrowserSafeUser(req.context.user)
8
9
  };
@@ -3,6 +3,7 @@ import compression from "compression";
3
3
  import cookieParser from "cookie-parser";
4
4
  import favicon from "serve-favicon";
5
5
  import fs from "fs";
6
+ import { __package } from "../../index.js";
6
7
  import insecure from "./insecure.js";
7
8
  import requestMethods from "./requestMethods.js";
8
9
  import bodyParser from "./bodyParser.js";
@@ -14,7 +15,6 @@ import runUserQuery from "../accounts/runUserQuery.js";
14
15
  import replaceBackslashesWithForwardSlashes from "../../lib/replaceBackslashesWithForwardSlashes.js";
15
16
  import replaceFileProtocol from "../../lib/replaceFileProtocol.js";
16
17
  import getBuildPath from "../../lib/getBuildPath.js";
17
- import sanitizeQueryParameters from "./sanitizeQueryParameters.js";
18
18
  import session from "./session.js";
19
19
  import csp from "./csp.js";
20
20
  const cwd = replaceFileProtocol(replaceBackslashesWithForwardSlashes(process.cwd()));
@@ -41,7 +41,6 @@ var middleware_default = ({
41
41
  }
42
42
  next();
43
43
  });
44
- app.use(sanitizeQueryParameters);
45
44
  app.use(requestMethods);
46
45
  if (cspConfig) {
47
46
  app.use((req, res, next) => csp(req, res, next, cspConfig));
@@ -54,7 +53,7 @@ var middleware_default = ({
54
53
  });
55
54
  app.use("/_joystick/utils/process.js", (_req, res) => {
56
55
  res.set("Content-Type", "text/javascript");
57
- const processPolyfill = fs.readFileSync(`${cwd}/node_modules/@joystick.js/node/dist/app/utils/process.js`, "utf-8");
56
+ const processPolyfill = fs.readFileSync(`${__package}/app/utils/process.js`, "utf-8");
58
57
  res.send(processPolyfill.replace("${NODE_ENV}", process.env.NODE_ENV));
59
58
  });
60
59
  app.use("/_joystick/index.client.js", express.static(`${buildPath}index.client.js`, {
@@ -65,7 +64,7 @@ var middleware_default = ({
65
64
  app.use("/_joystick/ui", express.static(`${buildPath}ui`, { eTag: false, maxAge: "0" }));
66
65
  app.use("/_joystick/hmr/client.js", (_req, res) => {
67
66
  res.set("Content-Type", "text/javascript");
68
- const hmrClient = fs.readFileSync(`${cwd}/node_modules/@joystick.js/node/dist/app/middleware/hmr/client.js`, "utf-8");
67
+ const hmrClient = fs.readFileSync(`${__package}/app/middleware/hmr/client.js`, "utf-8");
69
68
  res.send(hmrClient.replace("${process.env.PORT}", parseInt(process.env.PORT, 10) + 1));
70
69
  });
71
70
  app.use(favicon(faviconPath));
@@ -8,6 +8,8 @@ import generateErrorPage from "../../lib/generateErrorPage.js";
8
8
  import replaceFileProtocol from "../../lib/replaceFileProtocol.js";
9
9
  import replaceBackslashesWithForwardSlashes from "../../lib/replaceBackslashesWithForwardSlashes.js";
10
10
  import getBuildPath from "../../lib/getBuildPath.js";
11
+ import escapeHTML from "../../lib/escapeHTML.js";
12
+ import escapeKeyValuePair from "../../lib/escapeKeyValuePair.js";
11
13
  const generateHash = (input = "") => {
12
14
  return crypto.createHash("sha256").update(input).digest("hex");
13
15
  };
@@ -65,10 +67,10 @@ const getCachedHTML = ({ cachePath, cacheFileName, currentDiff }) => {
65
67
  const getUrl = (request = {}) => {
66
68
  const [path = null] = request.url?.split("?");
67
69
  return {
68
- params: request.params,
69
- query: request.query,
70
- route: request.route.path,
71
- path
70
+ params: escapeKeyValuePair(request.params),
71
+ query: escapeKeyValuePair(request.query),
72
+ route: escapeHTML(request.route.path),
73
+ path: escapeHTML(path)
72
74
  };
73
75
  };
74
76
  const getFile = async (buildPath = "") => {
@@ -1,10 +1,5 @@
1
1
  import util from "util";
2
- import { HTML_ENTITY_MAP } from "../lib/constants.js";
3
- const escapeHTML = (string = "") => {
4
- return String(string).replace(/[&<>"'`=\/]/g, function(match) {
5
- return HTML_ENTITY_MAP[match];
6
- });
7
- };
2
+ import escapeHTML from "../lib/escapeHTML.js";
8
3
  const sanitizeAPIResponse = (data = null) => {
9
4
  let sanitizedData = data;
10
5
  if (!util.isString(sanitizedData) && !util.isObject(sanitizedData) && !Array.isArray(sanitizedData)) {
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
- import sanitizeHTML from "sanitize-html";
2
1
  import fs from "fs";
2
+ import { fileURLToPath } from "url";
3
+ import { dirname } from "path";
4
+ import sanitizeHTML from "sanitize-html";
3
5
  import _accounts from "./app/accounts";
4
6
  import _action from "./action/index.js";
5
7
  import _websockets from "./websockets";
@@ -27,16 +29,18 @@ const sanitize = {
27
29
  allowedTags: sanitizeHTML.defaults.allowedTags
28
30
  }
29
31
  };
32
+ const currentFilePath = fileURLToPath(import.meta.url);
33
+ const __package = dirname(currentFilePath);
30
34
  const __filename = nodeUrlPolyfills.__filename;
31
35
  const __dirname = nodeUrlPolyfills.__dirname;
32
36
  const id = generateId;
33
37
  const origin = getOrigin();
34
38
  const settings = loadSettings();
35
- console.log("HERE", fs.readFileSync(__dirname("/dist/app/utils/process.js"), "utf-8"));
36
39
  global.joystick = {
37
40
  id: generateId,
38
41
  emitters: {},
39
42
  settings,
43
+ __package,
40
44
  __dirname,
41
45
  __filename
42
46
  };
@@ -58,6 +62,7 @@ var src_default = {
58
62
  export {
59
63
  __dirname,
60
64
  __filename,
65
+ __package,
61
66
  accounts,
62
67
  action,
63
68
  src_default as default,
@@ -0,0 +1,9 @@
1
+ import { HTML_ENTITY_MAP } from "./constants.js";
2
+ var escapeHTML_default = (string = "") => {
3
+ return String(string).replace(/[&<>"'`=]/g, function(match) {
4
+ return HTML_ENTITY_MAP[match];
5
+ });
6
+ };
7
+ export {
8
+ escapeHTML_default as default
9
+ };
@@ -0,0 +1,13 @@
1
+ import escapeHTML from "./escapeHTML.js";
2
+ var escapeKeyValuePair_default = (target = {}) => {
3
+ const parameters = Object.entries(target || {});
4
+ for (let i = 0; i < parameters?.length; i += 1) {
5
+ const [key, value] = parameters[i];
6
+ delete target[key];
7
+ target[escapeHTML(key)] = escapeHTML(value);
8
+ }
9
+ return target;
10
+ };
11
+ export {
12
+ escapeKeyValuePair_default as default
13
+ };
@@ -1,16 +1,12 @@
1
- import { URL } from "url";
1
+ import { fileURLToPath } from "url";
2
+ import { dirname } from "path";
2
3
  var nodeUrlPolyfills_default = {
3
- __filename: (url = null) => {
4
- if (!url) {
5
- return "";
6
- }
7
- return new URL("", url).pathname;
4
+ __filename: (url = "") => {
5
+ return fileURLToPath(url);
8
6
  },
9
- __dirname: (url = null) => {
10
- if (!url) {
11
- return "";
12
- }
13
- return new URL(".", url).pathname;
7
+ __dirname: (url = "") => {
8
+ const currentFilePath = fileURLToPath(url);
9
+ return dirname(currentFilePath);
14
10
  }
15
11
  };
16
12
  export {
package/dist/ssr/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from "fs";
2
+ import { __package } from "../index.js";
2
3
  import get from "../api/get";
3
4
  import set from "../api/set";
4
5
  import getBrowserSafeRequest from "../app/getBrowserSafeRequest";
@@ -184,7 +185,7 @@ const getBaseCSS = (baseHTMLName = "") => {
184
185
  try {
185
186
  const customBaseCSSPathForEmail = baseHTMLName ? `${process.cwd()}/email/base_${baseHTMLName}.css` : null;
186
187
  const customDefaultBaseCSSPathForEmail = `${process.cwd()}/email/base.css`;
187
- const defaultBaseCSSPathForEmail = process.env.NODE_ENV === "test" ? `${process.cwd()}/src/email/templates/base.css` : `${process.cwd()}/node_modules/@joystick.js/node/dist/email/templates/base.css`;
188
+ const defaultBaseCSSPathForEmail = process.env.NODE_ENV === "test" ? `${process.cwd()}/src/email/templates/base.css` : `${__package}/email/templates/base.css`;
188
189
  let baseCSSPathToFetch = defaultBaseCSSPathForEmail;
189
190
  if (fs.existsSync(customDefaultBaseCSSPathForEmail)) {
190
191
  baseCSSPathToFetch = customDefaultBaseCSSPathForEmail;
@@ -242,7 +243,7 @@ const getBaseHTML = (isEmailRender = false, baseEmailHTMLName = "") => {
242
243
  if (isEmailRender) {
243
244
  const customBaseHTMLPathForEmail = baseEmailHTMLName ? `${process.cwd()}/email/base_${baseEmailHTMLName}.html` : null;
244
245
  const customDefaultBaseHTMLPathForEmail = `${process.cwd()}/email/base.html`;
245
- const defaultBaseHTMLPathForEmail = process.env.NODE_ENV === "test" ? `${process.cwd()}/src/email/templates/base.html` : `${process.cwd()}/node_modules/@joystick.js/node/dist/email/templates/base.html`;
246
+ const defaultBaseHTMLPathForEmail = process.env.NODE_ENV === "test" ? `${process.cwd()}/src/email/templates/base.html` : `${__package}/email/templates/base.html`;
246
247
  baseHTMLPathToFetch = defaultBaseHTMLPathForEmail;
247
248
  if (fs.existsSync(customDefaultBaseHTMLPathForEmail)) {
248
249
  baseHTMLPathToFetch = customDefaultBaseHTMLPathForEmail;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.4",
3
+ "version": "0.0.0-canary.40",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",
@@ -1,16 +0,0 @@
1
- var sanitizeQueryParameters_default = (req, res, next) => {
2
- const queryParameters = Object.entries(req?.query);
3
- const htmlRegex = new RegExp(/<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g);
4
- for (let i = 0; i < queryParameters?.length; i += 1) {
5
- const [key, value] = queryParameters[i];
6
- const keyHTMLMatches = key?.match(htmlRegex);
7
- const valueHTMLMatches = value?.match(htmlRegex);
8
- if (keyHTMLMatches?.length > 0 || valueHTMLMatches?.length > 0) {
9
- delete req.query[key];
10
- }
11
- }
12
- next();
13
- };
14
- export {
15
- sanitizeQueryParameters_default as default
16
- };