@lowdefy/api 0.0.0-experimental-20260223144039 → 0.0.0-experimental-20260304101313

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.
@@ -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
- */ import { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
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
@@ -27,8 +27,7 @@ function createAuthorize({ session }) {
27
27
  }
28
28
  return authenticated;
29
29
  }
30
- throw new ConfigError({
31
- message: 'auth.public must be true or false.',
30
+ throw new ConfigError('auth.public must be true or false.', {
32
31
  received: auth.public,
33
32
  configKey: config['~k']
34
33
  });
@@ -12,23 +12,27 @@
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 createLogger({ logger }) {
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 }) {
16
22
  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
- })
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
+ }
32
36
  };
33
37
  }
34
38
  export default createLogger;
@@ -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
- */ import { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  function authorizeApiEndpoint({ authorize, logger }, { endpointConfig }) {
17
17
  if (!authorize(endpointConfig)) {
18
18
  logger.debug({
@@ -20,9 +20,7 @@ function authorizeApiEndpoint({ authorize, logger }, { endpointConfig }) {
20
20
  authorized: false,
21
21
  auth_config: endpointConfig.auth
22
22
  });
23
- throw new ConfigError({
24
- message: `API Endpoint "${endpointConfig.endpointId}" does not exist.`
25
- });
23
+ throw new ConfigError(`API Endpoint "${endpointConfig.endpointId}" does not exist.`);
26
24
  }
27
25
  logger.debug({
28
26
  event: 'debug_api_authorize',
@@ -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
- */ import { PluginError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  import runRoutine from '../runRoutine.js';
17
17
  async function controlFor(context, routineContext, { control }) {
18
18
  const { endpointId, logger, evaluateOperators } = context;
@@ -32,8 +32,7 @@ async function controlFor(context, routineContext, { control }) {
32
32
  itemName
33
33
  });
34
34
  if (!Array.isArray(array)) {
35
- throw new PluginError({
36
- message: `Invalid :for in endpoint "${endpointId}" - :in must evaluate to an array.`,
35
+ throw new ConfigError(`Invalid :for in endpoint "${endpointId}" - :in must evaluate to an array.`, {
37
36
  received: array,
38
37
  configKey: control['~k']
39
38
  });
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
- import { PluginError } from '@lowdefy/errors/server';
16
+ import { ConfigError } from '@lowdefy/errors';
17
17
  async function controlLog(context, routineContext, { control }) {
18
18
  const { endpointId, logger, evaluateOperators } = context;
19
19
  const { items } = routineContext;
@@ -32,8 +32,7 @@ async function controlLog(context, routineContext, { control }) {
32
32
  location
33
33
  }) ?? 'info';
34
34
  if (!type.isString(logLevel)) {
35
- throw new PluginError({
36
- message: `Invalid :log in endpoint "${endpointId}" - :level must be a string.`,
35
+ throw new ConfigError(`Invalid :log in endpoint "${endpointId}" - :level must be a string.`, {
37
36
  received: logLevel,
38
37
  configKey: control['~k']
39
38
  });
@@ -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
- */ import { PluginError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  import runRoutine from '../runRoutine.js';
17
17
  async function controlParallelFor(context, routineContext, { control }) {
18
18
  const { endpointId, logger, evaluateOperators } = context;
@@ -32,8 +32,7 @@ async function controlParallelFor(context, routineContext, { control }) {
32
32
  itemName
33
33
  });
34
34
  if (!Array.isArray(array)) {
35
- throw new PluginError({
36
- message: `Invalid :parallel_for in endpoint "${endpointId}" - :in must evaluate to an array.`,
35
+ throw new ConfigError(`Invalid :parallel_for in endpoint "${endpointId}" - :in must evaluate to an array.`, {
37
36
  received: array,
38
37
  configKey: control['~k']
39
38
  });
@@ -12,13 +12,11 @@
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 { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  async function getEndpointConfig({ logger, readConfigFile }, { endpointId }) {
17
17
  const endpoint = await readConfigFile(`api/${endpointId}.json`);
18
18
  if (!endpoint) {
19
- const err = new ConfigError({
20
- message: `API Endpoint "${endpointId}" does not exist.`
21
- });
19
+ const err = new ConfigError(`API Endpoint "${endpointId}" does not exist.`);
22
20
  logger.debug({
23
21
  params: {
24
22
  endpointId
@@ -50,7 +50,7 @@ async function runRoutine(context, routineContext, { routine }) {
50
50
  }
51
51
  });
52
52
  } catch (error) {
53
- context.logger.error(error);
53
+ await context.handleError(error);
54
54
  return {
55
55
  status: 'error',
56
56
  error
@@ -0,0 +1,31 @@
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
+ */ function formatValidationError({ ajvError, pluginLabel, typeName, fieldLabel }) {
16
+ const path = ajvError.instancePath ? ajvError.instancePath.substring(1).replace(/\//g, '.') : null;
17
+ const fieldName = path || ajvError.params?.missingProperty || 'unknown';
18
+ switch(ajvError.keyword){
19
+ case 'type':
20
+ return `${pluginLabel} "${typeName}" ${fieldLabel} "${fieldName}" must be type "${ajvError.params.type}".`;
21
+ case 'enum':
22
+ return `${pluginLabel} "${typeName}" ${fieldLabel} "${fieldName}" must be one of ${JSON.stringify(ajvError.params.allowedValues)}.`;
23
+ case 'additionalProperties':
24
+ return `${pluginLabel} "${typeName}" ${fieldLabel} "${ajvError.params.additionalProperty}" is not allowed.`;
25
+ case 'required':
26
+ return `${pluginLabel} "${typeName}" required ${fieldLabel} "${ajvError.params.missingProperty}" is missing.`;
27
+ default:
28
+ return `${pluginLabel} "${typeName}" ${fieldLabel} "${fieldName}" ${ajvError.message}.`;
29
+ }
30
+ }
31
+ export default formatValidationError;
@@ -12,44 +12,98 @@
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 { resolveConfigLocation } from '@lowdefy/errors/build';
16
- import { deserializeError } from '@lowdefy/errors/server';
17
- async function logClientError(context, data) {
15
+ */ import { ConfigError, loadAndResolveErrorLocation } from '@lowdefy/errors';
16
+ import { serializer, type } from '@lowdefy/helpers';
17
+ import formatValidationError from './formatValidationError.js';
18
+ import validatePluginSchema from './validatePluginSchema.js';
19
+ const validationConfigs = {
20
+ BlockError: {
21
+ schemaFile: 'plugins/blockSchemas.json',
22
+ schemaKey: 'properties',
23
+ pluginLabel: 'Block',
24
+ fieldLabel: 'property'
25
+ },
26
+ ActionError: {
27
+ schemaFile: 'plugins/actionSchemas.json',
28
+ schemaKey: 'params',
29
+ pluginLabel: 'Action',
30
+ fieldLabel: 'param'
31
+ },
32
+ OperatorError: {
33
+ schemaFile: 'plugins/operatorSchemas.json',
34
+ schemaKey: 'params',
35
+ pluginLabel: 'Operator',
36
+ fieldLabel: 'param'
37
+ }
38
+ };
39
+ async function logClientError(context, serializedError) {
18
40
  const { logger } = context;
19
- // Deserialize the error from the client
20
- const error = deserializeError(data);
21
- // Resolve config location if error has configKey
22
- if (error.configKey) {
41
+ const error = serializer.deserialize(serializedError);
42
+ // Schema validation for plugin errors with received data
43
+ const validationConfig = validationConfigs[error.name];
44
+ let validationError = null;
45
+ if (validationConfig && !type.isNone(error.received)) {
23
46
  try {
24
- const [keyMap, refMap] = await Promise.all([
25
- context.readConfigFile('keyMap.json'),
26
- context.readConfigFile('refMap.json')
27
- ]);
28
- const location = resolveConfigLocation({
29
- configKey: error.configKey,
30
- keyMap,
31
- refMap,
32
- configDirectory: context.configDirectory
33
- });
34
- if (location) {
35
- error.source = location.source;
36
- error.config = location.config;
37
- error.link = location.link;
47
+ const schemas = await context.readConfigFile(validationConfig.schemaFile);
48
+ if (schemas) {
49
+ const schema = schemas[error.typeName];
50
+ if (schema) {
51
+ const data = error.name === 'OperatorError' ? Object.values(error.received)[0] : error.received;
52
+ const ajvErrors = validatePluginSchema({
53
+ data,
54
+ schema,
55
+ schemaKey: validationConfig.schemaKey
56
+ });
57
+ if (ajvErrors) {
58
+ const displayName = error.name === 'OperatorError' && error.methodName ? `${error.typeName}.${error.methodName}` : error.typeName;
59
+ const messages = ajvErrors.map((ajvError)=>formatValidationError({
60
+ ajvError,
61
+ pluginLabel: validationConfig.pluginLabel,
62
+ typeName: displayName,
63
+ fieldLabel: validationConfig.fieldLabel
64
+ }));
65
+ const message = messages.length === 1 ? messages[0] : `${validationConfig.pluginLabel} "${displayName}" has invalid ${validationConfig.schemaKey}:\n${messages.map((m)=>` - ${m}`).join('\n')}`;
66
+ validationError = new ConfigError(message, {
67
+ configKey: error.configKey,
68
+ cause: error
69
+ });
70
+ }
71
+ }
38
72
  }
39
- } catch (err) {
40
- logger.warn({
41
- event: 'warn_maps_load_failed',
42
- error: err.message
43
- });
73
+ } catch (e) {
74
+ logger.warn(e);
75
+ }
76
+ }
77
+ const location = await loadAndResolveErrorLocation({
78
+ error,
79
+ readConfigFile: context.readConfigFile,
80
+ configDirectory: context.configDirectory
81
+ });
82
+ if (location) {
83
+ error.source = location.source;
84
+ error.config = location.config;
85
+ }
86
+ // If validation produced a ConfigError, log only that (cause chain shows original)
87
+ if (validationError) {
88
+ if (location) {
89
+ validationError.source = location.source;
90
+ validationError.config = location.config;
44
91
  }
92
+ logger.error(validationError);
93
+ return {
94
+ success: true,
95
+ source: error.source ?? null,
96
+ config: error.config ?? null,
97
+ error,
98
+ configError: serializer.serialize(validationError)
99
+ };
45
100
  }
46
- // Log error - logger handles formatting
47
101
  logger.error(error);
48
102
  return {
49
103
  success: true,
50
104
  source: error.source ?? null,
51
105
  config: error.config ?? null,
52
- link: error.link ?? null
106
+ error
53
107
  };
54
108
  }
55
109
  export default logClientError;
@@ -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
+ */ import { validate } from '@lowdefy/ajv';
16
+ function validatePluginSchema({ data, schema, schemaKey }) {
17
+ if (!schema?.[schemaKey]) return null;
18
+ const { valid, errors } = validate({
19
+ schema: schema[schemaKey],
20
+ data,
21
+ returnErrors: true
22
+ });
23
+ return valid ? null : errors;
24
+ }
25
+ export default validatePluginSchema;
@@ -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
- */ import { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  function authorizeRequest({ authorize, logger }, { requestConfig }) {
17
17
  if (!authorize(requestConfig)) {
18
18
  logger.debug({
@@ -21,8 +21,8 @@ function authorizeRequest({ authorize, logger }, { requestConfig }) {
21
21
  auth_config: requestConfig.auth
22
22
  });
23
23
  // Throw does not exist error to avoid leaking information that request exists to unauthorized users
24
- throw new ConfigError({
25
- message: `Request "${requestConfig.requestId}" does not exist.`
24
+ throw new ConfigError(`Request "${requestConfig.requestId}" does not exist.`, {
25
+ configKey: requestConfig['~k']
26
26
  });
27
27
  }
28
28
  logger.debug({
@@ -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
- */ import { ConfigError, PluginError, ServiceError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError, RequestError, ServiceError } from '@lowdefy/errors';
16
16
  async function callRequestResolver({ blockId, endpointId, logger, pageId, payload }, { connectionProperties, requestConfig, requestProperties, requestResolver }) {
17
17
  try {
18
18
  const response = await requestResolver({
@@ -43,8 +43,8 @@ async function callRequestResolver({ blockId, endpointId, logger, pageId, payloa
43
43
  }
44
44
  // Check if this is a service error (network, timeout, 5xx)
45
45
  if (ServiceError.isServiceError(error)) {
46
- const serviceError = new ServiceError({
47
- error,
46
+ const serviceError = new ServiceError(undefined, {
47
+ cause: error,
48
48
  service: requestConfig.connectionId,
49
49
  configKey: requestConfig['~k']
50
50
  });
@@ -57,11 +57,10 @@ async function callRequestResolver({ blockId, endpointId, logger, pageId, payloa
57
57
  }, serviceError.message);
58
58
  throw serviceError;
59
59
  }
60
- // Wrap other errors in PluginError (request/connection logic error)
61
- const pluginError = new PluginError({
62
- error,
63
- pluginType: 'request',
64
- pluginName: requestConfig.type,
60
+ // Wrap other errors in RequestError (request/connection logic error)
61
+ const requestError = new RequestError(error.message, {
62
+ cause: error,
63
+ typeName: requestConfig.type,
65
64
  received: requestProperties,
66
65
  location: `${requestConfig.connectionId}/${requestConfig.requestId}`,
67
66
  configKey: requestConfig['~k']
@@ -71,9 +70,9 @@ async function callRequestResolver({ blockId, endpointId, logger, pageId, payloa
71
70
  id: requestConfig.requestId,
72
71
  type: requestConfig.type
73
72
  },
74
- err: pluginError
75
- }, pluginError.message);
76
- throw pluginError;
73
+ err: requestError
74
+ }, requestError.message);
75
+ throw requestError;
77
76
  }
78
77
  }
79
78
  export default callRequestResolver;
@@ -12,12 +12,11 @@
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 { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  function checkConnectionRead({ logger }, { connectionConfig, connectionProperties, requestConfig, requestResolver }) {
17
17
  if (requestResolver.meta.checkRead && connectionProperties.read === false) {
18
18
  const configKey = requestConfig['~k'];
19
- const err = new ConfigError({
20
- message: `Connection "${connectionConfig.connectionId}" does not allow reads.`,
19
+ const err = new ConfigError(`Connection "${connectionConfig.connectionId}" does not allow reads.`, {
21
20
  configKey
22
21
  });
23
22
  logger.debug({
@@ -12,12 +12,11 @@
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 { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  function checkConnectionWrite({ logger }, { connectionConfig, connectionProperties, requestConfig, requestResolver }) {
17
17
  if (requestResolver.meta.checkWrite && connectionProperties.write !== true) {
18
18
  const configKey = requestConfig['~k'];
19
- const err = new ConfigError({
20
- message: `Connection "${connectionConfig.connectionId}" does not allow writes.`,
19
+ const err = new ConfigError(`Connection "${connectionConfig.connectionId}" does not allow writes.`, {
21
20
  configKey
22
21
  });
23
22
  logger.debug({
@@ -12,12 +12,12 @@
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 { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  function getConnection({ connections, logger }, { connectionConfig }) {
17
17
  const connection = connections[connectionConfig.type];
18
18
  if (!connection) {
19
- const err = new ConfigError({
20
- message: `Connection type "${connectionConfig.type}" can not be found.`
19
+ const err = new ConfigError(`Connection type "${connectionConfig.type}" can not be found.`, {
20
+ configKey: connectionConfig['~k']
21
21
  });
22
22
  logger.debug({
23
23
  params: {
@@ -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 { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  async function getConnectionConfig({ logger, readConfigFile }, { requestConfig }) {
17
17
  const { connectionId, requestId } = requestConfig;
18
18
  let err;
19
19
  if (!connectionId) {
20
- err = new ConfigError({
21
- message: `Request "${requestId}" does not specify a connection.`
20
+ err = new ConfigError(`Request "${requestId}" does not specify a connection.`, {
21
+ configKey: requestConfig['~k']
22
22
  });
23
23
  logger.debug({
24
24
  params: {
@@ -30,8 +30,8 @@ async function getConnectionConfig({ logger, readConfigFile }, { requestConfig }
30
30
  }
31
31
  const connection = await readConfigFile(`connections/${connectionId}.json`);
32
32
  if (!connection) {
33
- err = new ConfigError({
34
- message: `Connection "${connectionId}" does not exist.`
33
+ err = new ConfigError(`Connection "${connectionId}" does not exist.`, {
34
+ configKey: requestConfig['~k']
35
35
  });
36
36
  logger.debug({
37
37
  params: {
@@ -12,13 +12,11 @@
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 { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  async function getRequestConfig({ logger, readConfigFile }, { pageId, requestId }) {
17
17
  const request = await readConfigFile(`pages/${pageId}/requests/${requestId}.json`);
18
18
  if (!request) {
19
- const err = new ConfigError({
20
- message: `Request "${requestId}" does not exist.`
21
- });
19
+ const err = new ConfigError(`Request "${requestId}" does not exist.`);
22
20
  logger.debug({
23
21
  params: {
24
22
  pageId,
@@ -12,12 +12,12 @@
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 { ConfigError } from '@lowdefy/errors/server';
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
16
  function getRequestResolver({ logger }, { connection, requestConfig }) {
17
17
  const requestResolver = connection.requests[requestConfig.type];
18
18
  if (!requestResolver) {
19
- const err = new ConfigError({
20
- message: `Request type "${requestConfig.type}" can not be found.`
19
+ const err = new ConfigError(`Request type "${requestConfig.type}" can not be found.`, {
20
+ configKey: requestConfig['~k']
21
21
  });
22
22
  logger.debug({
23
23
  params: {
@@ -13,32 +13,46 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { validate } from '@lowdefy/ajv';
16
- import { ConfigError } from '@lowdefy/errors/server';
16
+ import { ConfigError } from '@lowdefy/errors';
17
+ import formatValidationError from '../log/formatValidationError.js';
17
18
  function validateSchemas({ logger }, { connection, connectionProperties, requestConfig, requestResolver, requestProperties }) {
18
- try {
19
- validate({
20
- schema: connection.schema,
21
- data: connectionProperties
22
- });
23
- validate({
24
- schema: requestResolver.schema,
25
- data: requestProperties
26
- });
27
- } catch (error) {
28
- const configKey = requestConfig['~k'];
29
- const err = new ConfigError({
30
- message: error.message,
19
+ const configKey = requestConfig['~k'];
20
+ const messages = [];
21
+ const connectionResult = validate({
22
+ schema: connection.schema,
23
+ data: connectionProperties,
24
+ returnErrors: true
25
+ });
26
+ if (!connectionResult.valid) {
27
+ for (const ajvError of connectionResult.errors){
28
+ messages.push(formatValidationError({
29
+ ajvError,
30
+ pluginLabel: 'Connection',
31
+ typeName: requestConfig.connectionId,
32
+ fieldLabel: 'property'
33
+ }));
34
+ }
35
+ }
36
+ const requestResult = validate({
37
+ schema: requestResolver.schema,
38
+ data: requestProperties,
39
+ returnErrors: true
40
+ });
41
+ if (!requestResult.valid) {
42
+ for (const ajvError of requestResult.errors){
43
+ messages.push(formatValidationError({
44
+ ajvError,
45
+ pluginLabel: 'Request',
46
+ typeName: requestConfig.type,
47
+ fieldLabel: 'property'
48
+ }));
49
+ }
50
+ }
51
+ if (messages.length > 0) {
52
+ const message = messages.length === 1 ? messages[0] : `Request "${requestConfig.requestId}" has schema validation errors:\n${messages.map((m)=>` - ${m}`).join('\n')}`;
53
+ throw new ConfigError(message, {
31
54
  configKey
32
55
  });
33
- logger.debug({
34
- params: {
35
- id: requestConfig.requestId,
36
- type: requestConfig.type,
37
- configKey
38
- },
39
- err
40
- }, err.message);
41
- throw err;
42
56
  }
43
57
  }
44
58
  export default validateSchemas;
@@ -27,6 +27,9 @@ function testContext({ config = {}, connections = {}, headers = {}, logger = {
27
27
  }),
28
28
  config,
29
29
  connections,
30
+ handleError: async (error)=>{
31
+ logger.error(error);
32
+ },
30
33
  headers,
31
34
  logger,
32
35
  operators,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/api",
3
- "version": "0.0.0-experimental-20260223144039",
3
+ "version": "0.0.0-experimental-20260304101313",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -34,13 +34,13 @@
34
34
  "dist/*"
35
35
  ],
36
36
  "dependencies": {
37
- "@lowdefy/ajv": "0.0.0-experimental-20260223144039",
38
- "@lowdefy/errors": "0.0.0-experimental-20260223144039",
39
- "@lowdefy/helpers": "0.0.0-experimental-20260223144039",
40
- "@lowdefy/node-utils": "0.0.0-experimental-20260223144039",
41
- "@lowdefy/nunjucks": "0.0.0-experimental-20260223144039",
42
- "@lowdefy/operators": "0.0.0-experimental-20260223144039",
43
- "@lowdefy/operators-js": "0.0.0-experimental-20260223144039"
37
+ "@lowdefy/ajv": "0.0.0-experimental-20260304101313",
38
+ "@lowdefy/errors": "0.0.0-experimental-20260304101313",
39
+ "@lowdefy/helpers": "0.0.0-experimental-20260304101313",
40
+ "@lowdefy/node-utils": "0.0.0-experimental-20260304101313",
41
+ "@lowdefy/nunjucks": "0.0.0-experimental-20260304101313",
42
+ "@lowdefy/operators": "0.0.0-experimental-20260304101313",
43
+ "@lowdefy/operators-js": "0.0.0-experimental-20260304101313"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@jest/globals": "28.1.3",