@joystick.js/node-canary 0.0.0-canary.374 → 0.0.0-canary.376
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.
package/dist/app/api/get.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import p from"./format_api_error.js";import f from"./get_output.js";import h from"../../lib/get_sanitized_context.js";import z from"./sanitize_api_response.js";import d from"../../test/track_function_call.js";import n from"../../lib/types.js";import m from"./validate_input.js";const _=async(o="",t={},r=null,s=null,a={},u={})=>{const l=t?.sanitize===!1,i=(t?.sanitize||u?.sanitize)===!0;d(`node.api.getters.${o}`,[r,h(a)]);const e=await t?.get(r,a),c=s?f(e,s):e;return!l&&i?z(c):c},w=async(o="",t={},r={},s={})=>{d(`node.api.getters.${o}.authorized`,[r,h(s)]);const a=await t?.authorized(r,s);if(typeof a=="boolean")return a;if(n.is_object(a)&&!n.is_array(a)&&!n.is_undefined(a?.authorized))return a?.authorized?!0:a?.message},y=(o=[],t="")=>{console.log(`Input validation for getter "${t}" failed with the following errors:
|
|
2
|
-
`);for(let r=0;r<o?.length;r+=1){const s=o[r];console.log(`${r+1}. ${s}`)}},$=(o={},t={})=>m(o,t),v=async({get_name:o,get_options:t,getter_definition:r,request_context:s,api_schema_options:a})=>{const u=r?.input&&Object.keys(r?.input)?.length>0,l=n.is_function(r?.authorized);if(u){const i=await $(t?.input,r?.input);if(i?.length>0)return y(i,o),Promise.reject({errors:i.map(e=>p(new Error(e),`getters.${o}.input`,
|
|
2
|
+
`);for(let r=0;r<o?.length;r+=1){const s=o[r];console.log(`${r+1}. ${s}`)}},$=(o={},t={})=>m(o,t),v=async({get_name:o,get_options:t,getter_definition:r,request_context:s,api_schema_options:a})=>{const u=r?.input&&Object.keys(r?.input)?.length>0,l=n.is_function(r?.authorized);if(u){const i=await $(t?.input,r?.input);if(i?.length>0)return y(i,o),Promise.reject({errors:i.map(e=>p(new Error(e),`getters.${o}.input`,400))})}if(l){const i=await w(o,r,t?.input,s);if(!i||n.is_string(i))return Promise.reject({errors:[p(new Error(typeof i=="string"?i:`Not authorized to access ${o}.`),`getters.${o}.authorized`,403)]})}if(n.is_function(r?.get)){const i=await _(o,r,t?.input,t?.output,s,a);return Promise.resolve(i)}};var N=v;export{N as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import i from"../../lib/types.js";import
|
|
1
|
+
import i from"../../lib/types.js";import m from"./validate_type.js";import v from"./is_array_path.js";const l=(r,e,t)=>r.includes(e)?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} only allows the following values: ${r.join(", ")}.`]},n=(r,e,t)=>i.is_array(e)&&e?.length<=r?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} length must be less than or equal to ${r}.`]},d=(r,e,t)=>i.is_array(e)&&e?.length>=r?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} length must be greater than or equal to ${r}.`]},g={types:["any","array","boolean","float","integer","number","object","string"],rules:{allowed_values:l,allowedValues:l,element:async(r,e,t,s)=>{if(e&&(i.is_object(r)||i.is_string(r))&&i.is_array(e)){const a=await Promise.all(e.flatMap(async(o,f)=>(await s(o,i.is_string(r)?{type:r}:r,`${t}.${f}`)).flatMap(c=>c)));return{valid:a.length===0,errors:a.flatMap(o=>o)}}return{valid:!0,errors:[]}},fields:async(r,e,t,s)=>{if(i.is_object(r)&&i.is_object(e)){const a=v(t)?e:{[t]:e},o=await s(a,r,t);return{valid:o.length===0,errors:[...o]}}return{valid:!1,errors:[`Field ${t} must be of type object.`]}},max:(r,e,t)=>e<=r?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} must be less than or equal to ${r}.`]},max_length:n,maxLength:n,min:(r,e,t)=>e>=r?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} must be greater than or equal to ${r}.`]},min_length:d,minLength:d,optional:(r,e,t)=>(r===!1?!!e:!0)?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} is required.`]},regex:(r,e,t)=>new RegExp(r).test(e)?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} must conform to regex: ${r}.`]},required:(r,e,t)=>(r===!1?!0:!!e)?{valid:!0,errors:[]}:{valid:!1,errors:[`Field ${t} is required.`]},type:(r,e,t)=>{const s=m(r,e);return e&&!s?{valid:!1,errors:[`Field ${t} must be of type ${r}.`]}:{valid:!0,errors:[]}}}};var h=g;export{h as default};
|
package/dist/app/ssr/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import u from"fs";import{parseHTML as p}from"linkedom";import y from"../api/get_api_for_data_functions.js";import $ from"../../lib/get_browser_safe_request.js";import h from"../settings/load.js";import b from"./set_base_attributes_in_html.js";import w from"./set_head_tags_in_html.js";import i from"../../lib/path_exists.js";import f from"../accounts/get_browser_safe_user.js";const{readFile:a}=u.promises,r=h(),s=process.env.NODE_ENV==="development",{document:g}=p("<div></div>")
|
|
1
|
+
import u from"fs";import{parseHTML as p}from"linkedom";import y from"../api/get_api_for_data_functions.js";import $ from"../../lib/get_browser_safe_request.js";import h from"../settings/load.js";import b from"./set_base_attributes_in_html.js";import w from"./set_head_tags_in_html.js";import i from"../../lib/path_exists.js";import f from"../accounts/get_browser_safe_user.js";const{readFile:a}=u.promises,r=h(),s=process.env.NODE_ENV==="development",{document:g}=p("<div></div>"),j=(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 = {
|
|
@@ -26,7 +26,7 @@ import u from"fs";import{parseHTML as p}from"linkedom";import y from"../api/get_
|
|
|
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
|
-
`),k=(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>`),v=(e={})=>e?.is_email?k(e):j(e),N=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`),""),O=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`),""),q=(e=null,t={})=>e(t),J=async(e={})=>{const t=q(e?.component_to_render,e?.component_options),c=y(e?.req,e?.api_schema),l=[],_=await t.render_for_ssr(c,e?.req,l,{is_email:e?.is_email}),n=e?.is_email?await O(e?.email_options?.base_html_name):null,o=e?.is_email?await N(e?.email_options?.base_html_name):null,m=v({is_email:e?.is_email,attributes:e?.attributes,base_html:e?.is_email?o:e?.base_html,component_instance:t,css:e?.is_email?`
|
|
29
|
+
`),k=(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>`),v=(e={})=>e?.is_email?k(e):j(e),N=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`),""),O=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`),""),q=(e=null,t={})=>e(t),J=async(e={})=>{const t=q(e?.component_to_render,e?.component_options),c=y(e?.req,e?.api_schema),l=[],_=await t.render_for_ssr(c,e?.req,l,{linkedom_document:g,is_email:e?.is_email}),n=e?.is_email?await O(e?.email_options?.base_html_name):null,o=e?.is_email?await N(e?.email_options?.base_html_name):null,m=v({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
30
|
${n}
|
|
31
31
|
${_?.css}
|
|
32
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=w(m,e?.head,e?.req);return b(d,e?.attributes)};var M=J;export{M as default};
|
package/package.json
CHANGED
package/src/app/api/get.js
CHANGED
|
@@ -80,7 +80,7 @@ const get = async ({
|
|
|
80
80
|
|
|
81
81
|
return Promise.reject({
|
|
82
82
|
errors: validation_errors.map((error) => {
|
|
83
|
-
return format_api_error(new Error(error), `getters.${get_name}.input`,
|
|
83
|
+
return format_api_error(new Error(error), `getters.${get_name}.input`, 400);
|
|
84
84
|
}),
|
|
85
85
|
});
|
|
86
86
|
}
|
|
@@ -2,6 +2,62 @@ import types from '../../lib/types.js';
|
|
|
2
2
|
import validate_type from "./validate_type.js";
|
|
3
3
|
import is_array_path from "./is_array_path.js";
|
|
4
4
|
|
|
5
|
+
const allowed_values = (rule_value, input_value, parent_path) => {
|
|
6
|
+
const isValid = rule_value.includes(input_value);
|
|
7
|
+
|
|
8
|
+
if (!isValid) {
|
|
9
|
+
return {
|
|
10
|
+
valid: false,
|
|
11
|
+
errors: [
|
|
12
|
+
`Field ${parent_path} only allows the following values: ${rule_value.join(
|
|
13
|
+
", "
|
|
14
|
+
)}.`,
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
valid: true,
|
|
21
|
+
errors: [],
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const max_length = (rule_value, input_value, parent_path) => {
|
|
26
|
+
const valid = types.is_array(input_value) && input_value?.length <= rule_value;
|
|
27
|
+
|
|
28
|
+
if (!valid) {
|
|
29
|
+
return {
|
|
30
|
+
valid: false,
|
|
31
|
+
errors: [
|
|
32
|
+
`Field ${parent_path} length must be less than or equal to ${rule_value}.`,
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
valid: true,
|
|
39
|
+
errors: [],
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const min_length = (rule_value, input_value, parent_path) => {
|
|
44
|
+
const valid = types.is_array(input_value) && input_value?.length >= rule_value;
|
|
45
|
+
|
|
46
|
+
if (!valid) {
|
|
47
|
+
return {
|
|
48
|
+
valid: false,
|
|
49
|
+
errors: [
|
|
50
|
+
`Field ${parent_path} length must be greater than or equal to ${rule_value}.`,
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
valid: true,
|
|
57
|
+
errors: [],
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
5
61
|
const input_validators = {
|
|
6
62
|
types: [
|
|
7
63
|
"any",
|
|
@@ -14,25 +70,8 @@ const input_validators = {
|
|
|
14
70
|
"string",
|
|
15
71
|
],
|
|
16
72
|
rules: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!isValid) {
|
|
21
|
-
return {
|
|
22
|
-
valid: false,
|
|
23
|
-
errors: [
|
|
24
|
-
`Field ${parent_path} only allows the following values: ${rule_value.join(
|
|
25
|
-
", "
|
|
26
|
-
)}.`,
|
|
27
|
-
],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
valid: true,
|
|
33
|
-
errors: [],
|
|
34
|
-
};
|
|
35
|
-
},
|
|
73
|
+
allowed_values,
|
|
74
|
+
allowedValues: allowed_values,
|
|
36
75
|
element: async (rule_value, input_value, parent_path, validate_input) => {
|
|
37
76
|
// NOTE: Allow for element to be passed as a type string so you can do arrays of single
|
|
38
77
|
// primitive elements (e.g., ['a', 'b', 'c'] or [1, 2, 3]).
|
|
@@ -110,23 +149,8 @@ const input_validators = {
|
|
|
110
149
|
errors: [],
|
|
111
150
|
};
|
|
112
151
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (!valid) {
|
|
117
|
-
return {
|
|
118
|
-
valid: false,
|
|
119
|
-
errors: [
|
|
120
|
-
`Field ${parent_path} length must be less than or equal to ${rule_value}.`,
|
|
121
|
-
],
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
valid: true,
|
|
127
|
-
errors: [],
|
|
128
|
-
};
|
|
129
|
-
},
|
|
152
|
+
max_length,
|
|
153
|
+
maxLength: max_length,
|
|
130
154
|
min: (rule_value, input_value, parent_path) => {
|
|
131
155
|
const valid = input_value >= rule_value;
|
|
132
156
|
|
|
@@ -144,23 +168,8 @@ const input_validators = {
|
|
|
144
168
|
errors: [],
|
|
145
169
|
};
|
|
146
170
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (!valid) {
|
|
151
|
-
return {
|
|
152
|
-
valid: false,
|
|
153
|
-
errors: [
|
|
154
|
-
`Field ${parent_path} length must be greater than or equal to ${rule_value}.`,
|
|
155
|
-
],
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
valid: true,
|
|
161
|
-
errors: [],
|
|
162
|
-
};
|
|
163
|
-
},
|
|
171
|
+
min_length,
|
|
172
|
+
minLength: min_length,
|
|
164
173
|
optional: (rule_value, input_value, parent_path) => {
|
|
165
174
|
const valid = rule_value === false ? !!input_value : true;
|
|
166
175
|
|
package/src/app/ssr/index.js
CHANGED
|
@@ -15,7 +15,6 @@ const is_development = process.env.NODE_ENV === 'development';
|
|
|
15
15
|
// NOTE: Set a global document so we have access to a pseudo-DOM in @joystick.js/ui
|
|
16
16
|
// when server-side rendering.
|
|
17
17
|
const { document: linkedom_document } = parseHTML('<div></div>');
|
|
18
|
-
document = linkedom_document;
|
|
19
18
|
|
|
20
19
|
const build_html_response_for_browser = (options = {}) => {
|
|
21
20
|
return options?.base_html
|
|
@@ -94,7 +93,10 @@ const ssr = async (ssr_options = {}) => {
|
|
|
94
93
|
const component_instance = get_component_instance(ssr_options?.component_to_render, ssr_options?.component_options);
|
|
95
94
|
const api = get_api_for_data_functions(ssr_options?.req, ssr_options?.api_schema);
|
|
96
95
|
const ssr_tree = [];
|
|
97
|
-
const ssr_render = await component_instance.render_for_ssr(api, ssr_options?.req, ssr_tree, {
|
|
96
|
+
const ssr_render = await component_instance.render_for_ssr(api, ssr_options?.req, ssr_tree, {
|
|
97
|
+
linkedom_document,
|
|
98
|
+
is_email: ssr_options?.is_email
|
|
99
|
+
});
|
|
98
100
|
const email_base_css = ssr_options?.is_email ? await get_base_css_for_email(ssr_options?.email_options?.base_html_name) : null;
|
|
99
101
|
const email_base_html = ssr_options?.is_email ? await get_base_html_for_email(ssr_options?.email_options?.base_html_name) : null;
|
|
100
102
|
|