@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
|
@@ -14,11 +14,9 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import createAuthorize from './createAuthorize.js';
|
|
16
16
|
import createReadConfigFile from './createReadConfigFile.js';
|
|
17
|
-
import getOrganizationBinding from '../routes/auth/organizations/getOrganizationBinding.js';
|
|
18
17
|
import resolveLocale from './resolveLocale.js';
|
|
19
18
|
function createApiContext(context) {
|
|
20
|
-
|
|
21
|
-
// dev/e2e caller) before this runs - never assigned here.
|
|
19
|
+
context.user = context?.session?.user;
|
|
22
20
|
if (context.i18n?.defaultLocale) {
|
|
23
21
|
const active = resolveLocale({
|
|
24
22
|
i18n: context.i18n,
|
|
@@ -31,12 +29,6 @@ function createApiContext(context) {
|
|
|
31
29
|
} else {
|
|
32
30
|
context.i18n = undefined;
|
|
33
31
|
}
|
|
34
|
-
// The retained organizations state ({ policy, pinned }) - read by the
|
|
35
|
-
// _organization operator and the org-scoped admin steps; null when auth
|
|
36
|
-
// (or organizations) is not configured.
|
|
37
|
-
context.organization = getOrganizationBinding({
|
|
38
|
-
auth: context.auth ?? null
|
|
39
|
-
});
|
|
40
32
|
context.authorize = createAuthorize(context);
|
|
41
33
|
context.readConfigFile = createReadConfigFile(context);
|
|
42
34
|
}
|
|
@@ -12,29 +12,18 @@
|
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// caller object when authenticated, else null.
|
|
24
|
-
const authenticated = !type.isNone(user);
|
|
25
|
-
const roles = user?.roles ?? [];
|
|
26
|
-
if (!Array.isArray(roles) || roles.some((role)=>!type.isString(role))) {
|
|
27
|
-
throw new ConfigError('user.roles must be an array of strings.', {
|
|
15
|
+
*/ import { ConfigError } from '@lowdefy/errors';
|
|
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
|
+
if (!Array.isArray(roles)) {
|
|
22
|
+
throw new ConfigError('session.user.roles must be an array of strings.', {
|
|
28
23
|
received: roles
|
|
29
24
|
});
|
|
30
25
|
}
|
|
31
26
|
function authorize(config) {
|
|
32
|
-
// In a system context (context.system === true) there is no session and no
|
|
33
|
-
// caller, so `auth.public` / `auth.roles` - which ask "does this caller's
|
|
34
|
-
// session carry the required roles?" - is undefined, not denied. Endpoint
|
|
35
|
-
// role-authorization is skipped, not satisfied by a synthetic role:
|
|
36
|
-
// "system" is never a role, it is the absence of a principal (Decision 2).
|
|
37
|
-
if (system === true) return true;
|
|
38
27
|
const { auth } = config;
|
|
39
28
|
if (auth.public === true) return true;
|
|
40
29
|
if (auth.public === false) {
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { ServerParser } from '@lowdefy/operators';
|
|
16
16
|
function createEvaluateOperators(context) {
|
|
17
|
-
const { appMeta, i18n, jsMap, operators,
|
|
17
|
+
const { appMeta, i18n, jsMap, operators, secrets, user } = context;
|
|
18
18
|
const operatorsParser = new ServerParser({
|
|
19
19
|
i18n,
|
|
20
20
|
jsMap,
|
|
21
21
|
lowdefyApp: appMeta,
|
|
22
22
|
operators,
|
|
23
|
-
organization,
|
|
24
23
|
secrets,
|
|
25
24
|
user
|
|
26
25
|
});
|
package/dist/index.js
CHANGED
|
@@ -14,22 +14,12 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import callAgent from './routes/agent/callAgent.js';
|
|
16
16
|
import callEndpoint from './routes/endpoints/callEndpoint.js';
|
|
17
|
-
import getEndpointConfig from './routes/endpoints/getEndpointConfig.js';
|
|
18
17
|
import callRequest from './routes/request/callRequest.js';
|
|
19
18
|
import createApiContext from './context/createApiContext.js';
|
|
20
|
-
import
|
|
21
|
-
import createSystemContext from './context/createSystemContext.js';
|
|
22
|
-
import createWebSocketConnection from './routes/websocket/createWebSocketConnection.js';
|
|
23
|
-
import getAuthStrategies from './routes/auth/strategies/getAuthStrategies.js';
|
|
24
|
-
import getBetterAuth from './routes/auth/getBetterAuth.js';
|
|
19
|
+
import createSessionCallback from './routes/auth/callbacks/createSessionCallback.js';
|
|
25
20
|
import getHomeAndMenus from './routes/rootConfig/getHomeAndMenus.js';
|
|
21
|
+
import getNextAuthConfig from './routes/auth/getNextAuthConfig.js';
|
|
26
22
|
import getPageConfig from './routes/page/getPageConfig.js';
|
|
27
23
|
import getRootConfig from './routes/rootConfig/getRootConfig.js';
|
|
28
24
|
import logClientError from './routes/log/logClientError.js';
|
|
29
|
-
|
|
30
|
-
import resolveAuthentication from './context/resolveAuthentication.js';
|
|
31
|
-
import resolvePinnedOrganization from './routes/auth/organizations/resolvePinnedOrganization.js';
|
|
32
|
-
import runDetachedEndpoint from './routes/endpoints/runDetachedEndpoint.js';
|
|
33
|
-
import runWebhookEndpoint from './routes/endpoints/runWebhookEndpoint.js';
|
|
34
|
-
import runScheduledEndpoint from './routes/endpoints/runScheduledEndpoint.js';
|
|
35
|
-
export { callAgent, callEndpoint, getEndpointConfig, callRequest, createApiContext, createChannelRegistry, createSystemContext, createWebSocketConnection, getAuthStrategies, getBetterAuth, getHomeAndMenus, getPageConfig, getRootConfig, logClientError, normalizeInjectedCaller, resolveAuthentication, resolvePinnedOrganization, runDetachedEndpoint, runWebhookEndpoint, runScheduledEndpoint };
|
|
25
|
+
export { callAgent, callEndpoint, callRequest, createApiContext, createSessionCallback, getHomeAndMenus, getNextAuthConfig, getPageConfig, getRootConfig, logClientError };
|
|
@@ -12,8 +12,15 @@
|
|
|
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
|
-
import
|
|
15
|
+
*/ import { serializer, type } from '@lowdefy/helpers';
|
|
16
|
+
import createEvaluateOperators from '../../context/createEvaluateOperators.js';
|
|
17
|
+
import authorizeApiEndpoint from '../endpoints/authorizeApiEndpoint.js';
|
|
18
|
+
import getEndpointConfig from '../endpoints/getEndpointConfig.js';
|
|
19
|
+
import runRoutine from '../endpoints/runRoutine.js';
|
|
20
|
+
import getAgentConfig from './getAgentConfig.js';
|
|
21
|
+
import getAgentResolver from './getAgentResolver.js';
|
|
22
|
+
import getConnectionConfig from '../connections/getConnectionConfig.js';
|
|
23
|
+
import getConnection from '../connections/getConnection.js';
|
|
17
24
|
async function callAgent(context, { agentId, pageId, messages, conversationId, urlQuery, sharedState }) {
|
|
18
25
|
const { logger } = context;
|
|
19
26
|
context.pageId = pageId;
|
|
@@ -23,6 +30,9 @@ async function callAgent(context, { agentId, pageId, messages, conversationId, u
|
|
|
23
30
|
agentId,
|
|
24
31
|
pageId
|
|
25
32
|
});
|
|
33
|
+
const agentConfig = await getAgentConfig(context, {
|
|
34
|
+
agentId
|
|
35
|
+
});
|
|
26
36
|
const agentContext = {
|
|
27
37
|
conversationId: conversationId ?? undefined,
|
|
28
38
|
pageId,
|
|
@@ -30,12 +40,175 @@ async function callAgent(context, { agentId, pageId, messages, conversationId, u
|
|
|
30
40
|
urlQuery: urlQuery ?? {},
|
|
31
41
|
userId: context.user?.sub ?? context.user?.id ?? null
|
|
32
42
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
// Evaluate operators in agent properties (e.g. _user, _secret, _payload)
|
|
44
|
+
agentConfig.properties = context.evaluateOperators({
|
|
45
|
+
input: agentConfig.properties ?? {},
|
|
46
|
+
location: agentConfig.agentId,
|
|
47
|
+
payload: agentContext,
|
|
48
|
+
state: {},
|
|
49
|
+
steps: {}
|
|
50
|
+
});
|
|
51
|
+
// Load connection config from build artifacts using agent's connectionId
|
|
52
|
+
const connectionConfig = await getConnectionConfig(context, {
|
|
53
|
+
connectionId: agentConfig.connectionId,
|
|
54
|
+
configKey: agentConfig['~k']
|
|
55
|
+
});
|
|
56
|
+
// Get connection plugin from registry
|
|
57
|
+
const connection = getConnection(context, {
|
|
58
|
+
connectionConfig
|
|
59
|
+
});
|
|
60
|
+
// Evaluate operators in connection properties
|
|
61
|
+
const connectionProperties = context.evaluateOperators({
|
|
62
|
+
input: connectionConfig.properties || {},
|
|
63
|
+
location: connectionConfig.connectionId,
|
|
64
|
+
payload: {},
|
|
65
|
+
state: {},
|
|
66
|
+
steps: {}
|
|
67
|
+
});
|
|
68
|
+
// Create connection instance (e.g., Anthropic provider)
|
|
69
|
+
const connectionInstance = connection.create({
|
|
70
|
+
connection: connectionProperties
|
|
38
71
|
});
|
|
72
|
+
// Get agent type from plugin registry
|
|
73
|
+
const agentType = getAgentResolver(context, {
|
|
74
|
+
agentConfig
|
|
75
|
+
});
|
|
76
|
+
// Build resolver context with callEndpoint that allows InternalApi endpoints
|
|
77
|
+
const resolverContext = {
|
|
78
|
+
agentContext,
|
|
79
|
+
i18n: context.i18n,
|
|
80
|
+
evaluateOperators: (input)=>context.evaluateOperators({
|
|
81
|
+
input,
|
|
82
|
+
location: agentConfig.agentId,
|
|
83
|
+
payload: agentContext,
|
|
84
|
+
state: {},
|
|
85
|
+
steps: {}
|
|
86
|
+
}),
|
|
87
|
+
callEndpoint: async (endpointId, { payload, abortSignal })=>{
|
|
88
|
+
const endpointConfig = await getEndpointConfig(context, {
|
|
89
|
+
endpointId
|
|
90
|
+
});
|
|
91
|
+
authorizeApiEndpoint(context, {
|
|
92
|
+
endpointConfig
|
|
93
|
+
});
|
|
94
|
+
const routineContext = {
|
|
95
|
+
steps: {},
|
|
96
|
+
payload: payload ?? {},
|
|
97
|
+
arrayIndices: [],
|
|
98
|
+
items: {},
|
|
99
|
+
state: {},
|
|
100
|
+
endpointDepth: 0
|
|
101
|
+
};
|
|
102
|
+
const { error, response, status } = await runRoutine(context, routineContext, {
|
|
103
|
+
routine: endpointConfig.routine
|
|
104
|
+
});
|
|
105
|
+
const success = ![
|
|
106
|
+
'error',
|
|
107
|
+
'reject'
|
|
108
|
+
].includes(status);
|
|
109
|
+
return {
|
|
110
|
+
error: serializer.serialize(error),
|
|
111
|
+
response: serializer.serialize(response),
|
|
112
|
+
status: success ? 'success' : status,
|
|
113
|
+
success
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
getEndpointConfig: async ({ endpointId })=>{
|
|
117
|
+
return getEndpointConfig(context, {
|
|
118
|
+
endpointId
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
getAgentConfig: async ({ agentId })=>{
|
|
122
|
+
return getAgentConfig(context, {
|
|
123
|
+
agentId
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
getConnectionForAgent: async ({ agentConfig: subAgentConfig })=>{
|
|
127
|
+
const subConnectionConfig = await getConnectionConfig(context, {
|
|
128
|
+
connectionId: subAgentConfig.connectionId,
|
|
129
|
+
configKey: subAgentConfig['~k']
|
|
130
|
+
});
|
|
131
|
+
const subConnection = getConnection(context, {
|
|
132
|
+
connectionConfig: subConnectionConfig
|
|
133
|
+
});
|
|
134
|
+
const subConnectionProperties = context.evaluateOperators({
|
|
135
|
+
input: subConnectionConfig.properties || {},
|
|
136
|
+
location: subConnectionConfig.connectionId,
|
|
137
|
+
payload: {},
|
|
138
|
+
state: {},
|
|
139
|
+
steps: {}
|
|
140
|
+
});
|
|
141
|
+
return subConnection.create({
|
|
142
|
+
connection: subConnectionProperties
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
resolveMcpSources: async ({ agentConfig: subAgentConfig })=>{
|
|
146
|
+
const resolvedMcp = [];
|
|
147
|
+
for (const mcpSource of subAgentConfig.mcp ?? []){
|
|
148
|
+
if (!type.isNone(mcpSource.connectionId)) {
|
|
149
|
+
const mcpConnConfig = await getConnectionConfig(context, {
|
|
150
|
+
connectionId: mcpSource.connectionId,
|
|
151
|
+
configKey: subAgentConfig['~k']
|
|
152
|
+
});
|
|
153
|
+
const mcpConnection = getConnection(context, {
|
|
154
|
+
connectionConfig: mcpConnConfig
|
|
155
|
+
});
|
|
156
|
+
const mcpConnProps = context.evaluateOperators({
|
|
157
|
+
input: mcpConnConfig.properties || {},
|
|
158
|
+
location: mcpConnConfig.connectionId,
|
|
159
|
+
payload: {},
|
|
160
|
+
state: {},
|
|
161
|
+
steps: {}
|
|
162
|
+
});
|
|
163
|
+
const mcpConfig = mcpConnection.create({
|
|
164
|
+
connection: mcpConnProps
|
|
165
|
+
});
|
|
166
|
+
const { connectionId: _, ...overrides } = mcpSource;
|
|
167
|
+
resolvedMcp.push({
|
|
168
|
+
...mcpConfig,
|
|
169
|
+
...overrides
|
|
170
|
+
});
|
|
171
|
+
} else {
|
|
172
|
+
resolvedMcp.push(mcpSource);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return resolvedMcp;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
// Resolve MCP connection references to inline config.
|
|
179
|
+
// Agent-level overrides (like confirm) may still contain operators —
|
|
180
|
+
// handleAgentChat evaluates those via its existing evaluateOperators call.
|
|
181
|
+
const resolvedMcp = [];
|
|
182
|
+
for (const mcpSource of agentConfig.mcp ?? []){
|
|
183
|
+
if (!type.isNone(mcpSource.connectionId)) {
|
|
184
|
+
const mcpConnConfig = await getConnectionConfig(context, {
|
|
185
|
+
connectionId: mcpSource.connectionId,
|
|
186
|
+
configKey: agentConfig['~k']
|
|
187
|
+
});
|
|
188
|
+
const mcpConnection = getConnection(context, {
|
|
189
|
+
connectionConfig: mcpConnConfig
|
|
190
|
+
});
|
|
191
|
+
const mcpConnProps = context.evaluateOperators({
|
|
192
|
+
input: mcpConnConfig.properties || {},
|
|
193
|
+
location: mcpConnConfig.connectionId,
|
|
194
|
+
payload: {},
|
|
195
|
+
state: {},
|
|
196
|
+
steps: {}
|
|
197
|
+
});
|
|
198
|
+
const mcpConfig = mcpConnection.create({
|
|
199
|
+
connection: mcpConnProps
|
|
200
|
+
});
|
|
201
|
+
// Merge: connection properties as base, agent-level overrides on top
|
|
202
|
+
const { connectionId: _, ...overrides } = mcpSource;
|
|
203
|
+
resolvedMcp.push({
|
|
204
|
+
...mcpConfig,
|
|
205
|
+
...overrides
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
resolvedMcp.push(mcpSource);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
agentConfig.mcp = resolvedMcp;
|
|
39
212
|
// Call the agent resolver
|
|
40
213
|
const { response } = await agentType.resolver({
|
|
41
214
|
connection: connectionInstance,
|
package/dist/routes/{websocket/authorizeWebsocket.js → auth/callbacks/addUserFieldsToSession.js}
RENAMED
|
@@ -12,16 +12,17 @@
|
|
|
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
|
-
function
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
*/ import { get, set } from '@lowdefy/helpers';
|
|
16
|
+
function addUserFieldsToSession({ session, token, authConfig, user }) {
|
|
17
|
+
if (token) {
|
|
18
|
+
Object.keys(authConfig.userFields).forEach((fieldName)=>{
|
|
19
|
+
set(session.user, fieldName, get(token, fieldName));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (user) {
|
|
23
|
+
Object.keys(authConfig.userFields).forEach((fieldName)=>{
|
|
24
|
+
set(session.user, fieldName, get(user, fieldName));
|
|
22
25
|
});
|
|
23
|
-
// Same message as a missing websocket so channel existence does not leak.
|
|
24
|
-
throw new ConfigError(`Websocket "${websocketConfig.websocketId}" does not exist.`);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
export default
|
|
28
|
+
export default addUserFieldsToSession;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { get, set } from '@lowdefy/helpers';
|
|
16
|
+
function addUserFieldsToToken({ account, authConfig, logger, profile, token, user }) {
|
|
17
|
+
const objects = {
|
|
18
|
+
account,
|
|
19
|
+
profile,
|
|
20
|
+
user
|
|
21
|
+
};
|
|
22
|
+
logger.debug('Adding userFields to user. Available provider data is:');
|
|
23
|
+
logger.debug(objects);
|
|
24
|
+
Object.entries(authConfig.userFields).forEach(([lowdefyFieldName, providerFieldName])=>{
|
|
25
|
+
const value = get(objects, providerFieldName);
|
|
26
|
+
logger.debug(`Adding provider field "${providerFieldName}" with value ${JSON.stringify(value)} as "${lowdefyFieldName}"`);
|
|
27
|
+
set(token, lowdefyFieldName, value);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export default addUserFieldsToToken;
|
|
@@ -12,15 +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
|
-
return async function afterSlot(data, ctx) {
|
|
21
|
-
for (const hook of hooks){
|
|
22
|
-
await hook(data, ctx);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
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);
|
|
25
20
|
}
|
|
26
|
-
export default
|
|
21
|
+
export default createCallbackPlugins;
|
|
@@ -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 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({ authConfig, logger, plugins }) {
|
|
20
|
+
const callbacks = {
|
|
21
|
+
session: createSessionCallback({
|
|
22
|
+
authConfig,
|
|
23
|
+
logger,
|
|
24
|
+
plugins
|
|
25
|
+
})
|
|
26
|
+
};
|
|
27
|
+
const jwt = createJWTCallback({
|
|
28
|
+
authConfig,
|
|
29
|
+
logger,
|
|
30
|
+
plugins
|
|
31
|
+
});
|
|
32
|
+
if (jwt) callbacks.jwt = jwt;
|
|
33
|
+
const redirect = createRedirectCallback({
|
|
34
|
+
authConfig,
|
|
35
|
+
logger,
|
|
36
|
+
plugins
|
|
37
|
+
});
|
|
38
|
+
if (redirect) callbacks.redirect = redirect;
|
|
39
|
+
const signIn = createSignInCallback({
|
|
40
|
+
authConfig,
|
|
41
|
+
plugins
|
|
42
|
+
});
|
|
43
|
+
if (signIn) callbacks.signIn = signIn;
|
|
44
|
+
return callbacks;
|
|
45
|
+
}
|
|
46
|
+
export default createCallbacks;
|
|
@@ -0,0 +1,77 @@
|
|
|
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 addUserFieldsToToken from './addUserFieldsToToken.js';
|
|
16
|
+
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
17
|
+
function createJWTCallback({ authConfig, logger, 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 { 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
|
+
token = {
|
|
27
|
+
id,
|
|
28
|
+
sub,
|
|
29
|
+
name,
|
|
30
|
+
given_name,
|
|
31
|
+
family_name,
|
|
32
|
+
middle_name,
|
|
33
|
+
nickname,
|
|
34
|
+
preferred_username,
|
|
35
|
+
profile: profile_claim,
|
|
36
|
+
picture,
|
|
37
|
+
website,
|
|
38
|
+
email,
|
|
39
|
+
email_verified,
|
|
40
|
+
gender,
|
|
41
|
+
birthdate,
|
|
42
|
+
zoneinfo,
|
|
43
|
+
locale,
|
|
44
|
+
phone_number,
|
|
45
|
+
phone_number_verified,
|
|
46
|
+
address,
|
|
47
|
+
updated_at,
|
|
48
|
+
...token
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (profile || user) {
|
|
52
|
+
if (authConfig.userFields) {
|
|
53
|
+
addUserFieldsToToken({
|
|
54
|
+
authConfig,
|
|
55
|
+
account,
|
|
56
|
+
logger,
|
|
57
|
+
profile,
|
|
58
|
+
token,
|
|
59
|
+
user
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const plugin of jwtCallbackPlugins){
|
|
64
|
+
token = await plugin.fn({
|
|
65
|
+
properties: plugin.properties ?? {},
|
|
66
|
+
account,
|
|
67
|
+
isNewUser,
|
|
68
|
+
profile,
|
|
69
|
+
token,
|
|
70
|
+
user
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return token;
|
|
74
|
+
}
|
|
75
|
+
return jwtCallback;
|
|
76
|
+
}
|
|
77
|
+
export default createJWTCallback;
|
|
@@ -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 createCallbackPlugins from './createCallbackPlugins.js';
|
|
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 }) {
|
|
22
|
+
const redirectCallbackPlugins = createCallbackPlugins({
|
|
23
|
+
authConfig,
|
|
24
|
+
plugins,
|
|
25
|
+
type: 'redirect'
|
|
26
|
+
});
|
|
27
|
+
if (redirectCallbackPlugins.length === 0) return defaultRedirect;
|
|
28
|
+
if (redirectCallbackPlugins.length !== 1) {
|
|
29
|
+
throw new Error('More than one auth redirect callbacks are configured. Only one is allowed.');
|
|
30
|
+
}
|
|
31
|
+
const [plugin] = redirectCallbackPlugins;
|
|
32
|
+
function redirectCallback({ url, baseUrl }) {
|
|
33
|
+
return plugin.fn({
|
|
34
|
+
properties: plugin.properties ?? {},
|
|
35
|
+
baseUrl,
|
|
36
|
+
url
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return redirectCallback;
|
|
40
|
+
}
|
|
41
|
+
export default createRedirectCallback;
|
|
@@ -0,0 +1,81 @@
|
|
|
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 crypto from 'crypto';
|
|
16
|
+
import addUserFieldsToSession from './addUserFieldsToSession.js';
|
|
17
|
+
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
18
|
+
import validateSessionRoles from './validateSessionRoles.js';
|
|
19
|
+
function createSessionCallback({ authConfig, plugins }) {
|
|
20
|
+
const sessionCallbackPlugins = createCallbackPlugins({
|
|
21
|
+
authConfig,
|
|
22
|
+
plugins,
|
|
23
|
+
type: 'session'
|
|
24
|
+
});
|
|
25
|
+
async function sessionCallback({ session, token, user }) {
|
|
26
|
+
const identifier = user ? user.id ?? user.sub ?? user.email : token.id ?? token.sub ?? token.email;
|
|
27
|
+
if (token) {
|
|
28
|
+
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;
|
|
29
|
+
session.user = {
|
|
30
|
+
id,
|
|
31
|
+
sub,
|
|
32
|
+
name,
|
|
33
|
+
given_name,
|
|
34
|
+
family_name,
|
|
35
|
+
middle_name,
|
|
36
|
+
nickname,
|
|
37
|
+
preferred_username,
|
|
38
|
+
profile,
|
|
39
|
+
picture,
|
|
40
|
+
website,
|
|
41
|
+
email,
|
|
42
|
+
email_verified,
|
|
43
|
+
gender,
|
|
44
|
+
birthdate,
|
|
45
|
+
zoneinfo,
|
|
46
|
+
locale,
|
|
47
|
+
phone_number,
|
|
48
|
+
phone_number_verified,
|
|
49
|
+
address,
|
|
50
|
+
updated_at,
|
|
51
|
+
...session.user
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (authConfig.userFields) {
|
|
55
|
+
addUserFieldsToSession({
|
|
56
|
+
authConfig,
|
|
57
|
+
session,
|
|
58
|
+
token,
|
|
59
|
+
user
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
for (const plugin of sessionCallbackPlugins){
|
|
63
|
+
// eslint-disable-next-line no-param-reassign
|
|
64
|
+
session = await plugin.fn({
|
|
65
|
+
properties: plugin.properties ?? {},
|
|
66
|
+
session,
|
|
67
|
+
token,
|
|
68
|
+
user
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
validateSessionRoles({
|
|
72
|
+
session
|
|
73
|
+
});
|
|
74
|
+
// TODO: Should this be session.hashed_id or session.user.hashed_id
|
|
75
|
+
// Only session.user will be available using the _user operator
|
|
76
|
+
session.hashed_id = crypto.createHash('sha256').update(identifier ?? '').digest('base64');
|
|
77
|
+
return session;
|
|
78
|
+
}
|
|
79
|
+
return sessionCallback;
|
|
80
|
+
}
|
|
81
|
+
export default createSessionCallback;
|