@lowdefy/errors 0.0.0-experimental-20260909123240 → 0.0.0-experimental-20260909201552

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.
@@ -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 authenticated caller is refused by an authorization gate - the
16
+ // caller holds a session or a strategy credential but not the roles the
17
+ // request, endpoint, agent, websocket or auth step requires. Maps to 403. The
18
+ // message is written by the gate and may stay deliberately generic so it does
19
+ // not reveal what exists. The server error handlers branch on the name before
20
+ // the structured-log and Sentry pipeline: a caller with the wrong roles is
21
+ // expected traffic and produces one warning line, not an error log.
22
+ let AuthorizationError = class AuthorizationError extends Error {
23
+ constructor(message = 'Forbidden.', { cause } = {}){
24
+ super(message, {
25
+ cause
26
+ });
27
+ this.name = 'AuthorizationError';
28
+ this.isLowdefyError = true;
29
+ }
30
+ };
31
+ export default AuthorizationError;
@@ -59,8 +59,10 @@
59
59
  if (error.code && SERVICE_ERROR_CODES.has(error.code)) {
60
60
  return true;
61
61
  }
62
- // Check HTTP status codes (5xx = server error)
63
- const statusCode = error.statusCode ?? error.status ?? error.response?.status;
62
+ // Check HTTP status codes (5xx = server error). AWS SDK v3 errors carry the
63
+ // status on $metadata.httpStatusCode; @google-cloud errors carry the numeric
64
+ // HTTP status as `code`.
65
+ const statusCode = error.statusCode ?? error.status ?? error.response?.status ?? error.$metadata?.httpStatusCode ?? (Number.isInteger(error.code) ? error.code : undefined);
64
66
  if (statusCode && statusCode >= 500 && statusCode < 600) {
65
67
  return true;
66
68
  }
@@ -104,7 +106,9 @@
104
106
  * @param {string} [options.code] - Error code (e.g., 'ECONNREFUSED')
105
107
  * @param {number} [options.statusCode] - HTTP status code if applicable
106
108
  * @param {string} [options.configKey] - Config key for location resolution
107
- */ constructor(message, { cause, service, code, statusCode, configKey } = {}){
109
+ * @param {string} [options.hint] - A sentence telling the developer what to do about the
110
+ * failure. Enumerable, so it survives serialization to the client.
111
+ */ constructor(message, { cause, service, code, statusCode, configKey, hint } = {}){
108
112
  // Extract info from wrapped error if provided
109
113
  const errorCode = code ?? cause?.code;
110
114
  const errorStatusCode = statusCode ?? cause?.statusCode ?? cause?.status ?? cause?.response?.status;
@@ -121,8 +125,11 @@
121
125
  this._message = baseMessage;
122
126
  this.service = service;
123
127
  this.code = errorCode;
128
+ this.hint = hint ?? cause?.hint ?? null;
124
129
  this.statusCode = errorStatusCode;
125
- this.configKey = configKey ?? null;
130
+ // Extract from the wrapped error like PluginError does, so a ServiceError
131
+ // wrapped around an error that already resolved its config location keeps it.
132
+ this.configKey = configKey ?? cause?.configKey ?? null;
126
133
  }
127
134
  };
128
135
  export default ServiceError;
@@ -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;
@@ -16,7 +16,10 @@
16
16
  if (typeof error === 'string') return error;
17
17
  if (error?.message === undefined) return String(error);
18
18
  const name = error.name || 'Error';
19
- let msg = `[${name}] ${error.message}`;
19
+ // Prod-gated build warnings are not fatal in dev but fail `lowdefy build`, so
20
+ // the name segment says so wherever the error is displayed.
21
+ const nameSegment = error.prodError === true ? `${name} · fails in prod` : name;
22
+ let msg = `[${nameSegment}] ${error.message}`;
20
23
  if (error.received !== undefined) {
21
24
  try {
22
25
  msg = `${msg} Received: ${JSON.stringify(error.received)}`;
package/dist/index.js CHANGED
@@ -42,9 +42,13 @@
42
42
  * - Extends ConfigError with name override
43
43
  * - Format: source:line\n[ConfigWarning] message
44
44
  *
45
- * 6. UserError - User-authored deliberate failure
46
- * - Thrown: Client-side Throw action; server-side controlThrow (routine :throw) and controlReject (routine :reject)
47
- * - Caught: Caller of the action/resolver; signals "the called routine deliberately failed" as distinct from a system fault
45
+ * 6. UserError - An expected outcome of user interaction, never a config or system fault
46
+ * - Thrown: Client-side Throw and Validate actions; server-side controlThrow (routine :throw)
47
+ * and controlReject (routine :reject); client auth methods when the auth server rejects
48
+ * the attempt (4xx: wrong password, expired or used link, invalid code, stale OAuth query)
49
+ * - Caught: Caller of the action/resolver; the message is shown to the user and catch actions
50
+ * run, but it logs to the browser console only - never posted to /api/client-error, never
51
+ * logged on the server at error level, never resolved to a config location
48
52
  * - Format: [User Error] message
49
53
  *
50
54
  * 7. AuthenticationError - Unauthenticated request to a protected endpoint
@@ -52,6 +56,16 @@
52
56
  * - Caught: Server error handlers, before structured logging and Sentry (401)
53
57
  * - Format: [AuthenticationError] message
54
58
  *
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
66
+ * - Caught: Server error handlers, before structured logging and Sentry (403)
67
+ * - Format: [AuthorizationError] message
68
+ *
55
69
  * Location Resolution Utilities:
56
70
  * resolveConfigLocation - Sync: configKey → {source, config} via keyMap/refMap
57
71
  * resolveErrorLocation - Sync: unified resolver (configKey or filePath/lineNumber)
@@ -59,6 +73,7 @@
59
73
  * shouldSuppressBuildCheck - Check ~ignoreBuildChecks in parent chain
60
74
  */ import ActionError from './ActionError.js';
61
75
  import AuthenticationError from './AuthenticationError.js';
76
+ import AuthorizationError from './AuthorizationError.js';
62
77
  import BlockError from './BlockError.js';
63
78
  import BuildError from './BuildError.js';
64
79
  import ConfigError from './ConfigError.js';
@@ -73,5 +88,6 @@ import loadAndResolveErrorLocation from './loadAndResolveErrorLocation.js';
73
88
  import resolveErrorLocation from './resolveErrorLocation.js';
74
89
  import ServiceError from './ServiceError.js';
75
90
  import shouldSuppressBuildCheck, { VALID_CHECK_SLUGS } from './shouldSuppressBuildCheck.js';
91
+ import TwoFactorEnrolmentRequiredError from './TwoFactorEnrolmentRequiredError.js';
76
92
  import UserError from './UserError.js';
77
- export { ActionError, AuthenticationError, BlockError, BuildError, ConfigError, ConfigWarning, errorToDisplayString, LowdefyInternalError, OperatorError, PluginError, RequestError, resolveConfigLocation, loadAndResolveErrorLocation, resolveErrorLocation, ServiceError, shouldSuppressBuildCheck, UserError, VALID_CHECK_SLUGS };
93
+ export { ActionError, AuthenticationError, AuthorizationError, BlockError, BuildError, ConfigError, ConfigWarning, errorToDisplayString, LowdefyInternalError, OperatorError, PluginError, RequestError, resolveConfigLocation, loadAndResolveErrorLocation, resolveErrorLocation, ServiceError, shouldSuppressBuildCheck, TwoFactorEnrolmentRequiredError, UserError, VALID_CHECK_SLUGS };
@@ -23,8 +23,14 @@
23
23
  'link-refs': 'Invalid Link action page reference warnings',
24
24
  'request-refs': 'Invalid Request action reference warnings',
25
25
  'connection-refs': 'Nonexistent connection ID references',
26
+ 'callapi-refs': 'Invalid CallAPI action endpoint reference warnings',
27
+ 'callapi-internal-refs': 'CallAPI actions targeting InternalApi endpoints',
28
+ 'dynamic-endpoint-refs': 'Invalid Dynamic block endpoint reference warnings',
29
+ 'websocket-refs': 'Invalid websocket action reference warnings',
30
+ icons: 'Unresolvable icon name warnings',
26
31
  types: 'All type validation (blocks, operators, actions, requests, connections)',
27
- schema: 'JSON schema validation errors'
32
+ schema: 'JSON schema validation errors',
33
+ secrets: 'Environment variable names that are not set in the build environment'
28
34
  };
29
35
  /**
30
36
  * Checks if a build check should be suppressed based on ~ignoreBuildChecks.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/errors",
3
- "version": "0.0.0-experimental-20260909123240",
3
+ "version": "0.0.0-experimental-20260909201552",
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",