@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/api",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.29",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -34,19 +34,18 @@
|
|
|
34
34
|
"dist/*"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "
|
|
37
|
+
"build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
|
|
38
38
|
"clean": "rm -rf dist",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
|
|
39
|
+
"prepublishOnly": "pnpm build",
|
|
40
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
42
41
|
},
|
|
43
42
|
"dependencies": {
|
|
44
|
-
"@lowdefy/ajv": "4.0.0-alpha.
|
|
45
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
46
|
-
"@lowdefy/node-utils": "4.0.0-alpha.
|
|
47
|
-
"@lowdefy/nunjucks": "4.0.0-alpha.
|
|
48
|
-
"@lowdefy/operators": "4.0.0-alpha.
|
|
49
|
-
"@lowdefy/operators-js": "4.0.0-alpha.
|
|
43
|
+
"@lowdefy/ajv": "4.0.0-alpha.29",
|
|
44
|
+
"@lowdefy/helpers": "4.0.0-alpha.29",
|
|
45
|
+
"@lowdefy/node-utils": "4.0.0-alpha.29",
|
|
46
|
+
"@lowdefy/nunjucks": "4.0.0-alpha.29",
|
|
47
|
+
"@lowdefy/operators": "4.0.0-alpha.29",
|
|
48
|
+
"@lowdefy/operators-js": "4.0.0-alpha.29"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
51
|
"@jest/globals": "28.1.0",
|
|
@@ -58,5 +57,5 @@
|
|
|
58
57
|
"publishConfig": {
|
|
59
58
|
"access": "public"
|
|
60
59
|
},
|
|
61
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "621a191ebc0a1569ee6669dc74c12f8be5a8c7f3"
|
|
62
61
|
}
|
|
@@ -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 createAuthorize from './createAuthorize.js';
|
|
16
|
-
import createReadConfigFile from './createReadConfigFile.js';
|
|
17
|
-
async function createApiContext({ buildDirectory , connections , logger , operators , secrets , session , }) {
|
|
18
|
-
const readConfigFile = createReadConfigFile({
|
|
19
|
-
buildDirectory
|
|
20
|
-
});
|
|
21
|
-
const config = await readConfigFile('config.json');
|
|
22
|
-
return {
|
|
23
|
-
authorize: createAuthorize({
|
|
24
|
-
session
|
|
25
|
-
}),
|
|
26
|
-
config,
|
|
27
|
-
connections,
|
|
28
|
-
logger,
|
|
29
|
-
operators,
|
|
30
|
-
readConfigFile,
|
|
31
|
-
secrets,
|
|
32
|
-
user: session?.user
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export default createApiContext;
|
|
@@ -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 { ServerError } from '../context/errors.js';
|
|
16
|
-
function createAuthorize({ session }) {
|
|
17
|
-
// Next-auth getSession provides a session object if the user is authenticated
|
|
18
|
-
// else session will be null
|
|
19
|
-
const authenticated = !!session;
|
|
20
|
-
const roles = session?.user?.roles ?? [];
|
|
21
|
-
function authorize({ auth }) {
|
|
22
|
-
if (auth.public === true) return true;
|
|
23
|
-
if (auth.public === false) {
|
|
24
|
-
if (auth.roles) {
|
|
25
|
-
return authenticated && auth.roles.some((role)=>roles.includes(role));
|
|
26
|
-
}
|
|
27
|
-
return authenticated;
|
|
28
|
-
}
|
|
29
|
-
throw new ServerError('Invalid auth configuration');
|
|
30
|
-
}
|
|
31
|
-
return authorize;
|
|
32
|
-
}
|
|
33
|
-
export default createAuthorize;
|
|
@@ -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 path from 'path';
|
|
16
|
-
import { cachedPromises } from '@lowdefy/helpers';
|
|
17
|
-
import { getFileExtension, readFile } from '@lowdefy/node-utils';
|
|
18
|
-
function createReadConfigFile({ buildDirectory }) {
|
|
19
|
-
async function readConfigFile(filePath) {
|
|
20
|
-
const fileContent = await readFile(path.resolve(buildDirectory, filePath));
|
|
21
|
-
if (getFileExtension(filePath) === 'json') {
|
|
22
|
-
return JSON.parse(fileContent);
|
|
23
|
-
}
|
|
24
|
-
return fileContent;
|
|
25
|
-
}
|
|
26
|
-
return cachedPromises(readConfigFile);
|
|
27
|
-
}
|
|
28
|
-
export default createReadConfigFile;
|
package/dist/context/errors.js
DELETED
|
@@ -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
|
-
*/ /* eslint-disable max-classes-per-file */ let ConfigurationError = class ConfigurationError extends Error {
|
|
16
|
-
constructor(message){
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = 'ConfigurationError';
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
let RequestError = class RequestError extends Error {
|
|
22
|
-
constructor(message){
|
|
23
|
-
super(message);
|
|
24
|
-
this.name = 'RequestError';
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
let ServerError = class ServerError extends Error {
|
|
28
|
-
constructor(message){
|
|
29
|
-
super(message);
|
|
30
|
-
this.name = 'ServerError';
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
export { ConfigurationError, RequestError, ServerError };
|
package/dist/index.js
DELETED
|
@@ -1,22 +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 callRequest from './routes/request/callRequest.js';
|
|
16
|
-
import createApiContext from './context/createApiContext.js';
|
|
17
|
-
import getHomeAndMenus from './routes/rootConfig/getHomeAndMenus.js';
|
|
18
|
-
import getNextAuthConfig from './routes/auth/getNextAuthConfig.js';
|
|
19
|
-
import getPageConfig from './routes/page/getPageConfig.js';
|
|
20
|
-
import getRootConfig from './routes/rootConfig/getRootConfig.js';
|
|
21
|
-
import { ConfigurationError, RequestError, ServerError } from './context/errors.js';
|
|
22
|
-
export { callRequest, ConfigurationError, createApiContext, getHomeAndMenus, getNextAuthConfig, getPageConfig, getRootConfig, RequestError, ServerError };
|
|
@@ -1,27 +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
|
-
*/ function addUserFieldsToSession(context, { session , token , authConfig , user }) {
|
|
16
|
-
if (token) {
|
|
17
|
-
Object.keys(authConfig.userFields).forEach((fieldName)=>{
|
|
18
|
-
session.user[fieldName] = token[fieldName];
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
if (user) {
|
|
22
|
-
Object.keys(authConfig.userFields).forEach((fieldName)=>{
|
|
23
|
-
session.user[fieldName] = user[fieldName];
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export default addUserFieldsToSession;
|
|
@@ -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 { get } from '@lowdefy/helpers';
|
|
16
|
-
function addUserFieldsToToken(context, { account , authConfig , profile , token , user }) {
|
|
17
|
-
// const { debug } = context.logger;
|
|
18
|
-
const objects = {
|
|
19
|
-
account,
|
|
20
|
-
profile,
|
|
21
|
-
user
|
|
22
|
-
};
|
|
23
|
-
// TODO: Add when debug is fixed.
|
|
24
|
-
// debug('Adding userFields to user. Available provider data is:');
|
|
25
|
-
// debug(objects);
|
|
26
|
-
Object.entries(authConfig.userFields).forEach(([lowdefyFieldName, providerFieldName])=>{
|
|
27
|
-
const value = get(objects, providerFieldName);
|
|
28
|
-
// debug(
|
|
29
|
-
// `Adding provider field "${providerFieldName}" with value ${JSON.stringify(
|
|
30
|
-
// value
|
|
31
|
-
// )} as "${lowdefyFieldName}"`
|
|
32
|
-
// );
|
|
33
|
-
token[lowdefyFieldName] = value;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
export default addUserFieldsToToken;
|
|
@@ -1,21 +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
|
-
*/ function createCallbackPlugins({ authConfig , plugins , type }) {
|
|
16
|
-
return authConfig.callbacks.map((callbackConfig)=>({
|
|
17
|
-
fn: plugins.callbacks[callbackConfig.type],
|
|
18
|
-
properties: callbackConfig.properties
|
|
19
|
-
})).filter((callback)=>callback.fn.meta.type === type);
|
|
20
|
-
}
|
|
21
|
-
export default createCallbackPlugins;
|
|
@@ -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 createJWTCallback from './createJWTCallback.js';
|
|
16
|
-
import createRedirectCallback from './createRedirectCallback.js';
|
|
17
|
-
import createSessionCallback from './createSessionCallback.js';
|
|
18
|
-
import createSignInCallback from './createSignInCallback.js';
|
|
19
|
-
function createCallbacks(context, { authConfig , plugins }) {
|
|
20
|
-
const callbacks = {
|
|
21
|
-
session: createSessionCallback(context, {
|
|
22
|
-
authConfig,
|
|
23
|
-
plugins
|
|
24
|
-
})
|
|
25
|
-
};
|
|
26
|
-
const jwt = createJWTCallback(context, {
|
|
27
|
-
authConfig,
|
|
28
|
-
plugins
|
|
29
|
-
});
|
|
30
|
-
if (jwt) callbacks.jwt = jwt;
|
|
31
|
-
const redirect = createRedirectCallback(context, {
|
|
32
|
-
authConfig,
|
|
33
|
-
plugins
|
|
34
|
-
});
|
|
35
|
-
if (redirect) callbacks.redirect = redirect;
|
|
36
|
-
const signIn = createSignInCallback(context, {
|
|
37
|
-
authConfig,
|
|
38
|
-
plugins
|
|
39
|
-
});
|
|
40
|
-
if (signIn) callbacks.signIn = signIn;
|
|
41
|
-
return callbacks;
|
|
42
|
-
}
|
|
43
|
-
export default createCallbacks;
|
|
@@ -1,75 +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 addUserFieldsToToken from './addUserFieldsToToken.js';
|
|
16
|
-
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
17
|
-
function createJWTCallback(context, { authConfig , plugins }) {
|
|
18
|
-
const jwtCallbackPlugins = createCallbackPlugins({
|
|
19
|
-
authConfig,
|
|
20
|
-
plugins,
|
|
21
|
-
type: 'jwt'
|
|
22
|
-
});
|
|
23
|
-
async function jwtCallback({ token , user , account , profile , isNewUser }) {
|
|
24
|
-
if (profile) {
|
|
25
|
-
const { sub , name , given_name , family_name , middle_name , nickname , preferred_username , profile: profile_claim , picture , website , email , email_verified , gender , birthdate , zoneinfo , locale , phone_number , phone_number_verified , address , updated_at , } = profile;
|
|
26
|
-
token = {
|
|
27
|
-
sub,
|
|
28
|
-
name,
|
|
29
|
-
given_name,
|
|
30
|
-
family_name,
|
|
31
|
-
middle_name,
|
|
32
|
-
nickname,
|
|
33
|
-
preferred_username,
|
|
34
|
-
profile: profile_claim,
|
|
35
|
-
picture,
|
|
36
|
-
website,
|
|
37
|
-
email,
|
|
38
|
-
email_verified,
|
|
39
|
-
gender,
|
|
40
|
-
birthdate,
|
|
41
|
-
zoneinfo,
|
|
42
|
-
locale,
|
|
43
|
-
phone_number,
|
|
44
|
-
phone_number_verified,
|
|
45
|
-
address,
|
|
46
|
-
updated_at,
|
|
47
|
-
...token
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (profile || user) {
|
|
51
|
-
if (authConfig.userFields) {
|
|
52
|
-
addUserFieldsToToken(context, {
|
|
53
|
-
authConfig,
|
|
54
|
-
account,
|
|
55
|
-
profile,
|
|
56
|
-
token,
|
|
57
|
-
user
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
for (const plugin of jwtCallbackPlugins){
|
|
62
|
-
token = await plugin.fn({
|
|
63
|
-
properties: plugin.properties ?? {},
|
|
64
|
-
account,
|
|
65
|
-
isNewUser,
|
|
66
|
-
profile,
|
|
67
|
-
token,
|
|
68
|
-
user
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return token;
|
|
72
|
-
}
|
|
73
|
-
return jwtCallback;
|
|
74
|
-
}
|
|
75
|
-
export default createJWTCallback;
|
|
@@ -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 createCallbackPlugins from './createCallbackPlugins.js';
|
|
16
|
-
function createRedirectCallback(context, { authConfig , plugins }) {
|
|
17
|
-
const redirectCallbackPlugins = createCallbackPlugins({
|
|
18
|
-
authConfig,
|
|
19
|
-
plugins,
|
|
20
|
-
type: 'redirect'
|
|
21
|
-
});
|
|
22
|
-
if (redirectCallbackPlugins.length === 0) return undefined;
|
|
23
|
-
if (redirectCallbackPlugins.length !== 1) {
|
|
24
|
-
throw new Error('More than one auth redirect callbacks are configured. Only one is allowed.');
|
|
25
|
-
}
|
|
26
|
-
const [plugin] = redirectCallbackPlugins;
|
|
27
|
-
async function redirectCallback({ url , baseUrl }) {
|
|
28
|
-
return plugin.fn({
|
|
29
|
-
properties: plugin.properties ?? {},
|
|
30
|
-
baseUrl,
|
|
31
|
-
url
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return redirectCallback;
|
|
35
|
-
}
|
|
36
|
-
export default createRedirectCallback;
|
|
@@ -1,71 +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 addUserFieldsToSession from './addUserFieldsToSession.js';
|
|
16
|
-
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
17
|
-
function createSessionCallback(context, { authConfig , plugins }) {
|
|
18
|
-
const sessionCallbackPlugins = createCallbackPlugins({
|
|
19
|
-
authConfig,
|
|
20
|
-
plugins,
|
|
21
|
-
type: 'session'
|
|
22
|
-
});
|
|
23
|
-
async function sessionCallback({ session , token , user }) {
|
|
24
|
-
if (token) {
|
|
25
|
-
const { sub , name , given_name , family_name , middle_name , nickname , preferred_username , profile , picture , website , email , email_verified , gender , birthdate , zoneinfo , locale , phone_number , phone_number_verified , address , updated_at , } = token;
|
|
26
|
-
session.user = {
|
|
27
|
-
sub,
|
|
28
|
-
name,
|
|
29
|
-
given_name,
|
|
30
|
-
family_name,
|
|
31
|
-
middle_name,
|
|
32
|
-
nickname,
|
|
33
|
-
preferred_username,
|
|
34
|
-
profile,
|
|
35
|
-
picture,
|
|
36
|
-
website,
|
|
37
|
-
email,
|
|
38
|
-
email_verified,
|
|
39
|
-
gender,
|
|
40
|
-
birthdate,
|
|
41
|
-
zoneinfo,
|
|
42
|
-
locale,
|
|
43
|
-
phone_number,
|
|
44
|
-
phone_number_verified,
|
|
45
|
-
address,
|
|
46
|
-
updated_at,
|
|
47
|
-
...session.user
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (authConfig.userFields) {
|
|
51
|
-
addUserFieldsToSession(context, {
|
|
52
|
-
authConfig,
|
|
53
|
-
session,
|
|
54
|
-
token,
|
|
55
|
-
user
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
for (const plugin of sessionCallbackPlugins){
|
|
59
|
-
// eslint-disable-next-line no-param-reassign
|
|
60
|
-
session = await plugin.fn({
|
|
61
|
-
properties: plugin.properties ?? {},
|
|
62
|
-
session,
|
|
63
|
-
token,
|
|
64
|
-
user
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return session;
|
|
68
|
-
}
|
|
69
|
-
return sessionCallback;
|
|
70
|
-
}
|
|
71
|
-
export default createSessionCallback;
|
|
@@ -1,40 +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 createCallbackPlugins from './createCallbackPlugins.js';
|
|
16
|
-
function createSignInCallback(context, { authConfig , plugins }) {
|
|
17
|
-
const signInCallbackPlugins = createCallbackPlugins({
|
|
18
|
-
authConfig,
|
|
19
|
-
plugins,
|
|
20
|
-
type: 'signIn'
|
|
21
|
-
});
|
|
22
|
-
if (signInCallbackPlugins.length === 0) return undefined;
|
|
23
|
-
async function signInCallback({ account , credentials , email , profile , user }) {
|
|
24
|
-
let allowSignIn = true;
|
|
25
|
-
for (const plugin of signInCallbackPlugins){
|
|
26
|
-
allowSignIn = await plugin.fn({
|
|
27
|
-
properties: plugin.properties ?? {},
|
|
28
|
-
account,
|
|
29
|
-
credentials,
|
|
30
|
-
email,
|
|
31
|
-
profile,
|
|
32
|
-
user
|
|
33
|
-
});
|
|
34
|
-
if (allowSignIn === false) break;
|
|
35
|
-
}
|
|
36
|
-
return allowSignIn;
|
|
37
|
-
}
|
|
38
|
-
return signInCallback;
|
|
39
|
-
}
|
|
40
|
-
export default createSignInCallback;
|
|
@@ -1,24 +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
|
-
*/ function createAdapter(context, { authConfig , plugins }) {
|
|
16
|
-
const adapterConfig = authConfig.adapter;
|
|
17
|
-
if (!adapterConfig) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
return plugins.adapters[adapterConfig.type]({
|
|
21
|
-
properties: adapterConfig.properties
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
export default createAdapter;
|
|
@@ -1,25 +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
|
-
*/ // TODO: docs:
|
|
16
|
-
// Callback url to configure with provider will be: {{ protocol }}{{ host }}/api/auth/callback/{{ providerId }}
|
|
17
|
-
// This depends on providerId, which might cause some issues if users copy an example and change the id.
|
|
18
|
-
// We need to allow users to configure ids, since they might have more than one of the same type.
|
|
19
|
-
function createProviders(context, { authConfig , plugins }) {
|
|
20
|
-
return authConfig.providers.map((providerConfig)=>plugins.providers[providerConfig.type]({
|
|
21
|
-
...providerConfig.properties,
|
|
22
|
-
id: providerConfig.id
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
export default createProviders;
|
|
@@ -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 createCreateUserEvent(context, { authConfig , plugins }) {
|
|
17
|
-
const createUserPlugins = createEventPlugins({
|
|
18
|
-
authConfig,
|
|
19
|
-
plugins,
|
|
20
|
-
type: 'createUser'
|
|
21
|
-
});
|
|
22
|
-
if (createUserPlugins.length === 0) return undefined;
|
|
23
|
-
async function createUserEvent({ user }) {
|
|
24
|
-
for (const plugin of createUserPlugins){
|
|
25
|
-
await plugin.fn({
|
|
26
|
-
properties: plugin.properties ?? {},
|
|
27
|
-
user
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return createUserEvent;
|
|
32
|
-
}
|
|
33
|
-
export default createCreateUserEvent;
|
|
@@ -1,21 +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
|
-
*/ function createEventPlugins({ authConfig , plugins , type }) {
|
|
16
|
-
return authConfig.events.map((eventConfig)=>({
|
|
17
|
-
fn: plugins.events[eventConfig.type],
|
|
18
|
-
properties: eventConfig.properties
|
|
19
|
-
})).filter((event)=>event.fn.meta.type === type);
|
|
20
|
-
}
|
|
21
|
-
export default createEventPlugins;
|