@lowdefy/api 4.0.0-alpha.26 → 4.0.0-alpha.29
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/package.json +11 -12
- package/dist/context/createApiContext.js +0 -35
- package/dist/context/createAuthorize.js +0 -33
- package/dist/context/createReadConfigFile.js +0 -28
- package/dist/context/errors.js +0 -33
- package/dist/index.js +0 -22
- package/dist/routes/auth/callbacks/addUserFieldsToSession.js +0 -27
- package/dist/routes/auth/callbacks/addUserFieldsToToken.js +0 -36
- package/dist/routes/auth/callbacks/createCallbackPlugins.js +0 -21
- package/dist/routes/auth/callbacks/createCallbacks.js +0 -43
- package/dist/routes/auth/callbacks/createJWTCallback.js +0 -75
- package/dist/routes/auth/callbacks/createRedirectCallback.js +0 -36
- package/dist/routes/auth/callbacks/createSessionCallback.js +0 -71
- package/dist/routes/auth/callbacks/createSignInCallback.js +0 -40
- package/dist/routes/auth/createAdapter.js +0 -24
- package/dist/routes/auth/createProviders.js +0 -25
- package/dist/routes/auth/events/createCreateUserEvent.js +0 -33
- package/dist/routes/auth/events/createEventPlugins.js +0 -21
- package/dist/routes/auth/events/createEvents.js +0 -55
- package/dist/routes/auth/events/createLinkAccountEvent.js +0 -35
- package/dist/routes/auth/events/createSessionEvent.js +0 -34
- package/dist/routes/auth/events/createSignInEvent.js +0 -36
- package/dist/routes/auth/events/createSignOutEvent.js +0 -34
- package/dist/routes/auth/events/createUpdateUserEvent.js +0 -33
- package/dist/routes/auth/getNextAuthConfig.js +0 -65
- package/dist/routes/page/getPageConfig.js +0 -23
- package/dist/routes/request/authorizeRequest.js +0 -28
- package/dist/routes/request/callRequest.js +0 -91
- package/dist/routes/request/callRequestResolver.js +0 -35
- package/dist/routes/request/checkConnectionRead.js +0 -29
- package/dist/routes/request/checkConnectionWrite.js +0 -29
- package/dist/routes/request/evaluateOperators.js +0 -43
- package/dist/routes/request/getConnection.js +0 -31
- package/dist/routes/request/getConnectionConfig.js +0 -42
- package/dist/routes/request/getRequestConfig.js +0 -31
- package/dist/routes/request/getRequestResolver.js +0 -31
- package/dist/routes/request/validateSchemas.js +0 -39
- package/dist/routes/rootConfig/getHomeAndMenus.js +0 -56
- package/dist/routes/rootConfig/getLowdefyGlobal.js +0 -19
- package/dist/routes/rootConfig/getRootConfig.js +0 -28
- package/dist/routes/rootConfig/menus/filterMenuList.js +0 -41
- package/dist/routes/rootConfig/menus/filterMenus.js +0 -29
- package/dist/routes/rootConfig/menus/getMenus.js +0 -22
- package/dist/test/testContext.js +0 -41
|
@@ -1,55 +0,0 @@
|
|
|
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 createCreateUserEvent from './createCreateUserEvent.js';
|
|
16
|
-
import createLinkAccountEvent from './createLinkAccountEvent.js';
|
|
17
|
-
import createSessionEvent from './createSessionEvent.js';
|
|
18
|
-
import createSignInEvent from './createSignInEvent.js';
|
|
19
|
-
import createSignOutEvent from './createSignOutEvent.js';
|
|
20
|
-
import createUpdateUserEvent from './createUpdateUserEvent.js';
|
|
21
|
-
function createEvents(context, { authConfig , plugins }) {
|
|
22
|
-
const events = {};
|
|
23
|
-
const createUser = createCreateUserEvent(context, {
|
|
24
|
-
authConfig,
|
|
25
|
-
plugins
|
|
26
|
-
});
|
|
27
|
-
if (createUser) events.createUser = createUser;
|
|
28
|
-
const linkAccount = createLinkAccountEvent(context, {
|
|
29
|
-
authConfig,
|
|
30
|
-
plugins
|
|
31
|
-
});
|
|
32
|
-
if (linkAccount) events.linkAccount = linkAccount;
|
|
33
|
-
const session = createSessionEvent(context, {
|
|
34
|
-
authConfig,
|
|
35
|
-
plugins
|
|
36
|
-
});
|
|
37
|
-
if (session) events.session = session;
|
|
38
|
-
const signIn = createSignInEvent(context, {
|
|
39
|
-
authConfig,
|
|
40
|
-
plugins
|
|
41
|
-
});
|
|
42
|
-
if (signIn) events.signIn = signIn;
|
|
43
|
-
const signOut = createSignOutEvent(context, {
|
|
44
|
-
authConfig,
|
|
45
|
-
plugins
|
|
46
|
-
});
|
|
47
|
-
if (signOut) events.signOut = signOut;
|
|
48
|
-
const updateUser = createUpdateUserEvent(context, {
|
|
49
|
-
authConfig,
|
|
50
|
-
plugins
|
|
51
|
-
});
|
|
52
|
-
if (updateUser) events.updateUser = updateUser;
|
|
53
|
-
return events;
|
|
54
|
-
}
|
|
55
|
-
export default createEvents;
|
|
@@ -1,35 +0,0 @@
|
|
|
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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createLinkAccountEvent(context, { authConfig , plugins }) {
|
|
17
|
-
const linkAccountPlugins = createEventPlugins({
|
|
18
|
-
authConfig,
|
|
19
|
-
plugins,
|
|
20
|
-
type: 'linkAccount'
|
|
21
|
-
});
|
|
22
|
-
if (linkAccountPlugins.length === 0) return undefined;
|
|
23
|
-
async function linkAccountEvent({ account , profile , user }) {
|
|
24
|
-
for (const plugin of linkAccountPlugins){
|
|
25
|
-
await plugin.fn({
|
|
26
|
-
properties: plugin.properties ?? {},
|
|
27
|
-
account,
|
|
28
|
-
profile,
|
|
29
|
-
user
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return linkAccountEvent;
|
|
34
|
-
}
|
|
35
|
-
export default createLinkAccountEvent;
|
|
@@ -1,34 +0,0 @@
|
|
|
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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createSessionEvent(context, { authConfig , plugins }) {
|
|
17
|
-
const sessionPlugins = createEventPlugins({
|
|
18
|
-
authConfig,
|
|
19
|
-
plugins,
|
|
20
|
-
type: 'session'
|
|
21
|
-
});
|
|
22
|
-
if (sessionPlugins.length === 0) return undefined;
|
|
23
|
-
async function sessionEvent({ session , token }) {
|
|
24
|
-
for (const plugin of sessionPlugins){
|
|
25
|
-
await plugin.fn({
|
|
26
|
-
properties: plugin.properties ?? {},
|
|
27
|
-
session,
|
|
28
|
-
token
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return sessionEvent;
|
|
33
|
-
}
|
|
34
|
-
export default createSessionEvent;
|
|
@@ -1,36 +0,0 @@
|
|
|
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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createSignInEvent(context, { authConfig , plugins }) {
|
|
17
|
-
const signInPlugins = createEventPlugins({
|
|
18
|
-
authConfig,
|
|
19
|
-
plugins,
|
|
20
|
-
type: 'signIn'
|
|
21
|
-
});
|
|
22
|
-
if (signInPlugins.length === 0) return undefined;
|
|
23
|
-
async function signInEvent({ account , isNewUser , profile , user }) {
|
|
24
|
-
for (const plugin of signInPlugins){
|
|
25
|
-
await plugin.fn({
|
|
26
|
-
properties: plugin.properties ?? {},
|
|
27
|
-
account,
|
|
28
|
-
isNewUser,
|
|
29
|
-
profile,
|
|
30
|
-
user
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return signInEvent;
|
|
35
|
-
}
|
|
36
|
-
export default createSignInEvent;
|
|
@@ -1,34 +0,0 @@
|
|
|
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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createSignOutEvent(context, { authConfig , plugins }) {
|
|
17
|
-
const signInPlugins = createEventPlugins({
|
|
18
|
-
authConfig,
|
|
19
|
-
plugins,
|
|
20
|
-
type: 'signOut'
|
|
21
|
-
});
|
|
22
|
-
if (signInPlugins.length === 0) return undefined;
|
|
23
|
-
async function signInEvent({ session , token }) {
|
|
24
|
-
for (const plugin of signInPlugins){
|
|
25
|
-
await plugin.fn({
|
|
26
|
-
properties: plugin.properties ?? {},
|
|
27
|
-
session,
|
|
28
|
-
token
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return signInEvent;
|
|
33
|
-
}
|
|
34
|
-
export default createSignOutEvent;
|
|
@@ -1,33 +0,0 @@
|
|
|
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 createEventPlugins from './createEventPlugins.js';
|
|
16
|
-
function createUpdateUserEvent(context, { authConfig , plugins }) {
|
|
17
|
-
const updateUserPlugins = createEventPlugins({
|
|
18
|
-
authConfig,
|
|
19
|
-
plugins,
|
|
20
|
-
type: 'updateUser'
|
|
21
|
-
});
|
|
22
|
-
if (updateUserPlugins.length === 0) return undefined;
|
|
23
|
-
async function updateUserEvent({ user }) {
|
|
24
|
-
for (const plugin of updateUserPlugins){
|
|
25
|
-
await plugin.fn({
|
|
26
|
-
properties: plugin.properties ?? {},
|
|
27
|
-
user
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return updateUserEvent;
|
|
32
|
-
}
|
|
33
|
-
export default createUpdateUserEvent;
|
|
@@ -1,65 +0,0 @@
|
|
|
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 { NodeParser } from '@lowdefy/operators';
|
|
16
|
-
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
17
|
-
import { _secret } from '@lowdefy/operators-js/operators/server';
|
|
18
|
-
import createAdapter from './createAdapter.js';
|
|
19
|
-
import createCallbacks from './callbacks/createCallbacks.js';
|
|
20
|
-
import createEvents from './events/createEvents.js';
|
|
21
|
-
import createProviders from './createProviders.js';
|
|
22
|
-
const nextAuthConfig = {};
|
|
23
|
-
let initialized = false;
|
|
24
|
-
function getNextAuthConfig(context, { authJson , plugins }) {
|
|
25
|
-
if (initialized) return nextAuthConfig;
|
|
26
|
-
const secrets = getSecretsFromEnv();
|
|
27
|
-
// TODO: Add logger
|
|
28
|
-
const operatorsParser = new NodeParser({
|
|
29
|
-
operators: {
|
|
30
|
-
_secret
|
|
31
|
-
},
|
|
32
|
-
payload: {},
|
|
33
|
-
secrets,
|
|
34
|
-
user: {}
|
|
35
|
-
});
|
|
36
|
-
const { output: authConfig , errors: operatorErrors } = operatorsParser.parse({
|
|
37
|
-
input: authJson,
|
|
38
|
-
location: 'auth'
|
|
39
|
-
});
|
|
40
|
-
if (operatorErrors.length > 0) {
|
|
41
|
-
throw new Error(operatorErrors[0]);
|
|
42
|
-
}
|
|
43
|
-
nextAuthConfig.adapter = createAdapter(context, {
|
|
44
|
-
authConfig,
|
|
45
|
-
plugins
|
|
46
|
-
});
|
|
47
|
-
nextAuthConfig.callbacks = createCallbacks(context, {
|
|
48
|
-
authConfig,
|
|
49
|
-
plugins
|
|
50
|
-
});
|
|
51
|
-
nextAuthConfig.events = createEvents(context, {
|
|
52
|
-
authConfig,
|
|
53
|
-
plugins
|
|
54
|
-
});
|
|
55
|
-
nextAuthConfig.providers = createProviders(context, {
|
|
56
|
-
authConfig,
|
|
57
|
-
plugins
|
|
58
|
-
});
|
|
59
|
-
nextAuthConfig.session = authConfig.session;
|
|
60
|
-
nextAuthConfig.theme = authConfig.theme;
|
|
61
|
-
nextAuthConfig.cookies = authConfig?.advanced?.cookies;
|
|
62
|
-
initialized = true;
|
|
63
|
-
return nextAuthConfig;
|
|
64
|
-
}
|
|
65
|
-
export default getNextAuthConfig;
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
*/ async function getPageConfig({ authorize , readConfigFile }, { pageId }) {
|
|
16
|
-
const pageConfig = await readConfigFile(`pages/${pageId}/${pageId}.json`);
|
|
17
|
-
if (pageConfig && authorize(pageConfig)) {
|
|
18
|
-
delete pageConfig.auth;
|
|
19
|
-
return pageConfig;
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
export default getPageConfig;
|
|
@@ -1,28 +0,0 @@
|
|
|
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 { ConfigurationError } from '../../context/errors.js';
|
|
16
|
-
function authorizeRequest({ authorize , logger }, { requestConfig }) {
|
|
17
|
-
if (!authorize(requestConfig)) {
|
|
18
|
-
logger.warn({
|
|
19
|
-
authorized: false
|
|
20
|
-
}, 'Unauthorized Request');
|
|
21
|
-
// Throw does not exist error to avoid leaking information that request exists to unauthorized users
|
|
22
|
-
throw new ConfigurationError(`Request "${requestConfig.requestId}" does not exist.`);
|
|
23
|
-
}
|
|
24
|
-
logger.debug({
|
|
25
|
-
authorized: true
|
|
26
|
-
}, 'Authorize Request');
|
|
27
|
-
}
|
|
28
|
-
export default authorizeRequest;
|
|
@@ -1,91 +0,0 @@
|
|
|
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 { serializer } from '@lowdefy/helpers';
|
|
16
|
-
import authorizeRequest from './authorizeRequest.js';
|
|
17
|
-
import callRequestResolver from './callRequestResolver.js';
|
|
18
|
-
import checkConnectionRead from './checkConnectionRead.js';
|
|
19
|
-
import checkConnectionWrite from './checkConnectionWrite.js';
|
|
20
|
-
import evaluateOperators from './evaluateOperators.js';
|
|
21
|
-
import getConnection from './getConnection.js';
|
|
22
|
-
import getConnectionConfig from './getConnectionConfig.js';
|
|
23
|
-
import getRequestConfig from './getRequestConfig.js';
|
|
24
|
-
import getRequestResolver from './getRequestResolver.js';
|
|
25
|
-
import validateSchemas from './validateSchemas.js';
|
|
26
|
-
async function callRequest(context, { blockId , pageId , payload , requestId }) {
|
|
27
|
-
const { logger } = context;
|
|
28
|
-
logger.debug({
|
|
29
|
-
route: 'request',
|
|
30
|
-
params: {
|
|
31
|
-
blockId,
|
|
32
|
-
pageId,
|
|
33
|
-
payload,
|
|
34
|
-
requestId
|
|
35
|
-
}
|
|
36
|
-
}, 'Started request');
|
|
37
|
-
const requestConfig = await getRequestConfig(context, {
|
|
38
|
-
pageId,
|
|
39
|
-
requestId
|
|
40
|
-
});
|
|
41
|
-
const connectionConfig = await getConnectionConfig(context, {
|
|
42
|
-
requestConfig
|
|
43
|
-
});
|
|
44
|
-
authorizeRequest(context, {
|
|
45
|
-
requestConfig
|
|
46
|
-
});
|
|
47
|
-
const connection = getConnection(context, {
|
|
48
|
-
connectionConfig
|
|
49
|
-
});
|
|
50
|
-
const requestResolver = getRequestResolver(context, {
|
|
51
|
-
connection,
|
|
52
|
-
requestConfig
|
|
53
|
-
});
|
|
54
|
-
const { connectionProperties , requestProperties } = evaluateOperators(context, {
|
|
55
|
-
connectionConfig,
|
|
56
|
-
payload: serializer.deserialize(payload),
|
|
57
|
-
requestConfig
|
|
58
|
-
});
|
|
59
|
-
checkConnectionRead(context, {
|
|
60
|
-
connectionConfig,
|
|
61
|
-
connectionProperties,
|
|
62
|
-
requestConfig,
|
|
63
|
-
requestResolver
|
|
64
|
-
});
|
|
65
|
-
checkConnectionWrite(context, {
|
|
66
|
-
connectionConfig,
|
|
67
|
-
connectionProperties,
|
|
68
|
-
requestConfig,
|
|
69
|
-
requestResolver
|
|
70
|
-
});
|
|
71
|
-
validateSchemas(context, {
|
|
72
|
-
connection,
|
|
73
|
-
connectionProperties,
|
|
74
|
-
requestConfig,
|
|
75
|
-
requestResolver,
|
|
76
|
-
requestProperties
|
|
77
|
-
});
|
|
78
|
-
const response = await callRequestResolver(context, {
|
|
79
|
-
connectionProperties,
|
|
80
|
-
requestConfig,
|
|
81
|
-
requestResolver,
|
|
82
|
-
requestProperties
|
|
83
|
-
});
|
|
84
|
-
return {
|
|
85
|
-
id: requestConfig.id,
|
|
86
|
-
success: true,
|
|
87
|
-
type: requestConfig.type,
|
|
88
|
-
response: serializer.serialize(response)
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
export default callRequest;
|
|
@@ -1,35 +0,0 @@
|
|
|
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 { RequestError } from '../../context/errors.js';
|
|
16
|
-
async function callRequestResolver({ logger }, { connectionProperties , requestConfig , requestProperties , requestResolver }) {
|
|
17
|
-
try {
|
|
18
|
-
const response = await requestResolver({
|
|
19
|
-
request: requestProperties,
|
|
20
|
-
connection: connectionProperties
|
|
21
|
-
});
|
|
22
|
-
return response;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
const err = new RequestError(error.message);
|
|
25
|
-
logger.debug({
|
|
26
|
-
params: {
|
|
27
|
-
id: requestConfig.requestId,
|
|
28
|
-
type: requestConfig.type
|
|
29
|
-
},
|
|
30
|
-
err
|
|
31
|
-
}, err.message);
|
|
32
|
-
throw err;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export default callRequestResolver;
|
|
@@ -1,29 +0,0 @@
|
|
|
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 { ConfigurationError } from '../../context/errors.js';
|
|
16
|
-
function checkConnectionRead({ logger }, { connectionConfig , connectionProperties , requestConfig , requestResolver }) {
|
|
17
|
-
if (requestResolver.meta.checkRead && connectionProperties.read === false) {
|
|
18
|
-
const err = new ConfigurationError(`Connection "${connectionConfig.connectionId}" does not allow reads.`);
|
|
19
|
-
logger.debug({
|
|
20
|
-
params: {
|
|
21
|
-
connectionId: connectionConfig.connectionId,
|
|
22
|
-
requestId: requestConfig.requestId
|
|
23
|
-
},
|
|
24
|
-
err
|
|
25
|
-
}, err.message);
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export default checkConnectionRead;
|
|
@@ -1,29 +0,0 @@
|
|
|
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 { ConfigurationError } from '../../context/errors.js';
|
|
16
|
-
function checkConnectionWrite({ logger }, { connectionConfig , connectionProperties , requestConfig , requestResolver }) {
|
|
17
|
-
if (requestResolver.meta.checkWrite && connectionProperties.write !== true) {
|
|
18
|
-
const err = new ConfigurationError(`Connection "${connectionConfig.connectionId}" does not allow writes.`);
|
|
19
|
-
logger.debug({
|
|
20
|
-
params: {
|
|
21
|
-
connectionId: connectionConfig.connectionId,
|
|
22
|
-
requestId: requestConfig.requestId
|
|
23
|
-
},
|
|
24
|
-
err
|
|
25
|
-
}, err.message);
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export default checkConnectionWrite;
|
|
@@ -1,43 +0,0 @@
|
|
|
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 { NodeParser } from '@lowdefy/operators';
|
|
16
|
-
import { RequestError } from '../../context/errors.js';
|
|
17
|
-
function evaluateOperators({ operators , secrets , user }, { connectionConfig , payload , requestConfig }) {
|
|
18
|
-
const operatorsParser = new NodeParser({
|
|
19
|
-
operators,
|
|
20
|
-
payload,
|
|
21
|
-
secrets,
|
|
22
|
-
user
|
|
23
|
-
});
|
|
24
|
-
const { output: connectionProperties , errors: connectionErrors } = operatorsParser.parse({
|
|
25
|
-
input: connectionConfig.properties || {},
|
|
26
|
-
location: connectionConfig.connectionId
|
|
27
|
-
});
|
|
28
|
-
if (connectionErrors.length > 0) {
|
|
29
|
-
throw new RequestError(connectionErrors[0]);
|
|
30
|
-
}
|
|
31
|
-
const { output: requestProperties , errors: requestErrors } = operatorsParser.parse({
|
|
32
|
-
input: requestConfig.properties || {},
|
|
33
|
-
location: requestConfig.requestId
|
|
34
|
-
});
|
|
35
|
-
if (requestErrors.length > 0) {
|
|
36
|
-
throw new RequestError(requestErrors[0]);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
connectionProperties,
|
|
40
|
-
requestProperties
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export default evaluateOperators;
|
|
@@ -1,31 +0,0 @@
|
|
|
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 { ConfigurationError } from '../../context/errors.js';
|
|
16
|
-
function getConnection({ connections , logger }, { connectionConfig }) {
|
|
17
|
-
const connection = connections[connectionConfig.type];
|
|
18
|
-
if (!connection) {
|
|
19
|
-
const err = new ConfigurationError(`Connection type "${connectionConfig.type}" can not be found.`);
|
|
20
|
-
logger.debug({
|
|
21
|
-
params: {
|
|
22
|
-
id: connectionConfig.connectionId,
|
|
23
|
-
type: connectionConfig.type
|
|
24
|
-
},
|
|
25
|
-
err
|
|
26
|
-
}, err.message);
|
|
27
|
-
throw err;
|
|
28
|
-
}
|
|
29
|
-
return connection;
|
|
30
|
-
}
|
|
31
|
-
export default getConnection;
|
|
@@ -1,42 +0,0 @@
|
|
|
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 { ConfigurationError } from '../../context/errors.js';
|
|
16
|
-
async function getConnectionConfig({ logger , readConfigFile }, { requestConfig }) {
|
|
17
|
-
const { connectionId , requestId } = requestConfig;
|
|
18
|
-
let err;
|
|
19
|
-
if (!connectionId) {
|
|
20
|
-
err = new ConfigurationError(`Request "${requestId}" does not specify a connection.`);
|
|
21
|
-
logger.debug({
|
|
22
|
-
params: {
|
|
23
|
-
requestId
|
|
24
|
-
},
|
|
25
|
-
err
|
|
26
|
-
}, err.message);
|
|
27
|
-
throw err;
|
|
28
|
-
}
|
|
29
|
-
const connection = await readConfigFile(`connections/${connectionId}.json`);
|
|
30
|
-
if (!connection) {
|
|
31
|
-
err = new ConfigurationError(`Connection "${connectionId}" does not exist.`);
|
|
32
|
-
logger.debug({
|
|
33
|
-
params: {
|
|
34
|
-
requestId
|
|
35
|
-
},
|
|
36
|
-
err
|
|
37
|
-
}, err.message);
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
return connection;
|
|
41
|
-
}
|
|
42
|
-
export default getConnectionConfig;
|