@lowdefy/client 4.0.0-alpha.10 → 4.0.0-alpha.11

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/Client.js CHANGED
@@ -19,14 +19,16 @@ import DisplayMessage from './DisplayMessage.js';
19
19
  import Head from './Head.js';
20
20
  import ProgressBarController from './ProgressBarController.js';
21
21
  import initLowdefyContext from './initLowdefyContext.js';
22
- const Client = ({ Components , config , resetContext ={
22
+ const Client = ({ auth , Components , config , resetContext ={
23
23
  reset: false,
24
24
  setReset: ()=>undefined
25
- } , router , stage , types , window , })=>{
25
+ } , router , session , stage , types , window , })=>{
26
26
  const lowdefy = initLowdefyContext({
27
+ auth,
27
28
  Components,
28
29
  config,
29
30
  router,
31
+ session,
30
32
  stage,
31
33
  types,
32
34
  window
@@ -78,8 +78,7 @@ const ProgressBarController = ({ id , lowdefy , resetContext })=>{
78
78
  makeCssClass
79
79
  },
80
80
  pageId: lowdefy.pageId,
81
- properties: state,
82
- user: lowdefy.user
81
+ properties: state
83
82
  }));
84
83
  };
85
84
  export default ProgressBarController;
@@ -0,0 +1,56 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type, urlQuery as urlQueryFn } from '@lowdefy/helpers';
16
+ function getCallbackUrl({ lowdefy , callbackUrl ={} }) {
17
+ const { home , pageId , urlQuery } = callbackUrl;
18
+ if ([
19
+ !home,
20
+ !pageId
21
+ ].filter((v)=>!v
22
+ ).length > 1) {
23
+ throw Error(`Invalid Link: To avoid ambiguity, only one of 'home' or 'pageId' can be defined.`);
24
+ }
25
+ const query = type.isNone(urlQuery) ? '' : `${urlQueryFn.stringify(urlQuery)}`;
26
+ if (home === true) {
27
+ return `/${lowdefy.home.configured ? '' : lowdefy.home.pageId}${query ? `?${query}` : ''}`;
28
+ }
29
+ if (type.isString(pageId)) {
30
+ return `/${pageId}${query ? `?${query}` : ''}`;
31
+ }
32
+ return undefined;
33
+ }
34
+ function createAuthMethods(lowdefy, auth) {
35
+ // login and logout are Lowdefy function that handle action params
36
+ // signIn and signOut are the next-auth methods
37
+ function login({ providerId , callbackUrl , authUrl ={} } = {}) {
38
+ // TODO: if only one provider exists, pass provider here
39
+ // to link directly to provider
40
+ auth.signIn(providerId, {
41
+ callbackUrl: getCallbackUrl({
42
+ lowdefy,
43
+ callbackUrl
44
+ })
45
+ }, authUrl.urlQuery);
46
+ }
47
+ // TODO: fix callbackUrl
48
+ function logout() {
49
+ auth.signOut();
50
+ }
51
+ return {
52
+ login,
53
+ logout
54
+ };
55
+ }
56
+ export default createAuthMethods;
@@ -80,7 +80,6 @@ const CategorySwitch = ({ block , Blocks , context , loading , lowdefy })=>{
80
80
  pageId: lowdefy.pageId,
81
81
  properties: block.eval.properties,
82
82
  required: block.eval.required,
83
- user: lowdefy.user,
84
83
  validation: block.eval.validation,
85
84
  value: block.value
86
85
  })));
@@ -108,7 +107,6 @@ const CategorySwitch = ({ block , Blocks , context , loading , lowdefy })=>{
108
107
  pageId: lowdefy.pageId,
109
108
  properties: block.eval.properties,
110
109
  required: block.eval.required,
111
- user: lowdefy.user,
112
110
  validation: block.eval.validation
113
111
  })));
114
112
  }
@@ -70,7 +70,6 @@ const Container = ({ block , Blocks , Component , context , loading , lowdefy }
70
70
  pageId: lowdefy.pageId,
71
71
  properties: block.eval.properties,
72
72
  required: block.eval.required,
73
- user: lowdefy.user,
74
73
  validation: block.eval.validation
75
74
  })));
76
75
  };
@@ -79,7 +79,6 @@ const List = ({ block , Blocks , Component , context , loading , lowdefy })=>{
79
79
  pageId: lowdefy.pageId,
80
80
  properties: block.eval.properties,
81
81
  required: block.eval.required,
82
- user: lowdefy.user,
83
82
  validation: block.eval.validation
84
83
  })));
85
84
  };
@@ -76,8 +76,7 @@ const LoadingBlock = ({ blockLayout , blockId , context , lowdefy , skeleton })
76
76
  menus: lowdefy.menus,
77
77
  methods: blockMethods,
78
78
  pageId: lowdefy.pageId,
79
- properties: skeleton.properties,
80
- user: lowdefy.user
79
+ properties: skeleton.properties
81
80
  })));
82
81
  }
83
82
  };
@@ -61,8 +61,7 @@ const LoadingContainer = ({ blockId , Component , context , layout , lowdefy , s
61
61
  makeCssClass
62
62
  },
63
63
  pageId: lowdefy.pageId,
64
- properties: skeleton.properties,
65
- user: lowdefy.user
64
+ properties: skeleton.properties
66
65
  })));
67
66
  };
68
67
  export default LoadingContainer;
@@ -65,8 +65,7 @@ const LoadingList = ({ blockId , Component , context , layout , lowdefy , skelet
65
65
  makeCssClass
66
66
  },
67
67
  pageId: lowdefy.pageId,
68
- properties: skeleton.properties,
69
- user: lowdefy.user
68
+ properties: skeleton.properties
70
69
  })));
71
70
  };
72
71
  export default LoadingList;
@@ -45,7 +45,6 @@ const lowdefyProps = [
45
45
  'registerEvent',
46
46
  'registerMethod',
47
47
  'schemaErrors',
48
- 'user',
49
48
  'validation',
50
49
  ];
51
50
  const createIcon = (Icons)=>{
@@ -15,6 +15,7 @@
15
15
  */ import { urlQuery } from '@lowdefy/helpers';
16
16
  import callRequest from './callRequest.js';
17
17
  import createIcon from './createIcon.js';
18
+ import createAuthMethods from './auth/createAuthMethods.js';
18
19
  import createLinkComponent from './createLinkComponent.js';
19
20
  import setupLink from './setupLink.js';
20
21
  const lowdefy = {
@@ -40,7 +41,7 @@ const lowdefy = {
40
41
  inputs: {},
41
42
  lowdefyGlobal: {}
42
43
  };
43
- function initLowdefyContext({ Components , config , router , stage , types , window }) {
44
+ function initLowdefyContext({ auth , Components , config , router , session , stage , types , window }) {
44
45
  if (stage === 'dev') {
45
46
  window.lowdefy = lowdefy;
46
47
  }
@@ -50,6 +51,7 @@ function initLowdefyContext({ Components , config , router , stage , types , win
50
51
  lowdefy.menus = config.rootConfig.menus;
51
52
  lowdefy.pageId = config.pageConfig.pageId;
52
53
  lowdefy.urlQuery = urlQuery.parse(window.location.search.slice(1));
54
+ lowdefy.user = session?.user ?? null;
53
55
  lowdefy._internal.window = window;
54
56
  lowdefy._internal.document = window.document;
55
57
  lowdefy._internal.router = router;
@@ -61,6 +63,8 @@ function initLowdefyContext({ Components , config , router , stage , types , win
61
63
  lowdefy._internal.actions = types.actions;
62
64
  lowdefy._internal.blockComponents = types.blocks;
63
65
  lowdefy._internal.operators = types.operators;
66
+ // TODO: discuss not using object arguments
67
+ lowdefy._internal.auth = createAuthMethods(lowdefy, auth);
64
68
  return lowdefy;
65
69
  }
66
70
  export default initLowdefyContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/client",
3
- "version": "4.0.0-alpha.10",
3
+ "version": "4.0.0-alpha.11",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy Client",
6
6
  "homepage": "https://lowdefy.com",
@@ -43,10 +43,10 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@ant-design/icons": "4.7.0",
46
- "@lowdefy/block-utils": "4.0.0-alpha.10",
47
- "@lowdefy/engine": "4.0.0-alpha.10",
48
- "@lowdefy/helpers": "4.0.0-alpha.10",
49
- "@lowdefy/layout": "4.0.0-alpha.10",
46
+ "@lowdefy/block-utils": "4.0.0-alpha.11",
47
+ "@lowdefy/engine": "4.0.0-alpha.11",
48
+ "@lowdefy/helpers": "4.0.0-alpha.11",
49
+ "@lowdefy/layout": "4.0.0-alpha.11",
50
50
  "classnames": "2.3.1",
51
51
  "react": "17.0.2",
52
52
  "react-dom": "17.0.2"
@@ -67,5 +67,5 @@
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  },
70
- "gitHead": "d697b4b5f354697d9481a371b90a00ca0944f486"
70
+ "gitHead": "810fb2d8cb9ee8b0586b55fbbf26a5a5a0da3b2a"
71
71
  }