@lowdefy/api 0.0.0-experimental-20260219135421 → 0.0.0-experimental-20260220095000

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
@@ -12,44 +12,26 @@
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 { loadAndResolveErrorLocation } from '@lowdefy/errors';
16
+ import { serializer } from '@lowdefy/helpers';
17
+ async function logClientError(context, serializedError) {
18
18
  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) {
23
- 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;
38
- }
39
- } catch (err) {
40
- logger.warn({
41
- event: 'warn_maps_load_failed',
42
- error: err.message
43
- });
44
- }
19
+ const error = serializer.deserialize(serializedError);
20
+ const location = await loadAndResolveErrorLocation({
21
+ error,
22
+ readConfigFile: context.readConfigFile,
23
+ configDirectory: context.configDirectory
24
+ });
25
+ if (location) {
26
+ error.source = location.source;
27
+ error.config = location.config;
45
28
  }
46
- // Log error - logger handles formatting
47
29
  logger.error(error);
48
30
  return {
49
31
  success: true,
50
32
  source: error.source ?? null,
51
33
  config: error.config ?? null,
52
- link: error.link ?? null
34
+ error
53
35
  };
54
36
  }
55
37
  export default logClientError;
@@ -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,7 +13,7 @@
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
17
  function validateSchemas({ logger }, { connection, connectionProperties, requestConfig, requestResolver, requestProperties }) {
18
18
  try {
19
19
  validate({
@@ -26,8 +26,7 @@ function validateSchemas({ logger }, { connection, connectionProperties, request
26
26
  });
27
27
  } catch (error) {
28
28
  const configKey = requestConfig['~k'];
29
- const err = new ConfigError({
30
- message: error.message,
29
+ const err = new ConfigError(error.message, {
31
30
  configKey
32
31
  });
33
32
  logger.debug({
@@ -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-20260219135421",
3
+ "version": "0.0.0-experimental-20260220095000",
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-20260219135421",
38
- "@lowdefy/errors": "0.0.0-experimental-20260219135421",
39
- "@lowdefy/helpers": "0.0.0-experimental-20260219135421",
40
- "@lowdefy/node-utils": "0.0.0-experimental-20260219135421",
41
- "@lowdefy/nunjucks": "0.0.0-experimental-20260219135421",
42
- "@lowdefy/operators": "0.0.0-experimental-20260219135421",
43
- "@lowdefy/operators-js": "0.0.0-experimental-20260219135421"
37
+ "@lowdefy/ajv": "0.0.0-experimental-20260220095000",
38
+ "@lowdefy/errors": "0.0.0-experimental-20260220095000",
39
+ "@lowdefy/helpers": "0.0.0-experimental-20260220095000",
40
+ "@lowdefy/node-utils": "0.0.0-experimental-20260220095000",
41
+ "@lowdefy/nunjucks": "0.0.0-experimental-20260220095000",
42
+ "@lowdefy/operators": "0.0.0-experimental-20260220095000",
43
+ "@lowdefy/operators-js": "0.0.0-experimental-20260220095000"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@jest/globals": "28.1.3",