@bywaretech/bysentinel-aws-lambda 0.1.0
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/LICENSE +202 -0
- package/README.md +184 -0
- package/dist/capture.d.ts +16 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +77 -0
- package/dist/capture.js.map +1 -0
- package/dist/context.d.ts +27 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +57 -0
- package/dist/context.js.map +1 -0
- package/dist/dedupe.d.ts +3 -0
- package/dist/dedupe.d.ts.map +1 -0
- package/dist/dedupe.js +25 -0
- package/dist/dedupe.js.map +1 -0
- package/dist/event.d.ts +21 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +72 -0
- package/dist/event.js.map +1 -0
- package/dist/git.d.ts +8 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +31 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +4 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +48 -0
- package/dist/options.js.map +1 -0
- package/dist/request.d.ts +12 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +67 -0
- package/dist/request.js.map +1 -0
- package/dist/runtime.d.ts +22 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +29 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scope.d.ts +14 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +9 -0
- package/dist/scope.js.map +1 -0
- package/dist/transport.d.ts +19 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +101 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/withBySentinel.d.ts +13 -0
- package/dist/withBySentinel.d.ts.map +1 -0
- package/dist/withBySentinel.js +78 -0
- package/dist/withBySentinel.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# @bywaretech/bysentinel-aws-lambda
|
|
2
|
+
|
|
3
|
+
BySentinel SDK for AWS Lambda handlers. Wraps your handler, captures sanitized
|
|
4
|
+
incident data on failure, and delivers it to a collector — without ever breaking
|
|
5
|
+
your function.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @bywaretech/bysentinel-aws-lambda
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## `withBySentinel(handler, options)`
|
|
14
|
+
|
|
15
|
+
Wraps a handler. On an unhandled exception it builds a **sanitized**
|
|
16
|
+
`BySentinelEvent`, delivers it (bounded, fail-silent), then **re-throws the
|
|
17
|
+
original error**. On success it only emits an event when a performance risk
|
|
18
|
+
(e.g. timeout) is detected.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { withBySentinel } from "@bywaretech/bysentinel-aws-lambda";
|
|
22
|
+
|
|
23
|
+
export const handler = withBySentinel(myHandler, {
|
|
24
|
+
project: "payments-api",
|
|
25
|
+
environment: "production",
|
|
26
|
+
collectorUrl: process.env.BYSENTINEL_COLLECTOR_URL,
|
|
27
|
+
apiKey: process.env.BYSENTINEL_API_KEY,
|
|
28
|
+
|
|
29
|
+
capture: {
|
|
30
|
+
requestBody: false, // default false (security-first)
|
|
31
|
+
headers: false, // default false
|
|
32
|
+
query: true,
|
|
33
|
+
stackTrace: true,
|
|
34
|
+
performance: true,
|
|
35
|
+
},
|
|
36
|
+
security: {
|
|
37
|
+
sanitize: true,
|
|
38
|
+
redactPII: true,
|
|
39
|
+
redactSecrets: true,
|
|
40
|
+
redactPaymentData: true,
|
|
41
|
+
strictMode: true, // forces requestBody/headers off no matter what
|
|
42
|
+
},
|
|
43
|
+
ai: {
|
|
44
|
+
enabled: true,
|
|
45
|
+
provider: "openrouter",
|
|
46
|
+
model: "deepseek/deepseek-chat",
|
|
47
|
+
sendBodyToAI: false,
|
|
48
|
+
sendHeadersToAI: false,
|
|
49
|
+
},
|
|
50
|
+
delivery: { mode: "background", timeoutMs: 2000, retries: 0, maxEventBytes: 262144 },
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`collectorUrl` is treated as a collector base URL and the SDK posts to
|
|
55
|
+
`/v1/events` by default. For raw webhook URLs such as webhook.site, use:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
delivery: {
|
|
59
|
+
endpointPath: "";
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Direct webhooks from the SDK
|
|
64
|
+
|
|
65
|
+
The recommended production flow is SDK -> BySentinel collector -> dashboard ->
|
|
66
|
+
signed outbound webhooks. If you also want the initial sanitized event delivered
|
|
67
|
+
directly from the Lambda, configure `delivery.webhooks`:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
export const handler = withBySentinel(myHandler, {
|
|
71
|
+
project: "payments-api",
|
|
72
|
+
environment: "production",
|
|
73
|
+
collectorUrl: process.env.BYSENTINEL_COLLECTOR_URL,
|
|
74
|
+
apiKey: process.env.BYSENTINEL_API_KEY,
|
|
75
|
+
delivery: {
|
|
76
|
+
timeoutMs: 5000,
|
|
77
|
+
webhooks: ["https://webhook.site/your-url"],
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This sends the same sanitized event to both:
|
|
83
|
+
|
|
84
|
+
```txt
|
|
85
|
+
<collectorUrl>/v1/events
|
|
86
|
+
https://webhook.site/your-url
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
For webhook-only usage, omit `collectorUrl` and keep `delivery.webhooks`.
|
|
90
|
+
Comma-separated URLs can also be set with `BYSENTINEL_DIRECT_WEBHOOK_URLS`.
|
|
91
|
+
|
|
92
|
+
## Manual capture
|
|
93
|
+
|
|
94
|
+
Inside a wrapped handler, manual capture inherits the active project /
|
|
95
|
+
environment / collector config automatically (via `AsyncLocalStorage`):
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { captureException, captureMessage } from "@bywaretech/bysentinel-aws-lambda";
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
await processPayment();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
await captureException(error, { feature: "payment-processing", step: "create-pix-charge" });
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
await captureMessage("Payment provider returned slow response", {
|
|
108
|
+
severity: "warning",
|
|
109
|
+
provider: "payment-api",
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Execution timeline
|
|
114
|
+
|
|
115
|
+
Record the flow of an invocation. Steps are auto-timed; on an unhandled error
|
|
116
|
+
the running step is marked `failed`, and a single **bottleneck** is computed.
|
|
117
|
+
Because each step carries an absolute timestamp, it also serves as the
|
|
118
|
+
chronological incident timeline.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { withBySentinel, BySentinel } from "@bywaretech/bysentinel-aws-lambda";
|
|
122
|
+
|
|
123
|
+
export const handler = withBySentinel(async (event) => {
|
|
124
|
+
const runtime = BySentinel.start(); // or: startRuntime()
|
|
125
|
+
|
|
126
|
+
runtime.step("Validate Request");
|
|
127
|
+
const body = validate(event);
|
|
128
|
+
|
|
129
|
+
runtime.step("Create Payment");
|
|
130
|
+
const payment = await createPayment(body);
|
|
131
|
+
|
|
132
|
+
runtime.step("Notify ERP").annotate({ endpoint: "erp.orders" });
|
|
133
|
+
await notifyErp(payment);
|
|
134
|
+
|
|
135
|
+
runtime.finish();
|
|
136
|
+
return { statusCode: 200, body: JSON.stringify(payment) };
|
|
137
|
+
}, options);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Inside a wrapped handler the timeline attaches to the active scope automatically,
|
|
141
|
+
so it is included in any captured event. Step `meta` is redacted before sending.
|
|
142
|
+
|
|
143
|
+
## Git / release correlation
|
|
144
|
+
|
|
145
|
+
Every event can carry `commitSha`, `branch`, `version`, `release`,
|
|
146
|
+
`buildTimestamp` and `repositoryUrl`. These are read from `git` in options, then
|
|
147
|
+
from `BYSENTINEL_*` env vars, then from common CI providers (GitHub Actions,
|
|
148
|
+
GitLab CI, Vercel):
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
BYSENTINEL_GIT_SHA=abc1234
|
|
152
|
+
BYSENTINEL_GIT_BRANCH=main
|
|
153
|
+
BYSENTINEL_VERSION=2.4.0
|
|
154
|
+
BYSENTINEL_RELEASE=release-42
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Deduplication
|
|
158
|
+
|
|
159
|
+
If you `captureException(err)` and then re-throw, the wrapper detects the error
|
|
160
|
+
was already reported and does **not** create a second incident — one failure,
|
|
161
|
+
one incident.
|
|
162
|
+
|
|
163
|
+
## What gets captured
|
|
164
|
+
|
|
165
|
+
- **Error**: type, message, stack (if `capture.stackTrace`)
|
|
166
|
+
- **Lambda context**: function name/version, request id, memory limit, remaining
|
|
167
|
+
time, **cold-start** flag
|
|
168
|
+
- **Performance**: duration, memory used, **timeout risk**
|
|
169
|
+
- **Request** (HTTP events, API Gateway v1/v2 + ALB): method, path, query, and —
|
|
170
|
+
only if explicitly enabled and not in strict mode — headers and body
|
|
171
|
+
- **Security signals**: SSRF-like URLs, SQL-error leakage, path traversal,
|
|
172
|
+
command injection, secrets in body/headers, scanner user-agents, admin-route
|
|
173
|
+
access
|
|
174
|
+
|
|
175
|
+
Everything is redacted by `@bywaretech/bysentinel-core` **before it leaves the process**.
|
|
176
|
+
See [docs/SECURITY.md](../../docs/SECURITY.md).
|
|
177
|
+
|
|
178
|
+
## Guarantees
|
|
179
|
+
|
|
180
|
+
- **Never breaks your Lambda.** A broken/unreachable collector is swallowed; your
|
|
181
|
+
business error always propagates unchanged.
|
|
182
|
+
- **Bounded delivery.** Sends are time-capped by `delivery.timeoutMs`.
|
|
183
|
+
- **Sanitized by default.** `event.sanitized` is always `true`; the collector
|
|
184
|
+
rejects unsanitized events.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CaptureContext } from "@bywaretech/bysentinel-core";
|
|
2
|
+
import type { BySentinelOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Manually capture an exception. Inside a `withBySentinel` handler the active
|
|
5
|
+
* project/environment/collector config is picked up automatically. Outside one,
|
|
6
|
+
* config falls back to environment variables (and `overrides` if provided).
|
|
7
|
+
*
|
|
8
|
+
* Never throws — capture failures are swallowed so business code is unaffected.
|
|
9
|
+
*/
|
|
10
|
+
export declare function captureException(error: unknown, context?: CaptureContext, overrides?: Partial<BySentinelOptions>): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Capture a standalone message/breadcrumb (no exception). Severity defaults to
|
|
13
|
+
* "info" and is stored in custom context.
|
|
14
|
+
*/
|
|
15
|
+
export declare function captureMessage(message: string, context?: CaptureContext, overrides?: Partial<BySentinelOptions>): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAMlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,cAAmB,EAC5B,SAAS,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACrC,OAAO,CAAC,IAAI,CAAC,CAmCf;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,cAAmB,EAC5B,SAAS,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACrC,OAAO,CAAC,IAAI,CAAC,CAyBf"}
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { markCaptured } from "./dedupe.js";
|
|
2
|
+
import { buildEvent } from "./event.js";
|
|
3
|
+
import { resolveOptions } from "./options.js";
|
|
4
|
+
import { currentScope } from "./scope.js";
|
|
5
|
+
import { deliver } from "./transport.js";
|
|
6
|
+
/**
|
|
7
|
+
* Manually capture an exception. Inside a `withBySentinel` handler the active
|
|
8
|
+
* project/environment/collector config is picked up automatically. Outside one,
|
|
9
|
+
* config falls back to environment variables (and `overrides` if provided).
|
|
10
|
+
*
|
|
11
|
+
* Never throws — capture failures are swallowed so business code is unaffected.
|
|
12
|
+
*/
|
|
13
|
+
export async function captureException(error, context = {}, overrides) {
|
|
14
|
+
try {
|
|
15
|
+
const scope = currentScope();
|
|
16
|
+
const options = scope?.options ??
|
|
17
|
+
resolveOptions({ project: "unknown", environment: "development", ...overrides });
|
|
18
|
+
// Capturing an exception implies the current timeline step failed.
|
|
19
|
+
let timeline;
|
|
20
|
+
if (scope?.timeline?.hasSteps) {
|
|
21
|
+
scope.timeline.fail();
|
|
22
|
+
timeline = scope.timeline.toJSON(true);
|
|
23
|
+
}
|
|
24
|
+
// Prevent the wrapper from re-capturing the same error when it re-propagates.
|
|
25
|
+
markCaptured(error);
|
|
26
|
+
const event = buildEvent({
|
|
27
|
+
options,
|
|
28
|
+
lambdaEvent: scope?.lambdaEvent,
|
|
29
|
+
lambdaContext: scope?.lambdaContext,
|
|
30
|
+
coldStart: scope?.coldStart ?? false,
|
|
31
|
+
error,
|
|
32
|
+
timeline,
|
|
33
|
+
customContext: context,
|
|
34
|
+
});
|
|
35
|
+
await deliver(options, event);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
// Last-resort guard: manual capture must not break the caller.
|
|
39
|
+
try {
|
|
40
|
+
currentScope()?.options.onError(err);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
/* ignore */
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Capture a standalone message/breadcrumb (no exception). Severity defaults to
|
|
49
|
+
* "info" and is stored in custom context.
|
|
50
|
+
*/
|
|
51
|
+
export async function captureMessage(message, context = {}, overrides) {
|
|
52
|
+
try {
|
|
53
|
+
const scope = currentScope();
|
|
54
|
+
const options = scope?.options ??
|
|
55
|
+
resolveOptions({ project: "unknown", environment: "development", ...overrides });
|
|
56
|
+
const event = buildEvent({
|
|
57
|
+
options,
|
|
58
|
+
lambdaEvent: scope?.lambdaEvent,
|
|
59
|
+
lambdaContext: scope?.lambdaContext,
|
|
60
|
+
coldStart: scope?.coldStart ?? false,
|
|
61
|
+
customContext: { severity: context.severity ?? "info", ...context },
|
|
62
|
+
});
|
|
63
|
+
// Model messages as a distinct "Message" event so the collector can tell
|
|
64
|
+
// them apart from thrown exceptions.
|
|
65
|
+
event.error = { type: "Message", message };
|
|
66
|
+
await deliver(options, event);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
try {
|
|
70
|
+
currentScope()?.options.onError(err);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
/* ignore */
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,KAAc,EACd,UAA0B,EAAE,EAC5B,SAAsC;IAEtC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,YAAY,EAAE,CAAC;QAC7B,MAAM,OAAO,GACX,KAAK,EAAE,OAAO;YACd,cAAc,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;QAEnF,mEAAmE;QACnE,IAAI,QAAQ,CAAC;QACb,IAAI,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;YAC9B,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACtB,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;QAED,8EAA8E;QAC9E,YAAY,CAAC,KAAK,CAAC,CAAC;QAEpB,MAAM,KAAK,GAAG,UAAU,CAAC;YACvB,OAAO;YACP,WAAW,EAAE,KAAK,EAAE,WAAW;YAC/B,aAAa,EAAE,KAAK,EAAE,aAAa;YACnC,SAAS,EAAE,KAAK,EAAE,SAAS,IAAI,KAAK;YACpC,KAAK;YACL,QAAQ;YACR,aAAa,EAAE,OAAkC;SAClD,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,+DAA+D;QAC/D,IAAI,CAAC;YACH,YAAY,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAe,EACf,UAA0B,EAAE,EAC5B,SAAsC;IAEtC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,YAAY,EAAE,CAAC;QAC7B,MAAM,OAAO,GACX,KAAK,EAAE,OAAO;YACd,cAAc,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;QAEnF,MAAM,KAAK,GAAG,UAAU,CAAC;YACvB,OAAO;YACP,WAAW,EAAE,KAAK,EAAE,WAAW;YAC/B,aAAa,EAAE,KAAK,EAAE,aAAa;YACnC,SAAS,EAAE,KAAK,EAAE,SAAS,IAAI,KAAK;YACpC,aAAa,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,MAAM,EAAE,GAAG,OAAO,EAAE;SACpE,CAAC,CAAC;QACH,yEAAyE;QACzE,qCAAqC;QACrC,KAAK,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;QAC3C,MAAM,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC;YACH,YAAY,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LambdaContext, PerformanceInfo } from "@bywaretech/bysentinel-core";
|
|
2
|
+
/** AWS Lambda `Context` — narrowed to what we use (avoids a hard dep). */
|
|
3
|
+
export interface AwsLambdaContextLike {
|
|
4
|
+
functionName?: string;
|
|
5
|
+
functionVersion?: string;
|
|
6
|
+
awsRequestId?: string;
|
|
7
|
+
memoryLimitInMB?: string;
|
|
8
|
+
getRemainingTimeInMillis?: () => number;
|
|
9
|
+
}
|
|
10
|
+
/** Reads and then clears the cold-start flag for this container. */
|
|
11
|
+
export declare function consumeColdStart(): boolean;
|
|
12
|
+
/** Test-only reset. */
|
|
13
|
+
export declare function __resetColdStart(): void;
|
|
14
|
+
export declare function extractLambdaContext(ctx: AwsLambdaContextLike | undefined, coldStart: boolean): LambdaContext;
|
|
15
|
+
export interface PerfProbe {
|
|
16
|
+
startMs: number;
|
|
17
|
+
startRemainingMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function startPerf(ctx: AwsLambdaContextLike | undefined): PerfProbe;
|
|
20
|
+
/**
|
|
21
|
+
* Compute performance metadata. Timeout risk fires when the invocation used up
|
|
22
|
+
* most of its remaining budget; memory pressure inflates severity elsewhere.
|
|
23
|
+
*/
|
|
24
|
+
export declare function finishPerf(probe: PerfProbe, ctx: AwsLambdaContextLike | undefined, memoryLimitMb: string | undefined): PerformanceInfo;
|
|
25
|
+
/** True when RSS is within 10% of the configured memory limit. */
|
|
26
|
+
export declare function isMemoryPressured(memoryUsedMb: number | undefined, memoryLimitMb: string | undefined): boolean;
|
|
27
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAElF,0EAA0E;AAC1E,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wBAAwB,CAAC,EAAE,MAAM,MAAM,CAAC;CACzC;AAKD,oEAAoE;AACpE,wBAAgB,gBAAgB,IAAI,OAAO,CAI1C;AAED,uBAAuB;AACvB,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,oBAAoB,GAAG,SAAS,EACrC,SAAS,EAAE,OAAO,GACjB,aAAa,CAUf;AAUD,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,oBAAoB,GAAG,SAAS,GAAG,SAAS,CAE1E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,oBAAoB,GAAG,SAAS,EACrC,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,eAAe,CAYjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,aAAa,EAAE,MAAM,GAAG,SAAS,GAChC,OAAO,CAIT"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Module-scoped: the first invocation of a warm container is a cold start.
|
|
2
|
+
let isColdStart = true;
|
|
3
|
+
/** Reads and then clears the cold-start flag for this container. */
|
|
4
|
+
export function consumeColdStart() {
|
|
5
|
+
const value = isColdStart;
|
|
6
|
+
isColdStart = false;
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
/** Test-only reset. */
|
|
10
|
+
export function __resetColdStart() {
|
|
11
|
+
isColdStart = true;
|
|
12
|
+
}
|
|
13
|
+
export function extractLambdaContext(ctx, coldStart) {
|
|
14
|
+
const remainingTimeMs = safeRemaining(ctx);
|
|
15
|
+
return {
|
|
16
|
+
functionName: ctx?.functionName,
|
|
17
|
+
functionVersion: ctx?.functionVersion,
|
|
18
|
+
requestId: ctx?.awsRequestId,
|
|
19
|
+
memoryLimitMb: ctx?.memoryLimitInMB,
|
|
20
|
+
remainingTimeMs,
|
|
21
|
+
coldStart,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function safeRemaining(ctx) {
|
|
25
|
+
try {
|
|
26
|
+
return ctx?.getRemainingTimeInMillis?.();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function startPerf(ctx) {
|
|
33
|
+
return { startMs: Date.now(), startRemainingMs: safeRemaining(ctx) };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Compute performance metadata. Timeout risk fires when the invocation used up
|
|
37
|
+
* most of its remaining budget; memory pressure inflates severity elsewhere.
|
|
38
|
+
*/
|
|
39
|
+
export function finishPerf(probe, ctx, memoryLimitMb) {
|
|
40
|
+
const durationMs = Date.now() - probe.startMs;
|
|
41
|
+
const memoryUsedMb = Math.round((process.memoryUsage().rss / (1024 * 1024)) * 10) / 10;
|
|
42
|
+
let timeoutRisk = false;
|
|
43
|
+
if (probe.startRemainingMs != null) {
|
|
44
|
+
const remainingNow = Math.max(0, probe.startRemainingMs - durationMs);
|
|
45
|
+
const threshold = Math.max(1000, probe.startRemainingMs * 0.1);
|
|
46
|
+
timeoutRisk = remainingNow <= threshold;
|
|
47
|
+
}
|
|
48
|
+
return { durationMs, memoryUsedMb, timeoutRisk };
|
|
49
|
+
}
|
|
50
|
+
/** True when RSS is within 10% of the configured memory limit. */
|
|
51
|
+
export function isMemoryPressured(memoryUsedMb, memoryLimitMb) {
|
|
52
|
+
const limit = memoryLimitMb ? Number(memoryLimitMb) : NaN;
|
|
53
|
+
if (!memoryUsedMb || !Number.isFinite(limit) || limit <= 0)
|
|
54
|
+
return false;
|
|
55
|
+
return memoryUsedMb / limit >= 0.9;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAWA,2EAA2E;AAC3E,IAAI,WAAW,GAAG,IAAI,CAAC;AAEvB,oEAAoE;AACpE,MAAM,UAAU,gBAAgB;IAC9B,MAAM,KAAK,GAAG,WAAW,CAAC;IAC1B,WAAW,GAAG,KAAK,CAAC;IACpB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,uBAAuB;AACvB,MAAM,UAAU,gBAAgB;IAC9B,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,GAAqC,EACrC,SAAkB;IAElB,MAAM,eAAe,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO;QACL,YAAY,EAAE,GAAG,EAAE,YAAY;QAC/B,eAAe,EAAE,GAAG,EAAE,eAAe;QACrC,SAAS,EAAE,GAAG,EAAE,YAAY;QAC5B,aAAa,EAAE,GAAG,EAAE,eAAe;QACnC,eAAe;QACf,SAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,GAAqC;IAC1D,IAAI,CAAC;QACH,OAAO,GAAG,EAAE,wBAAwB,EAAE,EAAE,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAOD,MAAM,UAAU,SAAS,CAAC,GAAqC;IAC7D,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,gBAAgB,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;AACvE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,KAAgB,EAChB,GAAqC,EACrC,aAAiC;IAEjC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9C,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;IAEvF,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,KAAK,CAAC,gBAAgB,IAAI,IAAI,EAAE,CAAC;QACnC,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,gBAAgB,GAAG,UAAU,CAAC,CAAC;QACtE,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,gBAAgB,GAAG,GAAG,CAAC,CAAC;QAC/D,WAAW,GAAG,YAAY,IAAI,SAAS,CAAC;IAC1C,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC;AACnD,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAC/B,YAAgC,EAChC,aAAiC;IAEjC,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1D,IAAI,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACzE,OAAO,YAAY,GAAG,KAAK,IAAI,GAAG,CAAC;AACrC,CAAC"}
|
package/dist/dedupe.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedupe.d.ts","sourceRoot":"","sources":["../src/dedupe.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAajD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAElD"}
|
package/dist/dedupe.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deduplication marker so an error captured manually (via `captureException`)
|
|
3
|
+
* is not captured a second time by the `withBySentinel` wrapper when it
|
|
4
|
+
* re-propagates. One failure → one incident.
|
|
5
|
+
*/
|
|
6
|
+
const CAPTURED = Symbol.for("bysentinel.captured");
|
|
7
|
+
export function markCaptured(error) {
|
|
8
|
+
if (error && typeof error === "object") {
|
|
9
|
+
try {
|
|
10
|
+
Object.defineProperty(error, CAPTURED, {
|
|
11
|
+
value: true,
|
|
12
|
+
enumerable: false,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
/* frozen/sealed error — best effort, ignore */
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function isCaptured(error) {
|
|
23
|
+
return Boolean(error && typeof error === "object" && error[CAPTURED]);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=dedupe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedupe.js","sourceRoot":"","sources":["../src/dedupe.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAEnD,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,IAAI,CAAC;YACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE;gBACrC,KAAK,EAAE,IAAI;gBACX,UAAU,EAAE,KAAK;gBACjB,YAAY,EAAE,IAAI;gBAClB,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,+CAA+C;QACjD,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAK,KAAiC,CAAC,QAAQ,CAAC,CAAC,CAAC;AACrG,CAAC"}
|
package/dist/event.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ErrorInfo, type ExecutionTimeline, type PerformanceInfo, type BySentinelEvent } from "@bywaretech/bysentinel-core";
|
|
2
|
+
import { type AwsLambdaContextLike } from "./context.js";
|
|
3
|
+
import type { ResolvedOptions } from "./types.js";
|
|
4
|
+
export declare function errorToInfo(error: unknown, includeStack: boolean): ErrorInfo;
|
|
5
|
+
export interface BuildEventParams {
|
|
6
|
+
options: ResolvedOptions;
|
|
7
|
+
lambdaEvent?: unknown;
|
|
8
|
+
lambdaContext?: AwsLambdaContextLike;
|
|
9
|
+
coldStart: boolean;
|
|
10
|
+
error?: unknown;
|
|
11
|
+
performance?: PerformanceInfo;
|
|
12
|
+
timeline?: ExecutionTimeline;
|
|
13
|
+
customContext?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Assemble a fully-sanitized BySentinelEvent. Security signals are detected on
|
|
17
|
+
* the RAW request (before redaction) so patterns are visible, then the request
|
|
18
|
+
* and custom context are redacted. `sanitized` is always true on the result.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildEvent(params: BuildEventParams): BySentinelEvent;
|
|
21
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAEpB,KAAK,eAAe,EAErB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAE/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,GAAG,SAAS,CAS5E;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,eAAe,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,eAAe,CA2CpE"}
|