@lowdefy/api 0.0.0-experimental-20260720072521 → 0.0.0-experimental-20260720135014
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context/createApiContext.js +1 -9
- package/dist/context/createAuthorize.js +8 -19
- package/dist/context/createEvaluateOperators.js +1 -2
- package/dist/index.js +3 -13
- package/dist/routes/agent/callAgent.js +180 -7
- package/dist/routes/{websocket/authorizeWebsocket.js → auth/callbacks/addUserFieldsToSession.js} +11 -10
- package/dist/routes/auth/callbacks/addUserFieldsToToken.js +30 -0
- package/dist/routes/auth/{hooks/composeAfterSlot.js → callbacks/createCallbackPlugins.js} +6 -11
- package/dist/routes/auth/callbacks/createCallbacks.js +46 -0
- package/dist/routes/auth/callbacks/createJWTCallback.js +77 -0
- package/dist/routes/auth/callbacks/createRedirectCallback.js +41 -0
- package/dist/routes/auth/callbacks/createSessionCallback.js +81 -0
- package/dist/routes/auth/callbacks/createSignInCallback.js +40 -0
- package/dist/routes/auth/callbacks/validateSessionRoles.js +33 -0
- package/dist/routes/{websocket/getWebsocketConfig.js → auth/createAdapter.js} +8 -14
- package/dist/routes/auth/createLogger.js +38 -0
- package/dist/routes/auth/createProviders.js +25 -0
- package/dist/routes/auth/events/createCreateUserEvent.js +41 -0
- package/dist/routes/auth/{organizations/getHookRequestHeaders.js → events/createEventPlugins.js} +6 -9
- package/dist/routes/auth/events/createEvents.js +56 -0
- package/dist/routes/auth/events/createLinkAccountEvent.js +43 -0
- package/dist/routes/auth/{strategies/getAuthStrategies.js → events/createSessionEvent.js} +17 -14
- package/dist/routes/auth/events/createSignInEvent.js +46 -0
- package/dist/routes/auth/events/createSignOutEvent.js +43 -0
- package/dist/routes/auth/events/createUpdateUserEvent.js +41 -0
- package/dist/routes/auth/getNextAuthConfig.js +75 -0
- package/dist/routes/endpoints/authorizeApiEndpoint.js +2 -8
- package/dist/routes/endpoints/callEndpoint.js +0 -20
- package/dist/routes/endpoints/control/controlReject.js +1 -3
- package/dist/routes/endpoints/control/controlThrow.js +1 -4
- package/dist/routes/endpoints/handleEndpointCall.js +1 -62
- package/dist/routes/endpoints/handleRequest.js +1 -8
- package/dist/routes/endpoints/handleValidateSchema.js +1 -3
- package/dist/routes/endpoints/runRoutine.js +0 -18
- package/dist/routes/endpoints/test/runTest.js +4 -3
- package/dist/routes/page/getPageConfig.js +8 -42
- package/dist/routes/request/authorizeRequest.js +2 -8
- package/dist/routes/request/callRequest.js +1 -8
- package/dist/routes/request/callRequestResolver.js +2 -6
- package/dist/test/testContext.js +6 -6
- package/package.json +10 -16
- package/dist/context/applySystemTrust.js +0 -33
- package/dist/context/createSystemContext.js +0 -72
- package/dist/context/normalizeInjectedCaller.js +0 -41
- package/dist/context/resolveAuthentication.js +0 -107
- package/dist/context/resolveStrategyCaller.js +0 -56
- package/dist/email/renderAuthEmail.js +0 -98
- package/dist/email/resolveThemeLogo.js +0 -35
- package/dist/routes/agent/prepareAgent.js +0 -169
- package/dist/routes/auth/buildAdminPlugin.js +0 -55
- package/dist/routes/auth/buildCaptchaPlugin.js +0 -61
- package/dist/routes/auth/buildPhoneNumberPlugin.js +0 -57
- package/dist/routes/auth/buildProviders.js +0 -51
- package/dist/routes/auth/createAuthLogger.js +0 -31
- package/dist/routes/auth/createSendEmail.js +0 -49
- package/dist/routes/auth/getBetterAuth.js +0 -72
- package/dist/routes/auth/getBetterAuthConfig.js +0 -439
- package/dist/routes/auth/getUserAdminRole.js +0 -32
- package/dist/routes/auth/hooks/authHookPoints.js +0 -192
- package/dist/routes/auth/hooks/buildEngineHooks.js +0 -43
- package/dist/routes/auth/hooks/buildHooks.js +0 -111
- package/dist/routes/auth/hooks/composeBeforeSlot.js +0 -41
- package/dist/routes/auth/hooks/createHookDispatch.js +0 -59
- package/dist/routes/auth/hooks/createUserAfterHook.js +0 -33
- package/dist/routes/auth/hooks/createUserBeforeHook.js +0 -47
- package/dist/routes/auth/hooks/findHookUser.js +0 -27
- package/dist/routes/auth/modelNames.js +0 -29
- package/dist/routes/auth/organizations/buildOrganizationPlugin.js +0 -136
- package/dist/routes/auth/organizations/createActiveOrgPolicyHook.js +0 -211
- package/dist/routes/auth/organizations/createAfterAcceptInvitationHook.js +0 -75
- package/dist/routes/auth/organizations/createAutoJoinHook.js +0 -63
- package/dist/routes/auth/organizations/ensureOrganization.js +0 -95
- package/dist/routes/auth/organizations/findPendingInvitation.js +0 -43
- package/dist/routes/auth/organizations/getOrganizationBinding.js +0 -65
- package/dist/routes/auth/organizations/resolvePinnedOrganization.js +0 -48
- package/dist/routes/auth/organizations/syncUserAdminRole.js +0 -102
- package/dist/routes/auth/resolveCookiePrefix.js +0 -30
- package/dist/routes/auth/strategies/createAuthStrategies.js +0 -77
- package/dist/routes/endpoints/handleAgentCall.js +0 -83
- package/dist/routes/endpoints/handleAuthStep.js +0 -124
- package/dist/routes/endpoints/handleRenderNotification.js +0 -189
- package/dist/routes/endpoints/runDetachedEndpoint.js +0 -85
- package/dist/routes/endpoints/runScheduledEndpoint.js +0 -102
- package/dist/routes/endpoints/runWebhookEndpoint.js +0 -118
- package/dist/routes/endpoints/runWebhookVerify.js +0 -94
- package/dist/routes/endpoints/scheduleBackground.js +0 -48
- package/dist/routes/notifications/derivePreview.js +0 -30
- package/dist/routes/notifications/getNotificationConfig.js +0 -32
- package/dist/routes/notifications/resolveNotificationLinks.js +0 -72
- package/dist/routes/page/dynamic/resolveDynamicContent.js +0 -172
- package/dist/routes/page/dynamic/unescapeOperators.js +0 -36
- package/dist/routes/page/dynamic/validateFragment.js +0 -104
- package/dist/routes/request/resolveTenant.js +0 -57
- package/dist/routes/websocket/createChannelRegistry.js +0 -278
- package/dist/routes/websocket/createWebSocketConnection.js +0 -131
- package/dist/routes/websocket/getWebsocketResolver.js +0 -33
- package/dist/routes/websocket/prepareChannel.js +0 -84
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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({ 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;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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 { ConfigError } from '@lowdefy/errors';
|
|
16
|
+
import { type } from '@lowdefy/helpers';
|
|
17
|
+
function validateSessionRoles({ session }) {
|
|
18
|
+
const roles = session?.user?.roles;
|
|
19
|
+
if (type.isNone(roles)) return;
|
|
20
|
+
if (!Array.isArray(roles)) {
|
|
21
|
+
throw new ConfigError('session.user.roles must be an array of strings. Check auth.userFields configuration and custom session callback plugins.', {
|
|
22
|
+
received: roles
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
for (const role of roles){
|
|
26
|
+
if (!type.isString(role)) {
|
|
27
|
+
throw new ConfigError('session.user.roles must be an array of strings. Check auth.userFields configuration and custom session callback plugins.', {
|
|
28
|
+
received: roles
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default validateSessionRoles;
|
|
@@ -12,19 +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
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const err = new ConfigError(`Websocket "${websocketId}" does not exist.`);
|
|
20
|
-
logger.debug({
|
|
21
|
-
params: {
|
|
22
|
-
websocketId
|
|
23
|
-
},
|
|
24
|
-
err
|
|
25
|
-
}, err.message);
|
|
26
|
-
throw err;
|
|
15
|
+
*/ function createAdapter({ authConfig, plugins }) {
|
|
16
|
+
const adapterConfig = authConfig.adapter;
|
|
17
|
+
if (!adapterConfig) {
|
|
18
|
+
return undefined;
|
|
27
19
|
}
|
|
28
|
-
return
|
|
20
|
+
return plugins.adapters[adapterConfig.type]({
|
|
21
|
+
properties: adapterConfig.properties
|
|
22
|
+
});
|
|
29
23
|
}
|
|
30
|
-
export default
|
|
24
|
+
export default createAdapter;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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
|
+
*/ const authWarnings = {
|
|
16
|
+
NEXTAUTH_URL: 'NEXTAUTH_URL - Environment variable NEXTAUTH_URL is missing. Set it in your .env file. On Vercel, VERCEL_URL is used automatically.',
|
|
17
|
+
NO_SECRET: 'NO_SECRET - No `secret` configured. In development a temporary secret is generated, but production requires an explicit secret.',
|
|
18
|
+
DEBUG_ENABLED: 'DEBUG_ENABLED - NextAuth debug mode is enabled. This is meant for development only — remove it before deploying to production.',
|
|
19
|
+
EXPERIMENTAL_API: 'EXPERIMENTAL_API - An experimental NextAuth API is in use. It may change or be removed in a future version.'
|
|
20
|
+
};
|
|
21
|
+
function createLogger({ logger }) {
|
|
22
|
+
return {
|
|
23
|
+
error: (code, metadata)=>{
|
|
24
|
+
const error = metadata instanceof Error ? metadata : metadata?.error;
|
|
25
|
+
if (error) {
|
|
26
|
+
error.code = code;
|
|
27
|
+
}
|
|
28
|
+
logger.error(error);
|
|
29
|
+
},
|
|
30
|
+
warn: (code)=>{
|
|
31
|
+
logger.warn(authWarnings[code] ?? code);
|
|
32
|
+
},
|
|
33
|
+
debug: (code, metadata)=>{
|
|
34
|
+
logger.debug(metadata, code);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export default createLogger;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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({ 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;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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({ authConfig, logger, plugins }) {
|
|
17
|
+
const createUserPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'createUser'
|
|
21
|
+
});
|
|
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
|
+
});
|
|
32
|
+
for (const plugin of createUserPlugins){
|
|
33
|
+
await plugin.fn({
|
|
34
|
+
properties: plugin.properties ?? {},
|
|
35
|
+
user
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return createUserEvent;
|
|
40
|
+
}
|
|
41
|
+
export default createCreateUserEvent;
|
package/dist/routes/auth/{organizations/getHookRequestHeaders.js → events/createEventPlugins.js}
RENAMED
|
@@ -12,13 +12,10 @@
|
|
|
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
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// from there.
|
|
21
|
-
function getHookRequestHeaders(ctx) {
|
|
22
|
-
return ctx?.headers ?? ctx?.request?.headers ?? ctx?.context?.headers;
|
|
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);
|
|
23
20
|
}
|
|
24
|
-
export default
|
|
21
|
+
export default createEventPlugins;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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({ 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({
|
|
50
|
+
authConfig,
|
|
51
|
+
plugins
|
|
52
|
+
});
|
|
53
|
+
if (session) events.session = session;
|
|
54
|
+
return events;
|
|
55
|
+
}
|
|
56
|
+
export default createEvents;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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({ authConfig, logger, plugins }) {
|
|
17
|
+
const linkAccountPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'linkAccount'
|
|
21
|
+
});
|
|
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
|
+
});
|
|
32
|
+
for (const plugin of linkAccountPlugins){
|
|
33
|
+
await plugin.fn({
|
|
34
|
+
properties: plugin.properties ?? {},
|
|
35
|
+
account,
|
|
36
|
+
profile,
|
|
37
|
+
user
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return linkAccountEvent;
|
|
42
|
+
}
|
|
43
|
+
export default createLinkAccountEvent;
|
|
@@ -12,20 +12,23 @@
|
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// resolves no session.
|
|
20
|
-
function getAuthStrategies({ appMeta, authJson, logger, plugins, secrets }) {
|
|
21
|
-
if (strategies) return strategies;
|
|
22
|
-
strategies = createAuthStrategies({
|
|
23
|
-
appMeta,
|
|
24
|
-
authJson,
|
|
25
|
-
logger,
|
|
15
|
+
*/ import createEventPlugins from './createEventPlugins.js';
|
|
16
|
+
function createSessionEvent({ authConfig, plugins }) {
|
|
17
|
+
const sessionPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
26
19
|
plugins,
|
|
27
|
-
|
|
20
|
+
type: 'session'
|
|
28
21
|
});
|
|
29
|
-
return
|
|
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;
|
|
30
33
|
}
|
|
31
|
-
export default
|
|
34
|
+
export default createSessionEvent;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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({ authConfig, logger, plugins }) {
|
|
17
|
+
const signInPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'signIn'
|
|
21
|
+
});
|
|
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
|
+
});
|
|
34
|
+
for (const plugin of signInPlugins){
|
|
35
|
+
await plugin.fn({
|
|
36
|
+
properties: plugin.properties ?? {},
|
|
37
|
+
account,
|
|
38
|
+
isNewUser,
|
|
39
|
+
profile,
|
|
40
|
+
user
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return signInEvent;
|
|
45
|
+
}
|
|
46
|
+
export default createSignInEvent;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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({ authConfig, logger, plugins }) {
|
|
17
|
+
const signOutPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'signOut'
|
|
21
|
+
});
|
|
22
|
+
async function signOutEvent({ session, token }) {
|
|
23
|
+
const user = session?.user ?? token;
|
|
24
|
+
logger.info({
|
|
25
|
+
event: 'auth_sign_out',
|
|
26
|
+
user: {
|
|
27
|
+
id: user.id,
|
|
28
|
+
roles: user.roles,
|
|
29
|
+
sub: user.sub,
|
|
30
|
+
session_id: user.session_id
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
for (const plugin of signOutPlugins){
|
|
34
|
+
await plugin.fn({
|
|
35
|
+
properties: plugin.properties ?? {},
|
|
36
|
+
session,
|
|
37
|
+
token
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return signOutEvent;
|
|
42
|
+
}
|
|
43
|
+
export default createSignOutEvent;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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({ authConfig, logger, plugins }) {
|
|
17
|
+
const updateUserPlugins = createEventPlugins({
|
|
18
|
+
authConfig,
|
|
19
|
+
plugins,
|
|
20
|
+
type: 'updateUser'
|
|
21
|
+
});
|
|
22
|
+
async function updateUserEvent({ user }) {
|
|
23
|
+
logger.info({
|
|
24
|
+
event: 'auth_update_user',
|
|
25
|
+
user: {
|
|
26
|
+
id: user.id,
|
|
27
|
+
roles: user.roles,
|
|
28
|
+
sub: user.sub,
|
|
29
|
+
session_id: user.session_id
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
for (const plugin of updateUserPlugins){
|
|
33
|
+
await plugin.fn({
|
|
34
|
+
properties: plugin.properties ?? {},
|
|
35
|
+
user
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return updateUserEvent;
|
|
40
|
+
}
|
|
41
|
+
export default createUpdateUserEvent;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 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 { ServerParser } from '@lowdefy/operators';
|
|
16
|
+
import { _app, _secret } from '@lowdefy/operators-js/operators/server';
|
|
17
|
+
import createAdapter from './createAdapter.js';
|
|
18
|
+
import createCallbacks from './callbacks/createCallbacks.js';
|
|
19
|
+
import createEvents from './events/createEvents.js';
|
|
20
|
+
import createLogger from './createLogger.js';
|
|
21
|
+
import createProviders from './createProviders.js';
|
|
22
|
+
const nextAuthConfig = {};
|
|
23
|
+
let initialized = false;
|
|
24
|
+
function getNextAuthConfig({ appMeta, authJson, logger, plugins, secrets }) {
|
|
25
|
+
if (initialized) return nextAuthConfig;
|
|
26
|
+
const operatorsParser = new ServerParser({
|
|
27
|
+
lowdefyApp: appMeta,
|
|
28
|
+
operators: {
|
|
29
|
+
_app,
|
|
30
|
+
_secret
|
|
31
|
+
},
|
|
32
|
+
secrets,
|
|
33
|
+
user: {}
|
|
34
|
+
});
|
|
35
|
+
const { output: authConfig, errors: operatorErrors } = operatorsParser.parse({
|
|
36
|
+
input: authJson,
|
|
37
|
+
location: 'auth',
|
|
38
|
+
payload: {}
|
|
39
|
+
});
|
|
40
|
+
if (operatorErrors.length > 0) {
|
|
41
|
+
throw operatorErrors[0];
|
|
42
|
+
}
|
|
43
|
+
nextAuthConfig.adapter = createAdapter({
|
|
44
|
+
authConfig,
|
|
45
|
+
logger,
|
|
46
|
+
plugins
|
|
47
|
+
});
|
|
48
|
+
nextAuthConfig.callbacks = createCallbacks({
|
|
49
|
+
authConfig,
|
|
50
|
+
logger,
|
|
51
|
+
plugins
|
|
52
|
+
});
|
|
53
|
+
nextAuthConfig.events = createEvents({
|
|
54
|
+
authConfig,
|
|
55
|
+
logger,
|
|
56
|
+
plugins
|
|
57
|
+
});
|
|
58
|
+
nextAuthConfig.logger = createLogger({
|
|
59
|
+
logger
|
|
60
|
+
});
|
|
61
|
+
nextAuthConfig.providers = createProviders({
|
|
62
|
+
authConfig,
|
|
63
|
+
logger,
|
|
64
|
+
plugins
|
|
65
|
+
});
|
|
66
|
+
nextAuthConfig.debug = authConfig.debug ?? logger?.isLevelEnabled('debug') === true;
|
|
67
|
+
nextAuthConfig.pages = authConfig.authPages;
|
|
68
|
+
nextAuthConfig.session = authConfig.session;
|
|
69
|
+
nextAuthConfig.theme = authConfig.theme;
|
|
70
|
+
nextAuthConfig.cookies = authConfig?.advanced?.cookies;
|
|
71
|
+
nextAuthConfig.originalRedirectCallback = nextAuthConfig.callbacks.redirect;
|
|
72
|
+
initialized = true;
|
|
73
|
+
return nextAuthConfig;
|
|
74
|
+
}
|
|
75
|
+
export default getNextAuthConfig;
|
|
@@ -12,20 +12,14 @@
|
|
|
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 {
|
|
16
|
-
|
|
17
|
-
function authorizeApiEndpoint({ authorize, logger, user }, { endpointConfig }) {
|
|
15
|
+
*/ import { ConfigError } from '@lowdefy/errors';
|
|
16
|
+
function authorizeApiEndpoint({ authorize, logger }, { endpointConfig }) {
|
|
18
17
|
if (!authorize(endpointConfig)) {
|
|
19
18
|
logger.debug({
|
|
20
19
|
event: 'debug_api_authorize',
|
|
21
20
|
authorized: false,
|
|
22
21
|
auth_config: endpointConfig.auth
|
|
23
22
|
});
|
|
24
|
-
// Unauthenticated on a protected endpoint - 401 tells the caller to fix
|
|
25
|
-
// its credentials. Wrong roles stay opaque below.
|
|
26
|
-
if (type.isNone(user)) {
|
|
27
|
-
throw new AuthenticationError(`Authentication required for API endpoint "${endpointConfig.endpointId}".`);
|
|
28
|
-
}
|
|
29
23
|
throw new ConfigError(`API Endpoint "${endpointConfig.endpointId}" does not exist.`);
|
|
30
24
|
}
|
|
31
25
|
logger.debug({
|
|
@@ -18,7 +18,6 @@ import authorizeApiEndpoint from './authorizeApiEndpoint.js';
|
|
|
18
18
|
import createEvaluateOperators from '../../context/createEvaluateOperators.js';
|
|
19
19
|
import getEndpointConfig from './getEndpointConfig.js';
|
|
20
20
|
import runRoutine from './runRoutine.js';
|
|
21
|
-
import scheduleBackground from './scheduleBackground.js';
|
|
22
21
|
async function callEndpoint(context, { blockId, endpointId, pageId, payload }) {
|
|
23
22
|
const { logger } = context;
|
|
24
23
|
context.blockId = blockId;
|
|
@@ -57,25 +56,6 @@ async function callEndpoint(context, { blockId, endpointId, pageId, payload }) {
|
|
|
57
56
|
state: {},
|
|
58
57
|
endpointDepth: 0
|
|
59
58
|
};
|
|
60
|
-
// async: true — acknowledge now, run the routine in the background.
|
|
61
|
-
// Auth was already checked above; the outcome lands in logs (scheduleBackground)
|
|
62
|
-
// and in whatever the routine itself records.
|
|
63
|
-
if (endpointConfig.async === true) {
|
|
64
|
-
scheduleBackground(context, {
|
|
65
|
-
event: 'background_endpoint',
|
|
66
|
-
endpointId
|
|
67
|
-
}, ()=>runRoutine(context, routineContext, {
|
|
68
|
-
routine: endpointConfig.routine
|
|
69
|
-
}));
|
|
70
|
-
return {
|
|
71
|
-
error: null,
|
|
72
|
-
response: serializer.serialize({
|
|
73
|
-
accepted: true
|
|
74
|
-
}),
|
|
75
|
-
status: 'accepted',
|
|
76
|
-
success: true
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
59
|
const { error, response, status } = await runRoutine(context, routineContext, {
|
|
80
60
|
routine: endpointConfig.routine
|
|
81
61
|
});
|
|
@@ -37,11 +37,9 @@ async function controlReject(context, routineContext, { control }) {
|
|
|
37
37
|
cause,
|
|
38
38
|
isReject: true
|
|
39
39
|
});
|
|
40
|
-
// Log under `err` — see controlThrow: only the `err` key runs the pino error
|
|
41
|
-
// serializer, so `error` would drop the message from the log line.
|
|
42
40
|
context.logger.warn({
|
|
43
41
|
event: 'warn_control_reject',
|
|
44
|
-
|
|
42
|
+
error
|
|
45
43
|
});
|
|
46
44
|
return {
|
|
47
45
|
status: 'reject',
|
|
@@ -36,12 +36,9 @@ async function controlThrow(context, routineContext, { control }) {
|
|
|
36
36
|
const error = new UserError(message, {
|
|
37
37
|
cause
|
|
38
38
|
});
|
|
39
|
-
// Log under `err` — the pino error serializer (createNodeLogger) is registered
|
|
40
|
-
// for the `err` key only; an Error passed as `error` is JSON-dumped without its
|
|
41
|
-
// non-enumerable `message`/`stack`, producing a log line with no message.
|
|
42
39
|
context.logger.error({
|
|
43
40
|
event: 'error_control_throw',
|
|
44
|
-
|
|
41
|
+
error
|
|
45
42
|
});
|
|
46
43
|
return {
|
|
47
44
|
status: 'error',
|