@lowdefy/api 4.0.0-rc.8 → 4.0.0

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.
Files changed (45) hide show
  1. package/dist/context/createApiContext.js +5 -18
  2. package/dist/context/createAuthorize.js +4 -4
  3. package/dist/context/createReadConfigFile.js +2 -2
  4. package/dist/context/errors.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/routes/auth/callbacks/addUserFieldsToSession.js +5 -4
  7. package/dist/routes/auth/callbacks/addUserFieldsToToken.js +7 -13
  8. package/dist/routes/auth/callbacks/createCallbackPlugins.js +2 -2
  9. package/dist/routes/auth/callbacks/createCallbacks.js +9 -6
  10. package/dist/routes/auth/callbacks/createJWTCallback.js +7 -5
  11. package/dist/routes/auth/callbacks/createRedirectCallback.js +9 -4
  12. package/dist/routes/auth/callbacks/createSessionCallback.js +12 -6
  13. package/dist/routes/auth/callbacks/createSignInCallback.js +3 -3
  14. package/dist/routes/auth/createAdapter.js +2 -2
  15. package/dist/routes/auth/createLogger.js +34 -0
  16. package/dist/routes/auth/createProviders.js +2 -2
  17. package/dist/routes/auth/events/createCreateUserEvent.js +12 -4
  18. package/dist/routes/auth/events/createEventPlugins.js +2 -2
  19. package/dist/routes/auth/events/createEvents.js +30 -29
  20. package/dist/routes/auth/events/createLinkAccountEvent.js +12 -4
  21. package/dist/routes/auth/events/createSessionEvent.js +3 -3
  22. package/dist/routes/auth/events/createSignInEvent.js +14 -4
  23. package/dist/routes/auth/events/createSignOutEvent.js +16 -7
  24. package/dist/routes/auth/events/createUpdateUserEvent.js +12 -4
  25. package/dist/routes/auth/getNextAuthConfig.js +18 -11
  26. package/dist/routes/page/getPageConfig.js +3 -3
  27. package/dist/routes/request/authorizeRequest.js +11 -7
  28. package/dist/routes/request/callRequest.js +10 -12
  29. package/dist/routes/request/callRequestResolver.js +3 -2
  30. package/dist/routes/request/checkConnectionRead.js +2 -2
  31. package/dist/routes/request/checkConnectionWrite.js +2 -2
  32. package/dist/routes/request/evaluateOperators.js +5 -5
  33. package/dist/routes/request/getConnection.js +2 -2
  34. package/dist/routes/request/getConnectionConfig.js +3 -3
  35. package/dist/routes/request/getRequestConfig.js +2 -2
  36. package/dist/routes/request/getRequestResolver.js +2 -2
  37. package/dist/routes/request/validateSchemas.js +2 -2
  38. package/dist/routes/rootConfig/getHomeAndMenus.js +1 -1
  39. package/dist/routes/rootConfig/getLowdefyGlobal.js +2 -2
  40. package/dist/routes/rootConfig/getRootConfig.js +2 -2
  41. package/dist/routes/rootConfig/menus/filterMenuList.js +3 -3
  42. package/dist/routes/rootConfig/menus/filterMenus.js +2 -2
  43. package/dist/routes/rootConfig/menus/getMenus.js +1 -1
  44. package/dist/test/testContext.js +5 -8
  45. package/package.json +18 -20
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,22 +14,9 @@
14
14
  limitations under the License.
15
15
  */ import createAuthorize from './createAuthorize.js';
16
16
  import createReadConfigFile from './createReadConfigFile.js';
17
- function createApiContext({ buildDirectory , config , connections , fileCache , logger , operators , secrets , session }) {
18
- const readConfigFile = createReadConfigFile({
19
- buildDirectory,
20
- fileCache
21
- });
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
- };
17
+ function createApiContext(context) {
18
+ context.readConfigFile = createReadConfigFile(context);
19
+ context.authorize = createAuthorize(context);
20
+ context.user = context?.session?.user;
34
21
  }
35
22
  export default createApiContext;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,13 +12,13 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import { ServerError } from '../context/errors.js';
16
- function createAuthorize({ session }) {
15
+ */ import { ServerError } from './errors.js';
16
+ function createAuthorize({ session }) {
17
17
  // Next-auth getSession provides a session object if the user is authenticated
18
18
  // else session will be null
19
19
  const authenticated = !!session;
20
20
  const roles = session?.user?.roles ?? [];
21
- function authorize({ auth }) {
21
+ function authorize({ auth }) {
22
22
  if (auth.public === true) return true;
23
23
  if (auth.public === false) {
24
24
  if (auth.roles) {
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
  */ import path from 'path';
16
16
  import { cachedPromises } from '@lowdefy/helpers';
17
17
  import { getFileExtension, readFile } from '@lowdefy/node-utils';
18
- function createReadConfigFile({ buildDirectory , fileCache }) {
18
+ function createReadConfigFile({ buildDirectory, fileCache }) {
19
19
  async function readConfigFile(filePath) {
20
20
  const fileContent = await readFile(path.resolve(buildDirectory, filePath));
21
21
  if (getFileExtension(filePath) === 'json') {
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,15 +12,16 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function addUserFieldsToSession(context, { session , token , authConfig , user }) {
15
+ */ import { get, set } from '@lowdefy/helpers';
16
+ function addUserFieldsToSession({ session, token, authConfig, user }) {
16
17
  if (token) {
17
18
  Object.keys(authConfig.userFields).forEach((fieldName)=>{
18
- session.user[fieldName] = token[fieldName];
19
+ set(session.user, fieldName, get(token, fieldName));
19
20
  });
20
21
  }
21
22
  if (user) {
22
23
  Object.keys(authConfig.userFields).forEach((fieldName)=>{
23
- session.user[fieldName] = user[fieldName];
24
+ set(session.user, fieldName, get(user, fieldName));
24
25
  });
25
26
  }
26
27
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,25 +12,19 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
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;
15
+ */ import { get, set } from '@lowdefy/helpers';
16
+ function addUserFieldsToToken({ account, authConfig, logger, profile, token, user }) {
18
17
  const objects = {
19
18
  account,
20
19
  profile,
21
20
  user
22
21
  };
23
- // TODO: Add when debug is fixed.
24
- // debug('Adding userFields to user. Available provider data is:');
25
- // debug(objects);
22
+ logger.debug('Adding userFields to user. Available provider data is:');
23
+ logger.debug(objects);
26
24
  Object.entries(authConfig.userFields).forEach(([lowdefyFieldName, providerFieldName])=>{
27
25
  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;
26
+ logger.debug(`Adding provider field "${providerFieldName}" with value ${JSON.stringify(value)} as "${lowdefyFieldName}"`);
27
+ set(token, lowdefyFieldName, value);
34
28
  });
35
29
  }
36
30
  export default addUserFieldsToToken;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function createCallbackPlugins({ authConfig , plugins , type }) {
15
+ */ function createCallbackPlugins({ authConfig, plugins, type }) {
16
16
  return authConfig.callbacks.map((callbackConfig)=>({
17
17
  fn: plugins.callbacks[callbackConfig.type],
18
18
  properties: callbackConfig.properties
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -16,24 +16,27 @@
16
16
  import createRedirectCallback from './createRedirectCallback.js';
17
17
  import createSessionCallback from './createSessionCallback.js';
18
18
  import createSignInCallback from './createSignInCallback.js';
19
- function createCallbacks(context, { authConfig , plugins }) {
19
+ function createCallbacks({ authConfig, logger, plugins }) {
20
20
  const callbacks = {
21
- session: createSessionCallback(context, {
21
+ session: createSessionCallback({
22
22
  authConfig,
23
+ logger,
23
24
  plugins
24
25
  })
25
26
  };
26
- const jwt = createJWTCallback(context, {
27
+ const jwt = createJWTCallback({
27
28
  authConfig,
29
+ logger,
28
30
  plugins
29
31
  });
30
32
  if (jwt) callbacks.jwt = jwt;
31
- const redirect = createRedirectCallback(context, {
33
+ const redirect = createRedirectCallback({
32
34
  authConfig,
35
+ logger,
33
36
  plugins
34
37
  });
35
38
  if (redirect) callbacks.redirect = redirect;
36
- const signIn = createSignInCallback(context, {
39
+ const signIn = createSignInCallback({
37
40
  authConfig,
38
41
  plugins
39
42
  });
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,16 +14,17 @@
14
14
  limitations under the License.
15
15
  */ import addUserFieldsToToken from './addUserFieldsToToken.js';
16
16
  import createCallbackPlugins from './createCallbackPlugins.js';
17
- function createJWTCallback(context, { authConfig , plugins }) {
17
+ function createJWTCallback({ authConfig, logger, plugins }) {
18
18
  const jwtCallbackPlugins = createCallbackPlugins({
19
19
  authConfig,
20
20
  plugins,
21
21
  type: 'jwt'
22
22
  });
23
- async function jwtCallback({ token , user , account , profile , isNewUser }) {
23
+ async function jwtCallback({ token, user, account, profile, isNewUser }) {
24
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;
25
+ const { id, 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
26
  token = {
27
+ id,
27
28
  sub,
28
29
  name,
29
30
  given_name,
@@ -49,9 +50,10 @@ function createJWTCallback(context, { authConfig , plugins }) {
49
50
  }
50
51
  if (profile || user) {
51
52
  if (authConfig.userFields) {
52
- addUserFieldsToToken(context, {
53
+ addUserFieldsToToken({
53
54
  authConfig,
54
55
  account,
56
+ logger,
55
57
  profile,
56
58
  token,
57
59
  user
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,18 +13,23 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createCallbackPlugins from './createCallbackPlugins.js';
16
- function createRedirectCallback(context, { authConfig , plugins }) {
16
+ function defaultRedirect({ url, baseUrl }) {
17
+ if (url.startsWith('/')) return `${baseUrl}${url}`;
18
+ else if (new URL(url).origin === baseUrl) return url;
19
+ return baseUrl;
20
+ }
21
+ function createRedirectCallback({ authConfig, plugins }) {
17
22
  const redirectCallbackPlugins = createCallbackPlugins({
18
23
  authConfig,
19
24
  plugins,
20
25
  type: 'redirect'
21
26
  });
22
- if (redirectCallbackPlugins.length === 0) return undefined;
27
+ if (redirectCallbackPlugins.length === 0) return defaultRedirect;
23
28
  if (redirectCallbackPlugins.length !== 1) {
24
29
  throw new Error('More than one auth redirect callbacks are configured. Only one is allowed.');
25
30
  }
26
31
  const [plugin] = redirectCallbackPlugins;
27
- async function redirectCallback({ url , baseUrl }) {
32
+ function redirectCallback({ url, baseUrl }) {
28
33
  return plugin.fn({
29
34
  properties: plugin.properties ?? {},
30
35
  baseUrl,
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,18 +12,21 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import addUserFieldsToSession from './addUserFieldsToSession.js';
15
+ */ import crypto from 'crypto';
16
+ import addUserFieldsToSession from './addUserFieldsToSession.js';
16
17
  import createCallbackPlugins from './createCallbackPlugins.js';
17
- function createSessionCallback(context, { authConfig , plugins }) {
18
+ function createSessionCallback({ authConfig, plugins }) {
18
19
  const sessionCallbackPlugins = createCallbackPlugins({
19
20
  authConfig,
20
21
  plugins,
21
22
  type: 'session'
22
23
  });
23
- async function sessionCallback({ session , token , user }) {
24
+ async function sessionCallback({ session, token, user }) {
25
+ const identifier = user ? user.id ?? user.sub ?? user.email : token.id ?? token.sub ?? token.email;
24
26
  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;
27
+ const { id, 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
28
  session.user = {
29
+ id,
27
30
  sub,
28
31
  name,
29
32
  given_name,
@@ -48,7 +51,7 @@ function createSessionCallback(context, { authConfig , plugins }) {
48
51
  };
49
52
  }
50
53
  if (authConfig.userFields) {
51
- addUserFieldsToSession(context, {
54
+ addUserFieldsToSession({
52
55
  authConfig,
53
56
  session,
54
57
  token,
@@ -64,6 +67,9 @@ function createSessionCallback(context, { authConfig , plugins }) {
64
67
  user
65
68
  });
66
69
  }
70
+ // TODO: Should this be session.hashed_id or session.user.hashed_id
71
+ // Only session.user will be available using the _user operator
72
+ session.hashed_id = crypto.createHash('sha256').update(identifier ?? '').digest('base64');
67
73
  return session;
68
74
  }
69
75
  return sessionCallback;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,14 +13,14 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createCallbackPlugins from './createCallbackPlugins.js';
16
- function createSignInCallback(context, { authConfig , plugins }) {
16
+ function createSignInCallback({ authConfig, plugins }) {
17
17
  const signInCallbackPlugins = createCallbackPlugins({
18
18
  authConfig,
19
19
  plugins,
20
20
  type: 'signIn'
21
21
  });
22
22
  if (signInCallbackPlugins.length === 0) return undefined;
23
- async function signInCallback({ account , credentials , email , profile , user }) {
23
+ async function signInCallback({ account, credentials, email, profile, user }) {
24
24
  let allowSignIn = true;
25
25
  for (const plugin of signInCallbackPlugins){
26
26
  allowSignIn = await plugin.fn({
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function createAdapter(context, { authConfig , plugins }) {
15
+ */ function createAdapter({ authConfig, plugins }) {
16
16
  const adapterConfig = authConfig.adapter;
17
17
  if (!adapterConfig) {
18
18
  return undefined;
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright 2020-2024 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 createLogger({ logger }) {
16
+ return {
17
+ error: (code, metadata)=>logger.error({
18
+ code,
19
+ metadata,
20
+ event: 'auth_error'
21
+ }),
22
+ warn: (code, metadata)=>logger.warn({
23
+ code,
24
+ metadata,
25
+ event: 'auth_warning'
26
+ }),
27
+ debug: (code, metadata)=>logger.debug({
28
+ code,
29
+ metadata,
30
+ event: 'auth_debug'
31
+ })
32
+ };
33
+ }
34
+ export default createLogger;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
16
16
  // Callback url to configure with provider will be: {{ protocol }}{{ host }}/api/auth/callback/{{ providerId }}
17
17
  // This depends on providerId, which might cause some issues if users copy an example and change the id.
18
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 }) {
19
+ function createProviders({ authConfig, plugins }) {
20
20
  return authConfig.providers.map((providerConfig)=>plugins.providers[providerConfig.type]({
21
21
  ...providerConfig.properties,
22
22
  id: providerConfig.id
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,14 +13,22 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createEventPlugins from './createEventPlugins.js';
16
- function createCreateUserEvent(context, { authConfig , plugins }) {
16
+ function createCreateUserEvent({ authConfig, logger, plugins }) {
17
17
  const createUserPlugins = createEventPlugins({
18
18
  authConfig,
19
19
  plugins,
20
20
  type: 'createUser'
21
21
  });
22
- if (createUserPlugins.length === 0) return undefined;
23
- async function createUserEvent({ user }) {
22
+ async function createUserEvent({ user }) {
23
+ logger.info({
24
+ event: 'auth_create_user',
25
+ user: {
26
+ id: user.id,
27
+ roles: user.roles,
28
+ sub: user.sub,
29
+ session_id: user.session_id
30
+ }
31
+ });
24
32
  for (const plugin of createUserPlugins){
25
33
  await plugin.fn({
26
34
  properties: plugin.properties ?? {},
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function createEventPlugins({ authConfig , plugins , type }) {
15
+ */ function createEventPlugins({ authConfig, plugins, type }) {
16
16
  return authConfig.events.map((eventConfig)=>({
17
17
  fn: plugins.events[eventConfig.type],
18
18
  properties: eventConfig.properties
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -18,38 +18,39 @@ import createSessionEvent from './createSessionEvent.js';
18
18
  import createSignInEvent from './createSignInEvent.js';
19
19
  import createSignOutEvent from './createSignOutEvent.js';
20
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, {
21
+ function createEvents({ authConfig, logger, plugins }) {
22
+ const events = {
23
+ createUser: createCreateUserEvent({
24
+ authConfig,
25
+ logger,
26
+ plugins
27
+ }),
28
+ linkAccount: createLinkAccountEvent({
29
+ authConfig,
30
+ logger,
31
+ plugins
32
+ }),
33
+ signIn: createSignInEvent({
34
+ authConfig,
35
+ logger,
36
+ plugins
37
+ }),
38
+ signOut: createSignOutEvent({
39
+ authConfig,
40
+ logger,
41
+ plugins
42
+ }),
43
+ updateUser: createUpdateUserEvent({
44
+ authConfig,
45
+ logger,
46
+ plugins
47
+ })
48
+ };
49
+ const session = createSessionEvent({
34
50
  authConfig,
35
51
  plugins
36
52
  });
37
53
  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
54
  return events;
54
55
  }
55
56
  export default createEvents;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,14 +13,22 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createEventPlugins from './createEventPlugins.js';
16
- function createLinkAccountEvent(context, { authConfig , plugins }) {
16
+ function createLinkAccountEvent({ authConfig, logger, plugins }) {
17
17
  const linkAccountPlugins = createEventPlugins({
18
18
  authConfig,
19
19
  plugins,
20
20
  type: 'linkAccount'
21
21
  });
22
- if (linkAccountPlugins.length === 0) return undefined;
23
- async function linkAccountEvent({ account , profile , user }) {
22
+ async function linkAccountEvent({ account, profile, user }) {
23
+ logger.info({
24
+ event: 'auth_link_account',
25
+ user: {
26
+ id: user.id,
27
+ roles: user.roles,
28
+ sub: user.sub,
29
+ session_id: user.session_id
30
+ }
31
+ });
24
32
  for (const plugin of linkAccountPlugins){
25
33
  await plugin.fn({
26
34
  properties: plugin.properties ?? {},
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,14 +13,14 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createEventPlugins from './createEventPlugins.js';
16
- function createSessionEvent(context, { authConfig , plugins }) {
16
+ function createSessionEvent({ authConfig, plugins }) {
17
17
  const sessionPlugins = createEventPlugins({
18
18
  authConfig,
19
19
  plugins,
20
20
  type: 'session'
21
21
  });
22
22
  if (sessionPlugins.length === 0) return undefined;
23
- async function sessionEvent({ session , token }) {
23
+ async function sessionEvent({ session, token }) {
24
24
  for (const plugin of sessionPlugins){
25
25
  await plugin.fn({
26
26
  properties: plugin.properties ?? {},
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2023 Lowdefy, Inc
2
+ Copyright 2020-2024 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,14 +13,24 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createEventPlugins from './createEventPlugins.js';
16
- function createSignInEvent(context, { authConfig , plugins }) {
16
+ function createSignInEvent({ authConfig, logger, plugins }) {
17
17
  const signInPlugins = createEventPlugins({
18
18
  authConfig,
19
19
  plugins,
20
20
  type: 'signIn'
21
21
  });
22
- if (signInPlugins.length === 0) return undefined;
23
- async function signInEvent({ account , isNewUser , profile , user }) {
22
+ async function signInEvent({ account, isNewUser, profile, user }) {
23
+ logger.info({
24
+ event: 'auth_sign_in',
25
+ isNewUser,
26
+ provider: account?.provider,
27
+ user: {
28
+ id: user.id,
29
+ roles: user.roles,
30
+ sub: user.sub,
31
+ session_id: user.session_id
32
+ }
33
+ });
24
34
  for (const plugin of signInPlugins){
25
35
  await plugin.fn({
26
36
  properties: plugin.properties ?? {},