@joystick.js/node-canary 0.0.0-canary.385 → 0.0.0-canary.387
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
|
|
1
|
+
import f from"./format_api_error.js";import g from"./get.js";import d from"./get_api_context.js";import y from"./get_api_url_component.js";import h from"./handle_api_error.js";import p from"../../lib/is_valid_json.js";import w from"../../lib/types.js";import v from"./validate_session.js";const x=(u={},n=[],_={},m={})=>{for(let r=0;r<n?.length;r+=1){const[s,i]=n[r];u.get(`/api/_getters/${y(s)}`,...w.is_array(i?.middleware)?i?.middleware:[],async(t={},e={})=>{if(process.databases?._sessions&&!await v(t,e))return e.status(403).send(JSON.stringify({errors:[f(new Error("Unauthorized request."))]}));const l=await d(t,e,_),a=p(t?.query?.input)?JSON.parse(t?.query?.input):null;console.log(a);const c=p(t?.query?.output)?JSON.parse(t?.query?.output):null;g({get_name:s,get_options:{input:a,output:c},getter_definition:i,request_context:l,api_schema_options:m}).then(o=>e.status(200).send(JSON.stringify(o))).catch(o=>{h(`api.getters.${s}`,o,e)})})}};var z=x;export{z as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const g=(n="",e=null,o={})=>{if(o?.req?.context?.user&&n)return o?.res.redirect(n);if(e)return e()},f=(n="",e=null,o={})=>{if(!o?.req?.context?.user&&n)return o?.res.redirect(n);if(e)return e()},d=async(n,e,o)=>{n.context={...n?.context||{},if_logged_in:(t="",i)=>g(t,i,{req:n,res:e}),ifLoggedIn:(t="",i)=>g(t,i,{req:n,res:e}),if_not_logged_in:(t="",i)=>f(t,i,{req:n,res:e}),ifNotLoggedIn:(t="",i)=>f(t,i,{req:n,res:e}),...process.databases||{}},o()};var r=d;export{r as default};
|
package/package.json
CHANGED
|
@@ -28,6 +28,9 @@ const register_getters = (express_app = {}, getter_definitions = [], api_context
|
|
|
28
28
|
|
|
29
29
|
const context = await get_api_context(req, res, api_context);
|
|
30
30
|
const input = is_valid_json(req?.query?.input) ? JSON.parse(req?.query?.input) : null;
|
|
31
|
+
|
|
32
|
+
console.log(input);
|
|
33
|
+
|
|
31
34
|
const output = is_valid_json(req?.query?.output) ? JSON.parse(req?.query?.output) : null;
|
|
32
35
|
|
|
33
36
|
get({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const if_logged_in = (redirect_path = "", callback = null) => {
|
|
2
|
-
if (!!req?.context?.user && redirect_path) {
|
|
3
|
-
return res.redirect(redirect_path);
|
|
1
|
+
const if_logged_in = (redirect_path = "", callback = null, http = {}) => {
|
|
2
|
+
if (!!http?.req?.context?.user && redirect_path) {
|
|
3
|
+
return http?.res.redirect(redirect_path);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
if (callback) {
|
|
@@ -8,9 +8,9 @@ const if_logged_in = (redirect_path = "", callback = null) => {
|
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
const if_not_logged_in = (redirect_path = "", callback = null) => {
|
|
12
|
-
if (!req?.context?.user && redirect_path) {
|
|
13
|
-
return res.redirect(redirect_path);
|
|
11
|
+
const if_not_logged_in = (redirect_path = "", callback = null, http = {}) => {
|
|
12
|
+
if (!http?.req?.context?.user && redirect_path) {
|
|
13
|
+
return http?.res.redirect(redirect_path);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
if (callback) {
|
|
@@ -21,10 +21,10 @@ const if_not_logged_in = (redirect_path = "", callback = null) => {
|
|
|
21
21
|
const context_middleware = async (req, res, next) => {
|
|
22
22
|
req.context = {
|
|
23
23
|
...(req?.context || {}),
|
|
24
|
-
if_logged_in,
|
|
25
|
-
ifLoggedIn: if_logged_in,
|
|
26
|
-
if_not_logged_in,
|
|
27
|
-
ifNotLoggedIn: if_not_logged_in,
|
|
24
|
+
if_logged_in: (redirect_path = '', callback) => if_logged_in(redirect_path, callback, { req, res }),
|
|
25
|
+
ifLoggedIn: (redirect_path = '', callback) => if_logged_in(redirect_path, callback, { req, res }),
|
|
26
|
+
if_not_logged_in: (redirect_path = '', callback) => if_not_logged_in(redirect_path, callback, { req, res }),
|
|
27
|
+
ifNotLoggedIn: (redirect_path = '', callback) => if_not_logged_in(redirect_path, callback, { req, res }),
|
|
28
28
|
...(process.databases || {}),
|
|
29
29
|
};
|
|
30
30
|
|