@joystick.js/node-canary 0.0.0-canary.365 → 0.0.0-canary.367
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 +1 @@
|
|
|
1
|
-
import w from"fs";import p from"../../../lib/dynamic_import.js";import c from"../generate_joystick_error_page.js";import k from"../../../lib/get_joystick_build_path.js";import j from"../../../lib/get_translations.js";import x from"./get_url.js";import _ from"../../../lib/path_exists.js";import v from"../../ssr/index.js";import
|
|
1
|
+
import w from"fs";import p from"../../../lib/dynamic_import.js";import c from"../generate_joystick_error_page.js";import k from"../../../lib/get_joystick_build_path.js";import j from"../../../lib/get_translations.js";import x from"./get_url.js";import _ from"../../../lib/path_exists.js";import v from"../../ssr/index.js";import"../../../lib/get_browser_safe_request.js";const{readFile:z}=w.promises,i=k(),A=()=>z("index.html","utf-8"),D=(s,e,f,d={})=>{e.render=async(n="",t={})=>{const u=n?.substring(0,1)==="/"?n?.replace("/",""):n,r=t?.layout?.substring(0,1)==="/"?t?.layout?.replace("/",""):t?.layout,a=`${i}${u}`,o=t?.layout?`${i}${r}`:null;if(!await _(a))return e.status(404).send(c({type:"page_not_found",path:`res.render('${a}')`,frame:null,stack:`A page component at the path ${a} could not be found.`}));if(o&&!await _(o))return e.status(404).send(c({type:"layout_not_found",path:`res.render('${a}', { layout: '${r}' })`,frame:null,stack:`A layout component at the path ${t?.layout} could not be found.`}));const l=await p(`${a}?v=${new Date().getTime()}`),h=o?await p(`${o}?v=${new Date().getTime()}`):null,m={...t?.props||{}};o&&(m.page=l);const y=await A(),g=await j({joystick_build_path:i,render_component_path:n,req:s}),$=x(s),b=await v({api_schema:d?.options?.api,attributes:t?.attributes,base_html:y,component_options:{props:m,translations:g,url:$},component_to_render:h||l,head:t?.head,render_component_path:u,render_layout_path:r,req:s});return e.status(200).send(b)},f()};var K=D;export{K as default};
|
package/dist/app/ssr/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import u from"fs";import p from"../api/get_api_for_data_functions.js";import y from"../../lib/get_browser_safe_request.js";import $ from"../settings/load.js";import h from"./set_base_attributes_in_html.js";import b from"./set_head_tags_in_html.js";import i from"../../lib/path_exists.js";import w from"../accounts/get_browser_safe_user.js";const{readFile:a}=u.promises,r=$(),s=process.env.NODE_ENV==="development",f=(e={})=>e?.base_html.replace("${css}",`<style type="text/css" js-css>${e?.css}</style>`).replace('<div id="app"></div>',`
|
|
2
2
|
<div id="app">${e?.html}</div>
|
|
3
3
|
<script>
|
|
4
4
|
window.joystick = {
|
|
@@ -13,20 +13,20 @@ import p from"fs";import y from"../api/get_api_for_data_functions.js";import $ f
|
|
|
13
13
|
${s?`window.__joystick_hmr_port__ = ${parseInt(process.env.PORT,10)+1}`:""}
|
|
14
14
|
window.__joystick_layout_url__ = ${e?.render_layout_path?`"/_joystick/${e?.render_layout_path}"`:null};
|
|
15
15
|
window.__joystick_page_url__ = ${e?.render_component_path?`"/_joystick/${e?.render_component_path}"`:null};
|
|
16
|
-
window.__joystick_request__ = ${JSON.stringify(e?.req)};
|
|
16
|
+
window.__joystick_request__ = ${JSON.stringify(y(e?.req))};
|
|
17
17
|
window.__joystick_settings__ = ${JSON.stringify({global:r?.global,public:r?.public})};
|
|
18
18
|
|
|
19
19
|
window.__joystick_should_auto_mount__ = true;
|
|
20
20
|
window.__joystick_ssr_props__ = ${JSON.stringify(e?.props)};
|
|
21
21
|
window.__joystick_url__ = ${JSON.stringify(e?.url)};
|
|
22
|
-
window.__joystick_user__ = ${JSON.stringify(e?.req?.context?.user)};
|
|
22
|
+
window.__joystick_user__ = ${JSON.stringify(w(e?.req?.context?.user))};
|
|
23
23
|
</script>
|
|
24
24
|
<script type="module" src="/_joystick/utils/process.js"></script>
|
|
25
25
|
<script type="module" src="/_joystick/index.client.js"></script>
|
|
26
26
|
${e?.render_component_path?`<script type="module" src="/_joystick/${e?.render_component_path}"></script>`:""}
|
|
27
27
|
${e?.render_layout_path?`<script type="module" src="/_joystick/${e?.render_layout_path}"></script>`:""}
|
|
28
28
|
${s?'<script type="module" src="/_joystick/hmr/client.js"></script>':""}
|
|
29
|
-
`),g=(e={})=>e?.base_html.replace("${css}",`<style type="text/css">${e?.css}</style>`).replace("${subject}",e?.email_options?.subject).replace("${preheader}",e?.email_options?.preheader||"").replace('<div id="email"></div>',`<div id="email">${e?.html}</div>`),j=(e={})=>e?.is_email?g(e):f(e),k=async(e="")=>await i(`email/${e?`base_${e}`:"base"}.html`)?a(`email/${e?`base_${e}`:"base"}.html`,"utf-8"):(console.warn(`Could not find email/${e?`base_${e}`:"base"}.html`),""),v=async(e="")=>await i(`email/${e?`base_${e}`:"base"}.css`)?a(`email/${e?`base_${e}`:"base"}.css`,"utf-8"):(console.warn(`Could not find email/${e?`base_${e}`:"base"}.css`),""),N=(e=null,t={})=>e(t),O=async(e={})=>{const t=N(e?.component_to_render,e?.component_options),l=
|
|
30
|
-
${
|
|
29
|
+
`),g=(e={})=>e?.base_html.replace("${css}",`<style type="text/css">${e?.css}</style>`).replace("${subject}",e?.email_options?.subject).replace("${preheader}",e?.email_options?.preheader||"").replace('<div id="email"></div>',`<div id="email">${e?.html}</div>`),j=(e={})=>e?.is_email?g(e):f(e),k=async(e="")=>await i(`email/${e?`base_${e}`:"base"}.html`)?a(`email/${e?`base_${e}`:"base"}.html`,"utf-8"):(console.warn(`Could not find email/${e?`base_${e}`:"base"}.html`),""),v=async(e="")=>await i(`email/${e?`base_${e}`:"base"}.css`)?a(`email/${e?`base_${e}`:"base"}.css`,"utf-8"):(console.warn(`Could not find email/${e?`base_${e}`:"base"}.css`),""),N=(e=null,t={})=>e(t),O=async(e={})=>{const t=N(e?.component_to_render,e?.component_options),l=p(e?.req,e?.api_schema),c=[],_=await t.render_for_ssr(l,e?.req,c,{is_email:e?.is_email}),n=e?.is_email?await v(e?.email_options?.base_html_name):null,o=e?.is_email?await k(e?.email_options?.base_html_name):null,m=j({is_email:e?.is_email,attributes:e?.attributes,base_html:e?.is_email?o:e?.base_html,component_instance:t,css:e?.is_email?`
|
|
30
|
+
${n}
|
|
31
31
|
${_?.css}
|
|
32
|
-
`:_?.css,data:_?.data,email_options:e?.email_options,head:e?.head,html:_?.html,props:e?.component_options?.props,render_component_path:e?.render_component_path,render_layout_path:e?.render_layout_path,req:
|
|
32
|
+
`:_?.css,data:_?.data,email_options:e?.email_options,head:e?.head,html:_?.html,props:e?.component_options?.props,render_component_path:e?.render_component_path,render_layout_path:e?.render_layout_path,req:e?.req,translations:e?.component_options?.translations,url:e?.component_options?.url}),d=b(m,e?.head,e?.req);return h(d,e?.attributes)};var P=O;export{P as default};
|
package/package.json
CHANGED
|
@@ -81,7 +81,7 @@ const render_middleware = (req, res, next, app_instance = {}) => {
|
|
|
81
81
|
head: render_options?.head,
|
|
82
82
|
render_component_path: sanitized_render_component_path,
|
|
83
83
|
render_layout_path: sanitized_render_layout_path,
|
|
84
|
-
req
|
|
84
|
+
req,
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
return res.status(200).send(html);
|
package/src/app/ssr/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import load_settings from '../settings/load.js';
|
|
|
5
5
|
import set_base_attributes_in_html from "./set_base_attributes_in_html.js";
|
|
6
6
|
import set_head_tags_in_html from "./set_head_tags_in_html.js";
|
|
7
7
|
import path_exists from "../../lib/path_exists.js";
|
|
8
|
+
import get_browser_safe_user from '../accounts/get_browser_safe_user.js';
|
|
8
9
|
|
|
9
10
|
const { readFile } = fs.promises;
|
|
10
11
|
const app_settings = load_settings();
|
|
@@ -28,7 +29,7 @@ const build_html_response_for_browser = (options = {}) => {
|
|
|
28
29
|
${is_development ? `window.__joystick_hmr_port__ = ${parseInt(process.env.PORT, 10) + 1}` : ''}
|
|
29
30
|
window.__joystick_layout_url__ = ${options?.render_layout_path ? `"/_joystick/${options?.render_layout_path}"` : null};
|
|
30
31
|
window.__joystick_page_url__ = ${options?.render_component_path ? `"/_joystick/${options?.render_component_path}"` : null};
|
|
31
|
-
window.__joystick_request__ = ${JSON.stringify(options?.req)};
|
|
32
|
+
window.__joystick_request__ = ${JSON.stringify(get_browser_safe_request(options?.req))};
|
|
32
33
|
window.__joystick_settings__ = ${JSON.stringify({
|
|
33
34
|
global: app_settings?.global,
|
|
34
35
|
public: app_settings?.public,
|
|
@@ -37,7 +38,7 @@ const build_html_response_for_browser = (options = {}) => {
|
|
|
37
38
|
window.__joystick_should_auto_mount__ = true;
|
|
38
39
|
window.__joystick_ssr_props__ = ${JSON.stringify(options?.props)};
|
|
39
40
|
window.__joystick_url__ = ${JSON.stringify(options?.url)};
|
|
40
|
-
window.__joystick_user__ = ${JSON.stringify(options?.req?.context?.user)};
|
|
41
|
+
window.__joystick_user__ = ${JSON.stringify(get_browser_safe_user(options?.req?.context?.user))};
|
|
41
42
|
</script>
|
|
42
43
|
<script type="module" src="/_joystick/utils/process.js"></script>
|
|
43
44
|
<script type="module" src="/_joystick/index.client.js"></script>
|
|
@@ -88,7 +89,6 @@ const ssr = async (ssr_options = {}) => {
|
|
|
88
89
|
const api = get_api_for_data_functions(ssr_options?.req, ssr_options?.api_schema);
|
|
89
90
|
const ssr_tree = [];
|
|
90
91
|
const ssr_render = await component_instance.render_for_ssr(api, ssr_options?.req, ssr_tree, { is_email: ssr_options?.is_email });
|
|
91
|
-
const browser_safe_request = ssr_options?.is_email ? null : get_browser_safe_request(ssr_options?.req);
|
|
92
92
|
const email_base_css = ssr_options?.is_email ? await get_base_css_for_email(ssr_options?.email_options?.base_html_name) : null;
|
|
93
93
|
const email_base_html = ssr_options?.is_email ? await get_base_html_for_email(ssr_options?.email_options?.base_html_name) : null;
|
|
94
94
|
|
|
@@ -108,7 +108,7 @@ const ssr = async (ssr_options = {}) => {
|
|
|
108
108
|
props: ssr_options?.component_options?.props,
|
|
109
109
|
render_component_path: ssr_options?.render_component_path,
|
|
110
110
|
render_layout_path: ssr_options?.render_layout_path,
|
|
111
|
-
req:
|
|
111
|
+
req: ssr_options?.req,
|
|
112
112
|
translations: ssr_options?.component_options?.translations,
|
|
113
113
|
url: ssr_options?.component_options?.url,
|
|
114
114
|
});
|
|
@@ -8,7 +8,7 @@ const get_browser_safe_request = (req = {}) => {
|
|
|
8
8
|
browser_safe_request.params = escape_key_value_pair(req.params);
|
|
9
9
|
browser_safe_request.query = escape_key_value_pair(req.query);
|
|
10
10
|
browser_safe_request.context = {
|
|
11
|
-
user: get_browser_safe_user(req.context.user)
|
|
11
|
+
user: get_browser_safe_user(req.context.user),
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
return browser_safe_request;
|