@lowdefy/errors 0.0.0-experimental-20260914131506 → 0.0.0-experimental-20260925210809

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,8 @@
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
- */ /**
15
+ */ import readErrorCodes from './readErrorCodes.js';
16
+ /**
16
17
  * Base error class for plugin failures (operators, actions, blocks, requests).
17
18
  *
18
19
  * Plugins throw plain Error objects with simple messages.
@@ -59,6 +60,12 @@
59
60
  this.received = received !== undefined ? received : cause?.received;
60
61
  this.location = location;
61
62
  this.configKey = configKey ?? cause?.configKey ?? null;
63
+ // Config branches on `code`/`statusCode` of the top-level error, which is
64
+ // this wrapper, so lift them from the plugin's error. One level only: each
65
+ // deeper cause is a node of its own and keeps its own codes.
66
+ const { code, statusCode } = readErrorCodes(cause);
67
+ if (code !== undefined) this.code = code;
68
+ if (statusCode !== undefined) this.statusCode = statusCode;
62
69
  // Location outputs (set by server-side resolution)
63
70
  this.source = null;
64
71
  this.config = null;
@@ -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
+ */ // Thrown when an authorized caller has not enrolled a second factor and the
16
+ // deployment sets auth.twoFactor.required. Distinct from AuthenticationError on
17
+ // purpose: a 401 reads to the client as a dead session and bounces the user to
18
+ // sign-in, which is the redirect loop the enrolment gate exists to avoid, so this
19
+ // maps to 403. The server error handlers branch on the name before the
20
+ // structured-log and Sentry pipeline - under required: true this is expected
21
+ // traffic from every unenrolled caller, not a fault.
22
+ let TwoFactorEnrolmentRequiredError = class TwoFactorEnrolmentRequiredError extends Error {
23
+ constructor(message = 'Two-factor enrolment required.', { cause } = {}){
24
+ super(message, {
25
+ cause
26
+ });
27
+ this.name = 'TwoFactorEnrolmentRequiredError';
28
+ this.isLowdefyError = true;
29
+ }
30
+ };
31
+ export default TwoFactorEnrolmentRequiredError;
package/dist/index.js CHANGED
@@ -56,8 +56,13 @@
56
56
  * - Caught: Server error handlers, before structured logging and Sentry (401)
57
57
  * - Format: [AuthenticationError] message
58
58
  *
59
- * 8. AuthorizationError - Authenticated caller refused by an authorization gate (wrong roles)
60
- * - Thrown: Request, endpoint, agent and auth-step authorization gates
59
+ * 8. TwoFactorEnrolmentRequiredError - Authorized caller with no enrolled second factor
60
+ * - Thrown: The authorization gate, when auth.twoFactor.required is set and the caller is unenrolled
61
+ * - Caught: Server error handlers, before structured logging and Sentry (403)
62
+ * - Format: [TwoFactorEnrolmentRequiredError] message
63
+ *
64
+ * 9. AuthorizationError - Authenticated caller refused by an authorization gate (wrong roles)
65
+ * - Thrown: Request, endpoint, agent, websocket and auth-step authorization gates
61
66
  * - Caught: Server error handlers, before structured logging and Sentry (403)
62
67
  * - Format: [AuthorizationError] message
63
68
  *
@@ -66,6 +71,11 @@
66
71
  * resolveErrorLocation - Sync: unified resolver (configKey or filePath/lineNumber)
67
72
  * loadAndResolveErrorLocation - Async: reads keyMap/refMap files at runtime
68
73
  * shouldSuppressBuildCheck - Check ~ignoreBuildChecks in parent chain
74
+ *
75
+ * Error Field Utilities:
76
+ * readErrorCodes - {code, statusCode} from one error node's own fields
77
+ * lowdefyErrorNames - Set of Lowdefy error class names
78
+ * lowdefyErrorTypes - Lowdefy error class by name, for reviving and reshaping errors
69
79
  */ import ActionError from './ActionError.js';
70
80
  import AuthenticationError from './AuthenticationError.js';
71
81
  import AuthorizationError from './AuthorizationError.js';
@@ -75,13 +85,17 @@ import ConfigError from './ConfigError.js';
75
85
  import ConfigWarning from './ConfigWarning.js';
76
86
  import errorToDisplayString from './errorToDisplayString.js';
77
87
  import LowdefyInternalError from './LowdefyInternalError.js';
88
+ import lowdefyErrorNames from './lowdefyErrorNames.js';
89
+ import lowdefyErrorTypes from './lowdefyErrorTypes.js';
78
90
  import OperatorError from './OperatorError.js';
79
91
  import PluginError from './PluginError.js';
92
+ import readErrorCodes from './readErrorCodes.js';
80
93
  import RequestError from './RequestError.js';
81
94
  import resolveConfigLocation from './resolveConfigLocation.js';
82
95
  import loadAndResolveErrorLocation from './loadAndResolveErrorLocation.js';
83
96
  import resolveErrorLocation from './resolveErrorLocation.js';
84
97
  import ServiceError from './ServiceError.js';
85
98
  import shouldSuppressBuildCheck, { VALID_CHECK_SLUGS } from './shouldSuppressBuildCheck.js';
99
+ import TwoFactorEnrolmentRequiredError from './TwoFactorEnrolmentRequiredError.js';
86
100
  import UserError from './UserError.js';
87
- export { ActionError, AuthenticationError, AuthorizationError, BlockError, BuildError, ConfigError, ConfigWarning, errorToDisplayString, LowdefyInternalError, OperatorError, PluginError, RequestError, resolveConfigLocation, loadAndResolveErrorLocation, resolveErrorLocation, ServiceError, shouldSuppressBuildCheck, UserError, VALID_CHECK_SLUGS };
101
+ export { ActionError, AuthenticationError, AuthorizationError, BlockError, BuildError, ConfigError, ConfigWarning, errorToDisplayString, LowdefyInternalError, lowdefyErrorNames, lowdefyErrorTypes, OperatorError, PluginError, readErrorCodes, RequestError, resolveConfigLocation, loadAndResolveErrorLocation, resolveErrorLocation, ServiceError, shouldSuppressBuildCheck, TwoFactorEnrolmentRequiredError, UserError, VALID_CHECK_SLUGS };
@@ -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
+ */ // Keyed on the class name rather than `isLowdefyError`, because an error rebuilt
16
+ // from a caught value can drop `isLowdefyError` yet must keep its class name.
17
+ const lowdefyErrorNames = new Set([
18
+ 'ActionError',
19
+ 'AuthenticationError',
20
+ 'AuthorizationError',
21
+ 'BlockError',
22
+ 'BuildError',
23
+ 'ConfigError',
24
+ 'ConfigWarning',
25
+ 'LowdefyInternalError',
26
+ 'OperatorError',
27
+ 'PluginError',
28
+ 'RequestError',
29
+ 'ServiceError',
30
+ 'TwoFactorEnrolmentRequiredError',
31
+ 'UserError'
32
+ ]);
33
+ export default lowdefyErrorNames;
@@ -0,0 +1,47 @@
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 ActionError from './ActionError.js';
16
+ import AuthenticationError from './AuthenticationError.js';
17
+ import AuthorizationError from './AuthorizationError.js';
18
+ import BlockError from './BlockError.js';
19
+ import BuildError from './BuildError.js';
20
+ import ConfigError from './ConfigError.js';
21
+ import ConfigWarning from './ConfigWarning.js';
22
+ import LowdefyInternalError from './LowdefyInternalError.js';
23
+ import OperatorError from './OperatorError.js';
24
+ import PluginError from './PluginError.js';
25
+ import RequestError from './RequestError.js';
26
+ import ServiceError from './ServiceError.js';
27
+ import TwoFactorEnrolmentRequiredError from './TwoFactorEnrolmentRequiredError.js';
28
+ import UserError from './UserError.js';
29
+ // Name to class, for rebuilding an error whose class identity is gone but whose
30
+ // name survived - a serializer round trip, or a caught error being reshaped.
31
+ const lowdefyErrorTypes = {
32
+ ActionError,
33
+ AuthenticationError,
34
+ AuthorizationError,
35
+ BlockError,
36
+ BuildError,
37
+ ConfigError,
38
+ ConfigWarning,
39
+ LowdefyInternalError,
40
+ OperatorError,
41
+ PluginError,
42
+ RequestError,
43
+ ServiceError,
44
+ TwoFactorEnrolmentRequiredError,
45
+ UserError
46
+ };
47
+ export default lowdefyErrorTypes;
@@ -0,0 +1,37 @@
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
+ */ // One rule over the conventions libraries already follow, instead of a
16
+ // per-driver table that goes stale: Node system errors, Postgres and Mongo set
17
+ // `code`; axios and most HTTP SDKs set `statusCode`, `status` or
18
+ // `response.status`. Non-number statuses are skipped so config branching on
19
+ // `statusCode` only ever compares against a number.
20
+ function readErrorCodes(node) {
21
+ if (node === null || typeof node !== 'object') {
22
+ return {
23
+ code: undefined,
24
+ statusCode: undefined
25
+ };
26
+ }
27
+ const statusCode = [
28
+ node.statusCode,
29
+ node.status,
30
+ node.response?.status
31
+ ].find((value)=>typeof value === 'number');
32
+ return {
33
+ code: node.code,
34
+ statusCode
35
+ };
36
+ }
37
+ export default readErrorCodes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/errors",
3
- "version": "0.0.0-experimental-20260914131506",
3
+ "version": "0.0.0-experimental-20260925210809",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy error classes for consistent error handling across build, server, and client",
6
6
  "homepage": "https://lowdefy.com",