-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3becfb6
Showing
28 changed files
with
428 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Lowdefy | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Lowdefy Plugins Example | ||
|
||
A plugin needs to be a npm package. The package is installed into the server using npm or yarn, so any of the supported protocols like `file:` or `git:` should work. We copy the `plugins` folder in your config into the server, so you can use relative paths there in the package specifier if you place your plugins in the `plugins` folder. | ||
|
||
You can have a look at the official Lowdefy plugins here: | ||
https://github.com/lowdefy/lowdefy/tree/main/packages/plugins | ||
The official plugins are built using swc, but is not really necessary, as the Lowdefy server is built with webpack, so it is simpler not to include a build step. | ||
|
||
To import the plugin into your app, you can add the following to the root of your lowdefy config (replacing the `types` array): | ||
|
||
```yaml | ||
plugins: | ||
- name: 'local-plugin' | ||
version: 'file:./plugins/local-plugin' | ||
- name: 'npm-plugin' | ||
version: 1.0.0 | ||
``` | ||
You can then use all of the types declared by the plugin as normal types. | ||
The plugin `package,json` file should look like this: | ||
```json | ||
{ | ||
"name": "plugin-name", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"exports": { | ||
"./auth/callbacks": "./auth/callbacks.js", | ||
"./auth/events": "./auth/events.js", | ||
"./auth/providers": "./auth/providers.js", | ||
"./blocks": "./blocks.js", | ||
"./connections": "./connections.js", | ||
"./operators/build": "./operatorsBuild.js", | ||
"./operators/client": "./operatorsClient.js", | ||
"./operators/server": "./operatorsServer.js", | ||
"./types": "./types.js" | ||
}, | ||
"files": [ | ||
"*" | ||
], | ||
"dependencies": {} | ||
} | ||
``` | ||
|
||
You can change your folder structure in your package, but then you need to change the `exports` config to match your file structure. | ||
|
||
You should have a `types.js` file, which exports all the types declared by the package. This is used so that the build knows which types can be used from that plugin. The type names exported in the `types.js` are the type names you can use in your Lowdefy config. | ||
|
||
The `types.js` file should look like | ||
|
||
```js | ||
export default { | ||
actions: ['Action'], | ||
auth: { | ||
callbacks: ['Callback'], | ||
events: ['Event'], | ||
provider: ['Provider'] | ||
}, | ||
blocks: ['Block'], | ||
connections: ['Connection'], | ||
requests: ['Request'], | ||
operators: { | ||
client: ['_build_operator', '_shared_operator'], | ||
client: ['_client_operator', '_shared_operator'], | ||
server: ['_server_operator', '_shared_operator'], | ||
}, | ||
}; | ||
``` | ||
|
||
The plugin should also have a file that exports all the types as named exports. So for example, you should have a `blocks.js`: | ||
|
||
```js | ||
export { default as Block } from './blocks/Block/Block.js'; | ||
``` | ||
|
||
The block file also needs to change slightly, an example block is | ||
|
||
```js | ||
import React from 'react'; | ||
import { blockDefaultProps } from '@lowdefy/block-utils'; | ||
const Box = ({ blockId, content, events, methods, properties }) => ( | ||
<div | ||
id={blockId} | ||
data-testid={blockId} | ||
onClick={() => methods.triggerEvent({ name: 'onClick' })} | ||
className={methods.makeCssClass([ | ||
{ outline: 'none', cursor: events.onClick && 'pointer' }, | ||
properties.style, | ||
])} | ||
> | ||
{properties.content || (content.content && content.content())} | ||
</div> | ||
); | ||
Box.defaultProps = blockDefaultProps; | ||
Box.meta = { | ||
category: 'container', // one of 'container', 'display', 'input' or 'list' | ||
icons: [], | ||
styles: [], | ||
}; | ||
export default Block; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
lowdefy: 4.0.0-alpha.17 | ||
license: MIT | ||
|
||
plugins: | ||
- name: 'plugin-name' | ||
version: 'file:./plugin-name' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Action } from './actions/Action.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
// See https://github.com/lowdefy/lowdefy/tree/main/packages/engine/src/actions/getActionMethods.js | ||
// for available methods | ||
function Action({ globals, methods, params }) { | ||
|
||
} | ||
|
||
export default Action; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Callback } from './callbacks/Callback.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// See https://next-auth.js.org/configuration/callbacks for more info | ||
|
||
function Callback({ account, isNewUser, profile, properties, token, user }) { | ||
return token; | ||
} | ||
|
||
Callback.meta = { | ||
type: 'jwt', // One of jwt, session, redirect or signIn | ||
}; | ||
|
||
export default Callback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Event } from './events/Event.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// See https://next-auth.js.org/configuration/events for more info | ||
|
||
function Event({}) { | ||
return token; | ||
} | ||
|
||
Event.meta = { | ||
type: 'createUser', // One of createUser, linkAccount, session, signIn, signOut, updateUser | ||
}; | ||
|
||
export default Event; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Provider } from './providers/Provider.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// See https://next-auth.js.org | ||
export default { | ||
id: "google", | ||
name: "Google", | ||
type: "oauth", | ||
wellKnown: "https://accounts.google.com/.well-known/openid-configuration", | ||
authorization: { params: { scope: "openid email profile" } }, | ||
idToken: true, | ||
checks: ["pkce", "state"], | ||
profile(profile) { | ||
return { | ||
id: profile.sub, | ||
name: profile.name, | ||
email: profile.email, | ||
image: profile.picture, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Block } from './blocks/Block/Block.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// See https://github.com/lowdefy/lowdefy/tree/main/packages/plugins/blocks/blocks-basic | ||
// for more examples | ||
|
||
|
||
import React from 'react'; | ||
import { blockDefaultProps } from '@lowdefy/block-utils'; | ||
|
||
const Block = ({ basePath, blockId, components, content, events, list, loading, methods, menus, pageId, properties, required, validation, value }) => ( | ||
<div | ||
id={blockId} | ||
onClick={() => methods.triggerEvent({ name: 'onClick' })} | ||
className={methods.makeCssClass([ | ||
{ outline: 'none', cursor: events.onClick && 'pointer' }, | ||
properties.style, | ||
])} | ||
> | ||
{properties.content || (content.content && content.content())} | ||
</div> | ||
); | ||
|
||
Box.defaultProps = blockDefaultProps; | ||
Box.meta = { | ||
category: 'display', // one of 'container', 'display', 'input' or 'list' | ||
icons: [], | ||
styles: [], | ||
}; | ||
|
||
export default Box; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"content": { | ||
"type": "string", | ||
"description": "Block content string. Overrides the \"content\" content area." | ||
}, | ||
"style": { | ||
"type": "object", | ||
"description": "Css style object to apply to Block div.", | ||
"docs": { | ||
"displayType": "yaml" | ||
} | ||
} | ||
} | ||
}, | ||
"events": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"onClick": { | ||
"type": "array", | ||
"description": "Trigger actions when the Block is clicked." | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Connection } from './actions/Connection.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Request from './Request/Request.js'; | ||
import schema from './schema.js'; | ||
|
||
export default { | ||
schema, | ||
requests: { | ||
Request, | ||
}, | ||
}; |
13 changes: 13 additions & 0 deletions
13
plugins/plugin-name/connections/Connection/Request/Request.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import schema from '../schema.js'; | ||
|
||
async function Request({ request, connection }) { | ||
return null | ||
} | ||
|
||
Request.schema = schema; | ||
Request.meta = { | ||
checkRead: false, | ||
checkWrite: false, | ||
}; | ||
|
||
export default Request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
title: 'Request Schema', | ||
type: 'object', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
title: 'Connection Schema', | ||
type: 'object', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import _build_operator from './operators/build/_build_operator.js'; | ||
import _shared_operator from './operators/shared/_shared_operator.js'; | ||
|
||
export { | ||
_build_operator, | ||
_shared_operator | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function _build_operator({ | ||
args, | ||
arrayIndices, | ||
env, | ||
location, | ||
methodName, | ||
operators, | ||
params, | ||
operatorPrefix, | ||
parser, | ||
payload, | ||
runtime, | ||
user, | ||
}) { | ||
return null; | ||
} | ||
|
||
export default _build_operator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import _client_operator from './operators/client/_client_operator.js'; | ||
import _shared_operator from './operators/shared/_shared_operator.js'; | ||
|
||
export { | ||
_client_operator, | ||
_shared_operator | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function _client_operator({ | ||
actions, | ||
args, | ||
arrayIndices, | ||
basePath, | ||
event, | ||
eventLog, | ||
globals, | ||
home, | ||
input, | ||
location, | ||
lowdefyGlobal, | ||
menus, | ||
methodName, | ||
operatorPrefix, | ||
operators, | ||
pageId, | ||
params, | ||
parser, | ||
requests, | ||
runtime, | ||
state, | ||
urlQuery, | ||
user, | ||
}) { | ||
return null; | ||
} | ||
|
||
export default _client_operator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import _server_operator from './operators/server/_build_operator.js'; | ||
import _shared_operator from './operators/shared/_shared_operator.js'; | ||
|
||
export { | ||
_server_operator, | ||
_shared_operator | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function _server_operator({ | ||
args, | ||
arrayIndices, | ||
env, | ||
location, | ||
methodName, | ||
operators, | ||
params, | ||
operatorPrefix, | ||
parser, | ||
payload, | ||
runtime, | ||
user, | ||
}) { | ||
return null; | ||
} | ||
|
||
export default _server_operator; |
Oops, something went wrong.