@dpuse/dpuse-shared 0.3.826 → 0.3.830
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/README.md +46 -74
- package/dist/dpuse-shared-errors.es.js +59 -36
- package/dist/dpuse-shared-errors.es.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
# DPUse Shared Library
|
|
2
2
|
|
|
3
|
-
[](./LICENSE)
|
|
4
|
-
[](https://www.npmjs.com/package/@dpuse/dpuse-shared)
|
|
5
|
-
[](https://github.com/dpuse/dpuse-shared/actions/workflows/codeql.yml)
|
|
6
|
-
[](https://sonarcloud.io/summary/new_code?id=dpuse_dpuse-shared)
|
|
7
|
-
[](https://github.com/dpuse/dpuse-shared/actions/workflows/ci.yml)
|
|
8
|
-
|
|
9
|
-
## Introduction
|
|
10
|
-
|
|
11
|
-
@dpuse/dpuse-shared is the foundational library for the [DPUse](https://www.dpuse.app/) ecosystem. It provides the common constants, types, errors, and utilities that are shared across all DPUse modules — including the App, API, Engine, Connectors, Contexts, Presenters and Recipes.
|
|
12
|
-
|
|
13
|
-
The library is written in TypeScript and designed to be consumed exclusively by TypeScript projects. All configuration types are schema-validated using [Valibot](https://valibot.dev/), giving consumers both compile-time safety and runtime validation from a single source of truth.
|
|
14
|
-
|
|
15
3
|
<!-- OPENING_START -->
|
|
16
4
|
|
|
17
5
|
[](./LICENSE)
|
|
@@ -28,10 +16,12 @@ DPUse (Data Positioning & Use) is an in-browser application that positions your
|
|
|
28
16
|
|
|
29
17
|
## Introduction
|
|
30
18
|
|
|
31
|
-
|
|
19
|
+
@dpuse/dpuse-shared is the foundational library for the [DPUse](https://www.dpuse.app/) ecosystem. It provides the common constants, types, errors, and utilities that are shared across all DPUse modules — including the App, API, Engine, Connectors, Contexts, Presenters and Recipes.,The library is written in TypeScript and designed to be consumed exclusively by TypeScript projects. All configuration types are schema-validated using [Valibot](https://valibot.dev/), giving consumers both compile-time safety and runtime validation from a single source of truth.
|
|
32
20
|
|
|
33
21
|
<!-- OPENING_END -->
|
|
34
22
|
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
35
25
|
<!-- USAGE_START -->
|
|
36
26
|
|
|
37
27
|
This connector is automatically uploaded to the DPUse Engine cloud once released and becomes instantly available to all new browser app instances, with existing instances notified of the update.
|
|
@@ -48,19 +38,7 @@ _Requires [Node.js](https://nodejs.org/) 24 or later, [npm](https://www.npmjs.co
|
|
|
48
38
|
|
|
49
39
|
<!-- USAGE_END -->
|
|
50
40
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## Prerequisites
|
|
54
|
-
|
|
55
|
-
The following are required to use this library:
|
|
56
|
-
|
|
57
|
-
| Prerequisite | Version |
|
|
58
|
-
| --------------------------------------------- | :-----: |
|
|
59
|
-
| [Node.js](https://nodejs.org/) | ≥ 22.0 |
|
|
60
|
-
| [npm](https://www.npmjs.com/) | ≥ 11.0 |
|
|
61
|
-
| [TypeScript](https://www.typescriptlang.org/) | ≥ 6.0 |
|
|
62
|
-
|
|
63
|
-
## Installation
|
|
41
|
+
### OLD Installation
|
|
64
42
|
|
|
65
43
|
`@dpuse/dpuse-shared` is published to the [public npm registry](https://www.npmjs.com/package/@dpuse/dpuse-shared). Install it using your preferred package manager:
|
|
66
44
|
|
|
@@ -75,9 +53,7 @@ yarn add @dpuse/dpuse-shared
|
|
|
75
53
|
pnpm add @dpuse/dpuse-shared
|
|
76
54
|
```
|
|
77
55
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
## Usage
|
|
56
|
+
### OLD Usage
|
|
81
57
|
|
|
82
58
|
This package uses [sub-path exports](https://nodejs.org/api/packages.html#subpath-exports). Import only the entry points you need:
|
|
83
59
|
|
|
@@ -127,51 +103,47 @@ See [API_REFERENCE.md](./API_REFERENCE.md) for the complete API reference, inclu
|
|
|
127
103
|
|
|
128
104
|
## Dependency Licenses
|
|
129
105
|
|
|
130
|
-
License data is collected automatically on each release using [license-checker](https://github.com/RSeidelsohn/license-checker-rseidelsohn). The following table lists all production dependencies. These dependencies (including transitive ones) have been checked and confirmed to use Apache-2.0, BSD-3-Clause, CC0-1.0, or MIT — all permissive, commercially-friendly licenses. Developers cloning this repository should independently verify development dependencies; users of the uploaded library are covered by these checks.
|
|
131
|
-
|
|
132
106
|
<!-- DEPENDENCY_LICENSES_START -->
|
|
133
107
|
|
|
134
108
|
License data is collected automatically on each release using [license-checker](https://github.com/RSeidelsohn/license-checker-rseidelsohn). The following table lists all production dependencies. These dependencies (including transitive ones) have been checked and confirmed to use Apache-2.0, BSD-3-Clause, or MIT — all permissive, commercially-friendly licenses. Users of the uploaded library are covered by these checks; developers cloning this repository should independently verify development dependencies.
|
|
135
109
|
|
|
136
|
-
|Dependency|Version|License(s)|Document|
|
|
137
|
-
|
|
138
|
-
|[@borewit/text-codec](https://github.com/Borewit/text-codec)|0.2.2|MIT|[LICENSE](licenses/downloads/@borewit/text-codec@0.2.2-LICENSE.txt)|
|
|
139
|
-
|[@tokenizer/inflate](https://github.com/Borewit/tokenizer-inflate)|0.4.1|MIT|[LICENSE](licenses/downloads/@tokenizer/inflate@0.4.1-LICENSE.txt)|
|
|
140
|
-
|[@tokenizer/token](https://github.com/Borewit/tokenizer-token)|0.3.0|MIT|[LICENSE](licenses/downloads/@tokenizer/token@0.3.0-LICENSE.txt)|
|
|
141
|
-
|[debug](https://github.com/debug-js/debug)|4.4.3|MIT|[LICENSE](licenses/downloads/debug@4.4.3-LICENSE.txt)|
|
|
142
|
-
|[file-type](https://github.com/sindresorhus/file-type)|22.1.1|MIT|[LICENSE](licenses/downloads/file-type@22.1.1-LICENSE.txt)|
|
|
143
|
-
|[ieee754](https://github.com/feross/ieee754)|1.2.1|BSD-3-Clause|[LICENSE](licenses/downloads/ieee754@1.2.1-LICENSE.txt)|
|
|
144
|
-
|[ms](https://github.com/vercel/ms)|2.1.3|MIT|[LICENSE](licenses/downloads/ms@2.1.3-LICENSE.txt)|
|
|
145
|
-
|[strtok3](https://github.com/Borewit/strtok3)|10.3.5|MIT|[LICENSE](licenses/downloads/strtok3@10.3.5-LICENSE.txt)|
|
|
146
|
-
|[token-types](https://github.com/Borewit/token-types)|6.1.2|MIT|[LICENSE](licenses/downloads/token-types@6.1.2-LICENSE.txt)|
|
|
147
|
-
|[typescript](https://github.com/microsoft/TypeScript)|6.0.3|Apache-2.0|[LICENSE](licenses/downloads/typescript@6.0.3-LICENSE.txt)|
|
|
148
|
-
|[uint8array-extras](https://github.com/sindresorhus/uint8array-extras)|1.5.0|MIT|[LICENSE](licenses/downloads/uint8array-extras@1.5.0-LICENSE.txt)|
|
|
149
|
-
|[valibot](https://github.com/open-circle/valibot)|1.5.0|MIT|[LICENSE](licenses/downloads/valibot@1.5.0-LICENSE.txt)|
|
|
110
|
+
| Dependency | Version | License(s) | Document |
|
|
111
|
+
| :--------------------------------------------------------------------- | :-----: | :----------- | :------------------------------------------------------------------ |
|
|
112
|
+
| [@borewit/text-codec](https://github.com/Borewit/text-codec) | 0.2.2 | MIT | [LICENSE](licenses/downloads/@borewit/text-codec@0.2.2-LICENSE.txt) |
|
|
113
|
+
| [@tokenizer/inflate](https://github.com/Borewit/tokenizer-inflate) | 0.4.1 | MIT | [LICENSE](licenses/downloads/@tokenizer/inflate@0.4.1-LICENSE.txt) |
|
|
114
|
+
| [@tokenizer/token](https://github.com/Borewit/tokenizer-token) | 0.3.0 | MIT | [LICENSE](licenses/downloads/@tokenizer/token@0.3.0-LICENSE.txt) |
|
|
115
|
+
| [debug](https://github.com/debug-js/debug) | 4.4.3 | MIT | [LICENSE](licenses/downloads/debug@4.4.3-LICENSE.txt) |
|
|
116
|
+
| [file-type](https://github.com/sindresorhus/file-type) | 22.1.1 | MIT | [LICENSE](licenses/downloads/file-type@22.1.1-LICENSE.txt) |
|
|
117
|
+
| [ieee754](https://github.com/feross/ieee754) | 1.2.1 | BSD-3-Clause | [LICENSE](licenses/downloads/ieee754@1.2.1-LICENSE.txt) |
|
|
118
|
+
| [ms](https://github.com/vercel/ms) | 2.1.3 | MIT | [LICENSE](licenses/downloads/ms@2.1.3-LICENSE.txt) |
|
|
119
|
+
| [strtok3](https://github.com/Borewit/strtok3) | 10.3.5 | MIT | [LICENSE](licenses/downloads/strtok3@10.3.5-LICENSE.txt) |
|
|
120
|
+
| [token-types](https://github.com/Borewit/token-types) | 6.1.2 | MIT | [LICENSE](licenses/downloads/token-types@6.1.2-LICENSE.txt) |
|
|
121
|
+
| [typescript](https://github.com/microsoft/TypeScript) | 6.0.3 | Apache-2.0 | [LICENSE](licenses/downloads/typescript@6.0.3-LICENSE.txt) |
|
|
122
|
+
| [uint8array-extras](https://github.com/sindresorhus/uint8array-extras) | 1.5.0 | MIT | [LICENSE](licenses/downloads/uint8array-extras@1.5.0-LICENSE.txt) |
|
|
123
|
+
| [valibot](https://github.com/open-circle/valibot) | 1.5.0 | MIT | [LICENSE](licenses/downloads/valibot@1.5.0-LICENSE.txt) |
|
|
150
124
|
|
|
151
125
|
<!-- DEPENDENCY_LICENSES_END -->
|
|
152
126
|
|
|
153
127
|
### Dependency Tree
|
|
154
128
|
|
|
155
|
-
The dependency tree below lists every package in this project — direct and transitive — along with its installed version, release date, and update status. Packages flagged ❗ have a newer version available; ⚠️ indicates a package that hasn't been updated in the last 6 months or longer. Neither flag necessarily indicates a problem: we let new releases stabilise before upgrading, and some packages are simply mature and stable, requiring no active development.
|
|
156
|
-
|
|
157
129
|
<!-- DEPENDENCY_TREE_START -->
|
|
158
130
|
|
|
159
131
|
The dependency tree below lists every package in this project — direct and transitive — along with its installed version, release date, and update status. Packages flagged ❗ have a newer version available; ⚠️ indicates a package that hasn't been updated in the last 6 months or longer. Neither flag necessarily indicates a problem: we let new releases stabilise before upgrading, and some packages are simply mature and stable, requiring no active development.
|
|
160
132
|
|
|
161
133
|
- **[file-type](https://github.com/sindresorhus/file-type)** 22.1.1 — this month: 2026-09-17
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
134
|
+
- **[@tokenizer/inflate](https://github.com/Borewit/tokenizer-inflate)** 0.4.1 — **10 months** ago: 2025-11-18 ⚠️
|
|
135
|
+
- **[debug](https://github.com/debug-js/debug)** 4.4.3 — **12 months** ago: 2025-09-13 ⚠️
|
|
136
|
+
- **[ms](https://github.com/vercel/ms)** 2.1.3 — **69 months** ago: 2020-12-08 ⚠️
|
|
137
|
+
- **[token-types](https://github.com/Borewit/token-types)** 6.1.2 — **8 months** ago: 2026-01-01 ⚠️
|
|
138
|
+
- **[strtok3](https://github.com/Borewit/strtok3)** 10.3.5 — **6 months** ago: 2026-03-21
|
|
139
|
+
- **[@tokenizer/token](https://github.com/Borewit/tokenizer-token)** 0.3.0 — **62 months** ago: 2021-07-12 ⚠️
|
|
165
140
|
- **[token-types](https://github.com/Borewit/token-types)** 6.1.2 — **8 months** ago: 2026-01-01 ⚠️
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
- **[
|
|
170
|
-
- **[@tokenizer/token](https://github.com/Borewit/tokenizer-token)** 0.3.0 — **62 months** ago: 2021-07-12 ⚠️
|
|
171
|
-
- **[ieee754](https://github.com/feross/ieee754)** 1.2.1 — **70 months** ago: 2020-10-27 ⚠️
|
|
172
|
-
- **[uint8array-extras](https://github.com/sindresorhus/uint8array-extras)** 1.5.0 — **13 months** ago: 2025-08-22 ⚠️
|
|
141
|
+
- **[@borewit/text-codec](https://github.com/Borewit/text-codec)** 0.2.2 — **6 months** ago: 2026-03-11
|
|
142
|
+
- **[@tokenizer/token](https://github.com/Borewit/tokenizer-token)** 0.3.0 — **62 months** ago: 2021-07-12 ⚠️
|
|
143
|
+
- **[ieee754](https://github.com/feross/ieee754)** 1.2.1 — **70 months** ago: 2020-10-27 ⚠️
|
|
144
|
+
- **[uint8array-extras](https://github.com/sindresorhus/uint8array-extras)** 1.5.0 — **13 months** ago: 2025-08-22 ⚠️
|
|
173
145
|
- **[valibot](https://github.com/open-circle/valibot)** 1.5.0 — this month: 2026-09-09
|
|
174
|
-
|
|
146
|
+
- **[typescript](https://github.com/microsoft/TypeScript)** 6.0.3 — **5 months** ago: 2026-04-16 → **latest**: 7.0.2 — **2 months** ago: 2026-07-08 ❗
|
|
175
147
|
|
|
176
148
|
<!-- DEPENDENCY_TREE_END -->
|
|
177
149
|
|
|
@@ -186,39 +158,39 @@ _Note: Sonda's Vite reports currently exclude CSS files, since Vite does not gen
|
|
|
186
158
|
|Chunk/Module/File|Composition|
|
|
187
159
|
|:------ |:-----------|
|
|
188
160
|
| dist/componentConfig.schema-DT3mO5rS.js | 10.2 kB · brotli 2.3 kB |
|
|
189
|
-
| valibot → dist/index.mjs | `████░░░░░░░░░░░░░░░░`
|
|
190
|
-
| (unassigned) → [unassigned] | `█░░░░░░░░░░░░░░░░░░░` 5.
|
|
191
|
-
| src | `█░░░░░░░░░░░░░░░░░░░` 4.
|
|
161
|
+
| valibot → dist/index.mjs | `████░░░░░░░░░░░░░░░░` 20.6% |
|
|
162
|
+
| (unassigned) → [unassigned] | `█░░░░░░░░░░░░░░░░░░░` 5.2% |
|
|
163
|
+
| src | `█░░░░░░░░░░░░░░░░░░░` 4.1% |
|
|
192
164
|
| componentConfig.schema.ts | `█░░░░░░░░░░░░░░░░░░░` 2.7% |
|
|
193
165
|
| locale.schema.ts | `░░░░░░░░░░░░░░░░░░░░` 0.8% |
|
|
194
|
-
| baseConfig.schema.ts | `░░░░░░░░░░░░░░░░░░░░` 0.
|
|
166
|
+
| baseConfig.schema.ts | `░░░░░░░░░░░░░░░░░░░░` 0.5% |
|
|
195
167
|
| schema.ts | `░░░░░░░░░░░░░░░░░░░░` 0.2% |
|
|
196
168
|
| dist/dpuse-shared-encoding.es.js | 7.4 kB · brotli 1.3 kB |
|
|
197
|
-
| src → index.ts | `████░░░░░░░░░░░░░░░░`
|
|
198
|
-
| (unassigned) → [unassigned] | `█░░░░░░░░░░░░░░░░░░░`
|
|
169
|
+
| src → index.ts | `████░░░░░░░░░░░░░░░░` 18.8% |
|
|
170
|
+
| (unassigned) → [unassigned] | `█░░░░░░░░░░░░░░░░░░░` 2.9% |
|
|
171
|
+
| dist/dpuse-shared-errors.es.js | 4.6 kB · brotli 1.6 kB |
|
|
172
|
+
| src → index.ts | `██░░░░░░░░░░░░░░░░░░` 12.2% |
|
|
173
|
+
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 1.4% |
|
|
199
174
|
| dist/dpuse-shared-componentModuleConnector.es.js | 3.6 kB · brotli 1.2 kB |
|
|
200
|
-
| src | `██░░░░░░░░░░░░░░░░░░` 8.
|
|
201
|
-
| index.ts | `█░░░░░░░░░░░░░░░░░░░` 6.
|
|
202
|
-
| connectorConfig.schema.ts | `░░░░░░░░░░░░░░░░░░░░` 2.
|
|
203
|
-
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 2.
|
|
204
|
-
| dist/dpuse-shared-errors.es.js | 3.5 kB · brotli 1.1 kB |
|
|
205
|
-
| src → index.ts | `██░░░░░░░░░░░░░░░░░░` 9.4% |
|
|
206
|
-
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 1.3% |
|
|
175
|
+
| src | `██░░░░░░░░░░░░░░░░░░` 8.3% |
|
|
176
|
+
| index.ts | `█░░░░░░░░░░░░░░░░░░░` 6.0% |
|
|
177
|
+
| connectorConfig.schema.ts | `░░░░░░░░░░░░░░░░░░░░` 2.3% |
|
|
178
|
+
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 2.2% |
|
|
207
179
|
| dist/dpuse-shared-utilities.es.js | 3.5 kB · brotli 1.1 kB |
|
|
208
|
-
| src → index.ts | `██░░░░░░░░░░░░░░░░░░` 9
|
|
180
|
+
| src → index.ts | `██░░░░░░░░░░░░░░░░░░` 8.9% |
|
|
209
181
|
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 1.4% |
|
|
210
182
|
| dist/dpuse-shared-locale.es.js | 856 B · brotli 330 B |
|
|
211
183
|
| src → index.ts | `░░░░░░░░░░░░░░░░░░░░` 1.6% |
|
|
212
184
|
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 0.9% |
|
|
213
185
|
| dist/dpuse-shared-component.es.js | 834 B · brotli 363 B |
|
|
214
|
-
| src → index.ts | `░░░░░░░░░░░░░░░░░░░░` 1.
|
|
186
|
+
| src → index.ts | `░░░░░░░░░░░░░░░░░░░░` 1.5% |
|
|
215
187
|
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 0.9% |
|
|
216
188
|
| dist/dpuse-shared-componentModuleTool.es.js | 784 B · brotli 398 B |
|
|
217
189
|
| src → index.ts | `░░░░░░░░░░░░░░░░░░░░` 1.7% |
|
|
218
190
|
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 0.6% |
|
|
219
191
|
| dist/dpuse-shared-componentDataView.es.js | 701 B · brotli 297 B |
|
|
220
192
|
| src → index.ts | `░░░░░░░░░░░░░░░░░░░░` 1.6% |
|
|
221
|
-
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 0.
|
|
193
|
+
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 0.4% |
|
|
222
194
|
| dist/dpuse-shared-componentModulePresenter.es.js | 411 B · brotli 225 B |
|
|
223
195
|
| (unassigned) → [unassigned] | `░░░░░░░░░░░░░░░░░░░░` 0.8% |
|
|
224
196
|
| src → presenterConfig.schema.ts | `░░░░░░░░░░░░░░░░░░░░` 0.4% |
|
|
@@ -1,49 +1,55 @@
|
|
|
1
1
|
//#region src/errors/index.ts
|
|
2
|
-
var e = 2048, t =
|
|
2
|
+
var e = 2048, t = "[REDACTED]", n = /api[-_]?key|authori[sz]ation|cookie|credential|passw(?:or)?d|private[-_]?key|secret|token/i, r = [
|
|
3
|
+
[/\b(Bearer|Basic) +[\w.~+/=-]+/gi, (e, n) => `${n} ${t}`],
|
|
4
|
+
[/(?<![\w-])([\w-]+)(["']?[ \t]*[:=][ \t]*["']?)([^\s"'&,;}?#]+)/g, (e, r, i, a) => n.test(r) && !/^(?:Basic|Bearer)$/i.test(a) ? `${r}${i}${t}` : e],
|
|
5
|
+
[/\beyJ[\w-]+\.[\w-]+\.[\w-]*/g, () => t],
|
|
6
|
+
[/\b(?:sk-|xaat-|xapt-|sl\.)[\w-]{16,}/g, () => t],
|
|
7
|
+
[/(?<![\w.+-])[\w.+-]+@[\w-]+\.[\w.-]+/g, () => t]
|
|
8
|
+
], i = class extends Error {
|
|
3
9
|
data;
|
|
4
10
|
locator;
|
|
5
11
|
constructor(e, t, n, r) {
|
|
6
12
|
super(e, r), this.name = "DPUseError", this.data = n, this.locator = t;
|
|
7
13
|
}
|
|
8
|
-
},
|
|
14
|
+
}, a = class extends i {
|
|
9
15
|
constructor(e, t, n, r) {
|
|
10
16
|
super(e, t, n, r), this.name = "AppError";
|
|
11
17
|
}
|
|
12
|
-
},
|
|
18
|
+
}, o = class extends i {
|
|
13
19
|
constructor(e, t, n, r) {
|
|
14
20
|
super(e, t, n, r), this.name = "APIError";
|
|
15
21
|
}
|
|
16
|
-
},
|
|
22
|
+
}, s = class extends i {
|
|
17
23
|
constructor(e, t, n, r) {
|
|
18
24
|
super(e, t, n, r), this.name = "EngineError";
|
|
19
25
|
}
|
|
20
|
-
},
|
|
26
|
+
}, c = class extends i {
|
|
21
27
|
constructor(e, t, n, r) {
|
|
22
28
|
super(e, t, n, r), this.name = "ConnectorError";
|
|
23
29
|
}
|
|
24
|
-
},
|
|
30
|
+
}, l = class extends i {
|
|
25
31
|
constructor(e, t, n, r) {
|
|
26
32
|
super(e, t, n, r), this.name = "FetchError";
|
|
27
33
|
}
|
|
28
34
|
};
|
|
29
|
-
async function
|
|
35
|
+
async function u(e, t, n) {
|
|
30
36
|
let r = ` - ${e.statusText}`, i = `${t} Response status '${String(e.status)}${e.statusText ? r : ""}' received.`, a;
|
|
31
37
|
try {
|
|
32
38
|
a = await e.text();
|
|
33
39
|
} catch (e) {
|
|
34
|
-
a = `<body unavailable: ${
|
|
40
|
+
a = `<body unavailable: ${p(e).message}>`;
|
|
35
41
|
}
|
|
36
|
-
return new
|
|
42
|
+
return new l(i, n, { body: x(a) });
|
|
37
43
|
}
|
|
38
|
-
function
|
|
44
|
+
function d(e) {
|
|
39
45
|
return e.map((e) => e.message).join(" ");
|
|
40
46
|
}
|
|
41
|
-
function
|
|
47
|
+
function f(e) {
|
|
42
48
|
try {
|
|
43
49
|
e();
|
|
44
50
|
} catch {}
|
|
45
51
|
}
|
|
46
|
-
function
|
|
52
|
+
function p(e) {
|
|
47
53
|
if (e instanceof Error) return e;
|
|
48
54
|
if (typeof e == "string") return Error(e);
|
|
49
55
|
if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint") return Error(String(e));
|
|
@@ -55,24 +61,24 @@ function u(e) {
|
|
|
55
61
|
}
|
|
56
62
|
return /* @__PURE__ */ Error("Unknown error");
|
|
57
63
|
}
|
|
58
|
-
function
|
|
59
|
-
let t = /* @__PURE__ */ new Set(), n = [], r =
|
|
64
|
+
function m(e) {
|
|
65
|
+
let t = /* @__PURE__ */ new Set(), n = [], r = p(e);
|
|
60
66
|
for (; r != null && !t.has(r);) {
|
|
61
67
|
t.add(r);
|
|
62
|
-
let [e, i] =
|
|
63
|
-
/(?:\.{3}|[.!?])$/.test(e.message) || (e.message += "."), n.push(e), r = i;
|
|
68
|
+
let [e, i] = S(r);
|
|
69
|
+
/(?:\.{3}|[.!?])$/.test(e.message) || (e.message += "."), n.push(v(e)), r = i;
|
|
64
70
|
}
|
|
65
71
|
return n;
|
|
66
72
|
}
|
|
67
|
-
function
|
|
73
|
+
function h(e) {
|
|
68
74
|
let t;
|
|
69
75
|
for (let n of e.toReversed()) {
|
|
70
|
-
let e =
|
|
76
|
+
let e = _(n, t);
|
|
71
77
|
n.stack !== void 0 && (e.stack = n.stack), t = e;
|
|
72
78
|
}
|
|
73
79
|
return t ?? /* @__PURE__ */ Error("No error to unserialise.");
|
|
74
80
|
}
|
|
75
|
-
function
|
|
81
|
+
function g(e) {
|
|
76
82
|
let t;
|
|
77
83
|
try {
|
|
78
84
|
t = JSON.stringify(e);
|
|
@@ -81,13 +87,13 @@ function p(e) {
|
|
|
81
87
|
}
|
|
82
88
|
return t === "" && (t = "Unknown error"), t;
|
|
83
89
|
}
|
|
84
|
-
function
|
|
90
|
+
function _(e, t) {
|
|
85
91
|
switch (e.name) {
|
|
86
|
-
case "APIError": return new
|
|
87
|
-
case "AppError": return new
|
|
88
|
-
case "ConnectorError": return new
|
|
89
|
-
case "EngineError": return new
|
|
90
|
-
case "FetchError": return new
|
|
92
|
+
case "APIError": return new o(e.message, e.locator, e.data, { cause: t });
|
|
93
|
+
case "AppError": return new a(e.message, e.locator, e.data, { cause: t });
|
|
94
|
+
case "ConnectorError": return new c(e.message, e.locator, e.data, { cause: t });
|
|
95
|
+
case "EngineError": return new s(e.message, e.locator, e.data, { cause: t });
|
|
96
|
+
case "FetchError": return new l(e.message, e.locator, e.data, { cause: t });
|
|
91
97
|
default: {
|
|
92
98
|
let n = e.name;
|
|
93
99
|
return new class extends Error {
|
|
@@ -96,32 +102,49 @@ function m(e, t) {
|
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
|
-
function
|
|
105
|
+
function v(e) {
|
|
106
|
+
let { data: t, message: n, stack: r } = e;
|
|
107
|
+
return {
|
|
108
|
+
...e,
|
|
109
|
+
data: t === void 0 ? void 0 : b(t, /* @__PURE__ */ new WeakSet(), 0),
|
|
110
|
+
message: y(n),
|
|
111
|
+
stack: r === void 0 ? void 0 : y(r)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function y(e) {
|
|
115
|
+
let t = e;
|
|
116
|
+
for (let [e, n] of r) t = t.replaceAll(e, (e, ...t) => n(e, ...t));
|
|
117
|
+
return t;
|
|
118
|
+
}
|
|
119
|
+
function b(e, r, i) {
|
|
120
|
+
return typeof e == "string" ? y(e) : typeof e != "object" || !e ? e : i >= 10 ? t : r.has(e) ? "[Circular]" : (r.add(e), Array.isArray(e) ? e.map((e) => b(e, r, i + 1)) : Object.fromEntries(Object.entries(e).map(([e, a]) => [e, a != null && n.test(e) ? t : b(a, r, i + 1)])));
|
|
121
|
+
}
|
|
122
|
+
function x(t) {
|
|
100
123
|
if (t != null && t !== "") return t.length > e ? `${t.slice(0, e)}... [truncated]` : t;
|
|
101
124
|
}
|
|
102
|
-
function
|
|
103
|
-
let
|
|
104
|
-
if (e instanceof
|
|
125
|
+
function S(e) {
|
|
126
|
+
let t = e.cause == null ? null : p(e.cause);
|
|
127
|
+
if (e instanceof i) return [{
|
|
105
128
|
data: e.data,
|
|
106
129
|
locator: e.locator,
|
|
107
130
|
message: e.message,
|
|
108
131
|
name: e.name,
|
|
109
132
|
stack: e.stack
|
|
110
|
-
},
|
|
111
|
-
let
|
|
133
|
+
}, t];
|
|
134
|
+
let n = Object.fromEntries(Object.entries(e).filter(([e]) => e !== "cause"));
|
|
112
135
|
return e.name ? [{
|
|
113
|
-
data:
|
|
136
|
+
data: n,
|
|
114
137
|
locator: "",
|
|
115
138
|
message: e.message,
|
|
116
139
|
name: e.name,
|
|
117
140
|
stack: e.stack
|
|
118
|
-
},
|
|
119
|
-
data:
|
|
141
|
+
}, t] : [{
|
|
142
|
+
data: n,
|
|
120
143
|
locator: "",
|
|
121
|
-
message:
|
|
144
|
+
message: g(e),
|
|
122
145
|
name: "Error",
|
|
123
146
|
stack: void 0
|
|
124
147
|
}, null];
|
|
125
148
|
}
|
|
126
149
|
//#endregion
|
|
127
|
-
export {
|
|
150
|
+
export { o as APIError, a as AppError, c as ConnectorError, i as DPUseError, s as EngineError, l as FetchError, u as buildFetchError, d as concatenateSerialisedErrorMessages, f as ignoreErrors, p as normalizeToError, m as serialiseError, h as unserialiseError };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dpuse-shared-errors.es.js","names":[],"sources":["../src/errors/index.ts"],"sourcesContent":["// ── Types ────────────────────────────────────────────────────────────────────────────────────────────────────────────\n\n// Serializable representation of an error; used for transporting errors across api and worker boundaries\nexport interface SerialisedError {\n data: Record<string, unknown> | undefined;\n locator: string; // Error locator 'package.module.method'\n message: string; // Human-readable error message\n name: string; // Error class or type name\n stack: string | undefined; // Stack trace if available\n}\n\n// ── Constants ───────────────────────────────────────────────────────────────────────────────────────────────────────\n\nconst RESPONSE_ERROR_BODY_LIMIT = 2048;\n\n// ── Errors ───────────────────────────────────────────────────────────────────────────────────────────────────────────\n\n// Base class for all DPUse errors; includes a locator for the error; never thrown directly\nexport class DPUseError extends Error {\n readonly data: Record<string, unknown> | undefined;\n readonly locator: string; // Error locator 'package.module.method'\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, options);\n this.name = 'DPUseError';\n this.data = data;\n this.locator = locator;\n }\n}\n\n// Thrown when an app (studio/assistant) error occurs\nexport class AppError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'AppError';\n }\n}\n\n// Thrown when an API request fails\nexport class APIError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'APIError';\n }\n}\n\n// Thrown when an engine request fails\nexport class EngineError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'EngineError';\n }\n}\n\n// Thrown when an connector operation fails; will always be wrapped in an engine error\nexport class ConnectorError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'ConnectorError';\n }\n}\n\n// Thrown when an HTTP request fails; may include a sanitized portion of the response body for diagnostic purposes\nexport class FetchError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'FetchError';\n }\n}\n\n// ── Actions ──────────────────────────────────────────────────────────────────────────────────────────────────────────\n\n// Builds a fetch error from an HTTP response; includes a text copy of the response body\nexport async function buildFetchError(response: { status: number; statusText: string; text: () => Promise<string> }, message: string, locator: string): Promise<FetchError> {\n const responseStatusStuff = ` - ${response.statusText}`;\n const fetchMessage = `${message} Response status '${String(response.status)}${response.statusText ? responseStatusStuff : ''}' received.`;\n let bodyText: string;\n try {\n bodyText = await response.text();\n } catch (error) {\n const normalised = normalizeToError(error);\n bodyText = `<body unavailable: ${normalised.message}>`;\n }\n return new FetchError(fetchMessage, locator, { body: sanitizeResponseErrorBody(bodyText) });\n}\n\n// Concatenates serialized error messages into a single string\nexport function concatenateSerialisedErrorMessages(serialisedErrors: SerialisedError[]): string {\n return serialisedErrors.map((serialisedError) => serialisedError.message).join(' ');\n}\n\n// Ignore best-effort cleanup errors to keep teardown noise-free\nexport function ignoreErrors(action: () => void): void {\n try {\n action();\n } catch {\n // Intentionally ignore errors\n }\n}\n\n// Normalizes an unknown thrown value into an error\nexport function normalizeToError(value: unknown): Error {\n if (value instanceof Error) return value;\n if (typeof value === 'string') return new Error(value);\n if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') return new Error(String(value));\n if (typeof value === 'symbol') return new Error(value.description ?? 'Unknown error');\n if (typeof value === 'object') {\n try {\n return new Error(JSON.stringify(value));\n } catch {\n return new Error('Unknown error');\n }\n }\n return new Error('Unknown error');\n}\n\n// Serializes an error and its cause chain into a array of serialised error objects;\n// errors are ordered from outermost to root cause;\n// cycles in the cause chain are safely ignored;\n// messages are normalized to end with punctuation\nexport function serialiseError(error?: unknown): SerialisedError[] {\n const seenCauses = new Set();\n const serialisedErrors: SerialisedError[] = [];\n let cause: Error | null = normalizeToError(error);\n while (cause != null && !seenCauses.has(cause)) {\n seenCauses.add(cause);\n const [serialisedError, nextCause] = serialiseSingleError(cause);\n if (!/(?:\\.{3}|[.!?])$/.test(serialisedError.message)) serialisedError.message += '.';\n serialisedErrors.push(serialisedError);\n cause = nextCause;\n }\n return serialisedErrors;\n}\n\n// Unserialises an array of serialised error objects back into an error with a cause chain;\n// reconstructs the appropriate error class based on serialized properties;\n// chains errors from outermost to root cause using the `cause` option;\n// returns a placeholder error if the input array is empty\nexport function unserialiseError(serialisedErrors: SerialisedError[]): Error {\n // Build the error chain from root cause (end) to outermost (start)\n let rebuiltError: Error | undefined;\n for (const serialised of serialisedErrors.toReversed()) {\n const error = reconstructError(serialised, rebuiltError);\n if (serialised.stack !== undefined) error.stack = serialised.stack; // Restore stack trace if available\n rebuiltError = error;\n }\n return rebuiltError ?? new Error('No error to unserialise.');\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────────────────────────────────────────────────\n\n// Builds a fallback message for non-error throwables\nfunction buildFallbackMessage(cause: unknown): string {\n let fallbackMessage: string;\n try {\n fallbackMessage = JSON.stringify(cause);\n } catch {\n if (typeof cause === 'symbol') fallbackMessage = cause.description ?? 'Unknown error';\n else if (typeof cause === 'bigint') fallbackMessage = cause.toString();\n else fallbackMessage = 'Unknown error';\n }\n if (fallbackMessage === '') fallbackMessage = 'Unknown error';\n return fallbackMessage;\n}\n\nfunction reconstructError(serialised: SerialisedError, cause: Error | undefined): Error {\n switch (serialised.name) {\n case 'APIError':\n return new APIError(serialised.message, serialised.locator, serialised.data, { cause });\n case 'AppError':\n return new AppError(serialised.message, serialised.locator, serialised.data, { cause });\n case 'ConnectorError':\n return new ConnectorError(serialised.message, serialised.locator, serialised.data, { cause });\n case 'EngineError':\n return new EngineError(serialised.message, serialised.locator, serialised.data, { cause });\n case 'FetchError':\n return new FetchError(serialised.message, serialised.locator, serialised.data, { cause });\n default: {\n const name = serialised.name;\n return new (class extends Error {\n override name = name;\n })(serialised.message, { cause });\n }\n }\n}\n\n// Sanitizes a response body; limits body size to avoid excessive payloads when logging\nfunction sanitizeResponseErrorBody(body?: string): string | undefined {\n if (body == null || body === '') return undefined;\n return body.length > RESPONSE_ERROR_BODY_LIMIT ? `${body.slice(0, RESPONSE_ERROR_BODY_LIMIT)}... [truncated]` : body;\n}\n\nfunction serialiseSingleError(cause: Error): [SerialisedError, Error | null] {\n const nextCause = cause.cause == null ? null : normalizeToError(cause.cause);\n if (cause instanceof DPUseError) {\n return [{ data: cause.data, locator: cause.locator, message: cause.message, name: cause.name, stack: cause.stack }, nextCause];\n }\n const customProperties = Object.fromEntries(Object.entries(cause).filter(([k]) => k !== 'cause'));\n return cause.name\n ? [{ data: customProperties, locator: '', message: cause.message, name: cause.name, stack: cause.stack }, nextCause]\n : [{ data: customProperties, locator: '', message: buildFallbackMessage(cause), name: 'Error', stack: undefined }, null];\n}\n"],"mappings":";AAaA,IAAM,IAA4B,MAKrB,IAAb,cAAgC,MAAM;CAClC;CACA;CACA,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAIlG,AAHA,MAAM,GAAS,CAAO,GACtB,KAAK,OAAO,cACZ,KAAK,OAAO,GACZ,KAAK,UAAU;CACnB;AACJ,GAGa,IAAb,cAA8B,EAAW;CACrC,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAElG,AADA,MAAM,GAAS,GAAS,GAAM,CAAO,GACrC,KAAK,OAAO;CAChB;AACJ,GAGa,IAAb,cAA8B,EAAW;CACrC,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAElG,AADA,MAAM,GAAS,GAAS,GAAM,CAAO,GACrC,KAAK,OAAO;CAChB;AACJ,GAGa,IAAb,cAAiC,EAAW;CACxC,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAElG,AADA,MAAM,GAAS,GAAS,GAAM,CAAO,GACrC,KAAK,OAAO;CAChB;AACJ,GAGa,IAAb,cAAoC,EAAW;CAC3C,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAElG,AADA,MAAM,GAAS,GAAS,GAAM,CAAO,GACrC,KAAK,OAAO;CAChB;AACJ,GAGa,IAAb,cAAgC,EAAW;CACvC,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAElG,AADA,MAAM,GAAS,GAAS,GAAM,CAAO,GACrC,KAAK,O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AACJ;AAGA,SAAS,EAA0B,GAAmC;CAClE,IAAI,KAAQ,QAAQ,MAAS,IAC7B,OAAO,EAAK,SAAS,IAA4B,GAAG,EAAK,MAAM,GAAG,CAAyB,EAAE,mBAAmB;AACpH;AAEA,SAAS,EAAqB,GAA+C;CACzE,IAAM,IAAY,EAAM,SAAS,OAAO,OAAO,EAAiB,EAAM,KAAK;CAC3E,IAAI,aAAiB,GACjB,OAAO,CAAC;EAAE,MAAM,EAAM;EAAM,SAAS,EAAM;EAAS,SAAS,EAAM;EAAS,MAAM,EAAM;EAAM,OAAO,EAAM;CAAM,GAAG,CAAS;CAEjI,IAAM,IAAmB,OAAO,YAAY,OAAO,QAAQ,CAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,MAAM,OAAO,CAAC;CAChG,OAAO,EAAM,OACP,CAAC;EAAE,MAAM;EAAkB,SAAS;EAAI,SAAS,EAAM;EAAS,MAAM,EAAM;EAAM,OAAO,EAAM;CAAM,GAAG,CAAS,IACjH,CAAC;EAAE,MAAM;EAAkB,SAAS;EAAI,SAAS,EAAqB,CAAK;EAAG,MAAM;EAAS,OAAO,KAAA;CAAU,GAAG,IAAI;AAC/H"}
|
|
1
|
+
{"version":3,"file":"dpuse-shared-errors.es.js","names":[],"sources":["../src/errors/index.ts"],"sourcesContent":["// ── Types ────────────────────────────────────────────────────────────────────────────────────────────────────────────\n\n// Serializable representation of an error; used for transporting errors across api and worker boundaries\nexport interface SerialisedError {\n data: Record<string, unknown> | undefined;\n locator: string; // Error locator 'package.module.method'\n message: string; // Human-readable error message\n name: string; // Error class or type name\n stack: string | undefined; // Stack trace if available\n}\n\n// ── Constants ───────────────────────────────────────────────────────────────────────────────────────────────────────\n\nconst RESPONSE_ERROR_BODY_LIMIT = 2048;\n\n// Redaction — serialised errors are shown in the browser and stored in Axiom, so secrets and email addresses are masked\n// first. Best effort: it catches the common shapes, not every possible secret.\nconst REDACTED = '[REDACTED]';\nconst REDACTION_MAX_DEPTH = 10; // Deeper 'data' is replaced whole rather than walked.\nconst SECRET_KEY_PATTERN = /api[-_]?key|authori[sz]ation|cookie|credential|passw(?:or)?d|private[-_]?key|secret|token/i; // A 'data' field whose name matches has its whole value masked.\n// Each pattern is anchored to the start of a word, so it runs in linear time even over a long response body.\nconst SECRET_TEXT_PATTERNS: [RegExp, (match: string, ...groups: string[]) => string][] = [\n [/\\b(Bearer|Basic) +[\\w.~+/=-]+/gi, (_match, scheme) => `${scheme} ${REDACTED}`], // Authorisation header values.\n // Any 'name: value' or 'name=value' pair, in JSON, query strings, form bodies or headers; masked when the name looks\n // secret. A bare 'Basic' or 'Bearer' value is the scheme left by the pattern above, whose token is already masked.\n [\n /(?<![\\w-])([\\w-]+)([\"']?[ \\t]*[:=][ \\t]*[\"']?)([^\\s\"'&,;}?#]+)/g,\n (match, name, separator, value) => (SECRET_KEY_PATTERN.test(name) && !/^(?:Basic|Bearer)$/i.test(value) ? `${name}${separator}${REDACTED}` : match)\n ],\n [/\\beyJ[\\w-]+\\.[\\w-]+\\.[\\w-]*/g, () => REDACTED], // JSON web tokens.\n [/\\b(?:sk-|xaat-|xapt-|sl\\.)[\\w-]{16,}/g, () => REDACTED], // Known token prefixes: OpenAI, Anthropic, Axiom, Dropbox.\n [/(?<![\\w.+-])[\\w.+-]+@[\\w-]+\\.[\\w.-]+/g, () => REDACTED] // Email addresses.\n];\n\n// ── Errors ───────────────────────────────────────────────────────────────────────────────────────────────────────────\n\n// Base class for all DPUse errors; includes a locator for the error; never thrown directly\nexport class DPUseError extends Error {\n readonly data: Record<string, unknown> | undefined;\n readonly locator: string; // Error locator 'package.module.method'\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, options);\n this.name = 'DPUseError';\n this.data = data;\n this.locator = locator;\n }\n}\n\n// Thrown when an app (studio/assistant) error occurs\nexport class AppError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'AppError';\n }\n}\n\n// Thrown when an API request fails\nexport class APIError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'APIError';\n }\n}\n\n// Thrown when an engine request fails\nexport class EngineError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'EngineError';\n }\n}\n\n// Thrown when an connector operation fails; will always be wrapped in an engine error\nexport class ConnectorError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'ConnectorError';\n }\n}\n\n// Thrown when an HTTP request fails; may include a sanitized portion of the response body for diagnostic purposes\nexport class FetchError extends DPUseError {\n constructor(message: string, locator: string, data?: Record<string, unknown>, options?: ErrorOptions) {\n super(message, locator, data, options);\n this.name = 'FetchError';\n }\n}\n\n// ── Actions ──────────────────────────────────────────────────────────────────────────────────────────────────────────\n\n// Builds a fetch error from an HTTP response; includes a text copy of the response body\nexport async function buildFetchError(response: { status: number; statusText: string; text: () => Promise<string> }, message: string, locator: string): Promise<FetchError> {\n const responseStatusStuff = ` - ${response.statusText}`;\n const fetchMessage = `${message} Response status '${String(response.status)}${response.statusText ? responseStatusStuff : ''}' received.`;\n let bodyText: string;\n try {\n bodyText = await response.text();\n } catch (error) {\n const normalised = normalizeToError(error);\n bodyText = `<body unavailable: ${normalised.message}>`;\n }\n return new FetchError(fetchMessage, locator, { body: sanitizeResponseErrorBody(bodyText) });\n}\n\n// Concatenates serialized error messages into a single string\nexport function concatenateSerialisedErrorMessages(serialisedErrors: SerialisedError[]): string {\n return serialisedErrors.map((serialisedError) => serialisedError.message).join(' ');\n}\n\n// Ignore best-effort cleanup errors to keep teardown noise-free\nexport function ignoreErrors(action: () => void): void {\n try {\n action();\n } catch {\n // Intentionally ignore errors\n }\n}\n\n// Normalizes an unknown thrown value into an error\nexport function normalizeToError(value: unknown): Error {\n if (value instanceof Error) return value;\n if (typeof value === 'string') return new Error(value);\n if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') return new Error(String(value));\n if (typeof value === 'symbol') return new Error(value.description ?? 'Unknown error');\n if (typeof value === 'object') {\n try {\n return new Error(JSON.stringify(value));\n } catch {\n return new Error('Unknown error');\n }\n }\n return new Error('Unknown error');\n}\n\n// Serializes an error and its cause chain into a array of serialised error objects;\n// errors are ordered from outermost to root cause;\n// cycles in the cause chain are safely ignored;\n// messages are normalized to end with punctuation;\n// secrets and email addresses in messages, stacks and data are redacted\nexport function serialiseError(error?: unknown): SerialisedError[] {\n const seenCauses = new Set();\n const serialisedErrors: SerialisedError[] = [];\n let cause: Error | null = normalizeToError(error);\n while (cause != null && !seenCauses.has(cause)) {\n seenCauses.add(cause);\n const [serialisedError, nextCause] = serialiseSingleError(cause);\n if (!/(?:\\.{3}|[.!?])$/.test(serialisedError.message)) serialisedError.message += '.';\n serialisedErrors.push(redactSerialisedError(serialisedError));\n cause = nextCause;\n }\n return serialisedErrors;\n}\n\n// Unserialises an array of serialised error objects back into an error with a cause chain;\n// reconstructs the appropriate error class based on serialized properties;\n// chains errors from outermost to root cause using the `cause` option;\n// returns a placeholder error if the input array is empty\nexport function unserialiseError(serialisedErrors: SerialisedError[]): Error {\n // Build the error chain from root cause (end) to outermost (start)\n let rebuiltError: Error | undefined;\n for (const serialised of serialisedErrors.toReversed()) {\n const error = reconstructError(serialised, rebuiltError);\n if (serialised.stack !== undefined) error.stack = serialised.stack; // Restore stack trace if available\n rebuiltError = error;\n }\n return rebuiltError ?? new Error('No error to unserialise.');\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────────────────────────────────────────────────\n\n// Builds a fallback message for non-error throwables\nfunction buildFallbackMessage(cause: unknown): string {\n let fallbackMessage: string;\n try {\n fallbackMessage = JSON.stringify(cause);\n } catch {\n if (typeof cause === 'symbol') fallbackMessage = cause.description ?? 'Unknown error';\n else if (typeof cause === 'bigint') fallbackMessage = cause.toString();\n else fallbackMessage = 'Unknown error';\n }\n if (fallbackMessage === '') fallbackMessage = 'Unknown error';\n return fallbackMessage;\n}\n\nfunction reconstructError(serialised: SerialisedError, cause: Error | undefined): Error {\n switch (serialised.name) {\n case 'APIError':\n return new APIError(serialised.message, serialised.locator, serialised.data, { cause });\n case 'AppError':\n return new AppError(serialised.message, serialised.locator, serialised.data, { cause });\n case 'ConnectorError':\n return new ConnectorError(serialised.message, serialised.locator, serialised.data, { cause });\n case 'EngineError':\n return new EngineError(serialised.message, serialised.locator, serialised.data, { cause });\n case 'FetchError':\n return new FetchError(serialised.message, serialised.locator, serialised.data, { cause });\n default: {\n const name = serialised.name;\n return new (class extends Error {\n override name = name;\n })(serialised.message, { cause });\n }\n }\n}\n\nfunction redactSerialisedError(serialisedError: SerialisedError): SerialisedError {\n const { data, message, stack } = serialisedError;\n return {\n ...serialisedError,\n data: data === undefined ? undefined : (redactValue(data, new WeakSet(), 0) as Record<string, unknown>),\n message: redactText(message),\n stack: stack === undefined ? undefined : redactText(stack)\n };\n}\n\nfunction redactText(text: string): string {\n let redactedText = text;\n for (const [pattern, replacement] of SECRET_TEXT_PATTERNS)\n redactedText = redactedText.replaceAll(pattern, (match: string, ...groups: string[]) => replacement(match, ...groups));\n return redactedText;\n}\n\n// Walks 'data', masking any field whose name looks secret and any secret found in text.\nfunction redactValue(value: unknown, seen: WeakSet<object>, depth: number): unknown {\n if (typeof value === 'string') return redactText(value);\n if (typeof value !== 'object' || value === null) return value;\n if (depth >= REDACTION_MAX_DEPTH) return REDACTED;\n if (seen.has(value)) return '[Circular]';\n seen.add(value);\n return Array.isArray(value)\n ? value.map((item) => redactValue(item, seen, depth + 1))\n : Object.fromEntries(\n Object.entries(value).map(([key, entryValue]) => [key, entryValue != null && SECRET_KEY_PATTERN.test(key) ? REDACTED : redactValue(entryValue, seen, depth + 1)])\n );\n}\n\n// Sanitizes a response body; limits body size to avoid excessive payloads when logging\nfunction sanitizeResponseErrorBody(body?: string): string | undefined {\n if (body == null || body === '') return undefined;\n return body.length > RESPONSE_ERROR_BODY_LIMIT ? `${body.slice(0, RESPONSE_ERROR_BODY_LIMIT)}... [truncated]` : body;\n}\n\nfunction serialiseSingleError(cause: Error): [SerialisedError, Error | null] {\n const nextCause = cause.cause == null ? null : normalizeToError(cause.cause);\n if (cause instanceof DPUseError) {\n return [{ data: cause.data, locator: cause.locator, message: cause.message, name: cause.name, stack: cause.stack }, nextCause];\n }\n const customProperties = Object.fromEntries(Object.entries(cause).filter(([k]) => k !== 'cause'));\n return cause.name\n ? [{ data: customProperties, locator: '', message: cause.message, name: cause.name, stack: cause.stack }, nextCause]\n : [{ data: customProperties, locator: '', message: buildFallbackMessage(cause), name: 'Error', stack: undefined }, null];\n}\n"],"mappings":";AAaA,IAAM,IAA4B,MAI5B,IAAW,cAEX,IAAqB,8FAErB,IAAmF;CACrF,CAAC,oCAAoC,GAAQ,MAAW,GAAG,EAAO,GAAG,GAAU;CAG/E,CACI,oEACC,GAAO,GAAM,GAAW,MAAW,EAAmB,KAAK,CAAI,KAAK,CAAC,sBAAsB,KAAK,CAAK,IAAI,GAAG,IAAO,IAAY,MAAa,CACjJ;CACA,CAAC,sCAAsC,CAAQ;CAC/C,CAAC,+CAA+C,CAAQ;CACxD,CAAC,+CAA+C,CAAQ;AAC5D,GAKa,IAAb,cAAgC,MAAM;CAClC;CACA;CACA,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAIlG,AAHA,MAAM,GAAS,CAAO,GACtB,KAAK,OAAO,cACZ,KAAK,OAAO,GACZ,KAAK,UAAU;CACnB;AACJ,GAGa,IAAb,cAA8B,EAAW;CACrC,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAElG,AADA,MAAM,GAAS,GAAS,GAAM,CAAO,GACrC,KAAK,OAAO;CAChB;AACJ,GAGa,IAAb,cAA8B,EAAW;CACrC,YAAY,GAAiB,GAAiB,GAAgC,GAAwB;EAElG,AADA,MAAM,GAAS,GAAS,GAAM,CAAO,GACrC,KAAK,OAA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c,QAAQ,EAAmB,KAAK,CAAG,IAAI,IAAW,EAAY,GAAY,GAAM,IAAQ,CAAC,CAAC,CAAC,CACpK;AACV;AAGA,SAAS,EAA0B,GAAmC;CAClE,IAAI,KAAQ,QAAQ,MAAS,IAC7B,OAAO,EAAK,SAAS,IAA4B,GAAG,EAAK,MAAM,GAAG,CAAyB,EAAE,mBAAmB;AACpH;AAEA,SAAS,EAAqB,GAA+C;CACzE,IAAM,IAAY,EAAM,SAAS,OAAO,OAAO,EAAiB,EAAM,KAAK;CAC3E,IAAI,aAAiB,GACjB,OAAO,CAAC;EAAE,MAAM,EAAM;EAAM,SAAS,EAAM;EAAS,SAAS,EAAM;EAAS,MAAM,EAAM;EAAM,OAAO,EAAM;CAAM,GAAG,CAAS;CAEjI,IAAM,IAAmB,OAAO,YAAY,OAAO,QAAQ,CAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,MAAM,OAAO,CAAC;CAChG,OAAO,EAAM,OACP,CAAC;EAAE,MAAM;EAAkB,SAAS;EAAI,SAAS,EAAM;EAAS,MAAM,EAAM;EAAM,OAAO,EAAM;CAAM,GAAG,CAAS,IACjH,CAAC;EAAE,MAAM;EAAkB,SAAS;EAAI,SAAS,EAAqB,CAAK;EAAG,MAAM;EAAS,OAAO,KAAA;CAAU,GAAG,IAAI;AAC/H"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dpuse/dpuse-shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.830",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Common constants, types and utilities used across all DPUse projects.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -170,10 +170,10 @@
|
|
|
170
170
|
"valibot": "^1.5.0"
|
|
171
171
|
},
|
|
172
172
|
"devDependencies": {
|
|
173
|
-
"@dpuse/dpuse-development": "^0.3.
|
|
174
|
-
"@dpuse/eslint-config-dpuse": "^1.0.
|
|
173
|
+
"@dpuse/dpuse-development": "^0.3.723",
|
|
174
|
+
"@dpuse/eslint-config-dpuse": "^1.0.123",
|
|
175
175
|
"@types/node": "^26.6.2",
|
|
176
|
-
"@vitest/coverage-v8": "^5.0.
|
|
176
|
+
"@vitest/coverage-v8": "^5.0.2",
|
|
177
177
|
"eslint": "^10.11.0",
|
|
178
178
|
"fallow": "^3.28.0",
|
|
179
179
|
"prettier": "^3.9.9",
|
|
@@ -181,6 +181,6 @@
|
|
|
181
181
|
"typescript": "^6.0.3",
|
|
182
182
|
"vite": "^8.3.1",
|
|
183
183
|
"vite-plugin-dts": "^5.1.1",
|
|
184
|
-
"vitest": "^5.0.
|
|
184
|
+
"vitest": "^5.0.2"
|
|
185
185
|
}
|
|
186
186
|
}
|