autotel 3.5.0 → 3.7.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/dist/attribute-redacting-processor-DtTS9xxh.d.cts +175 -0
- package/dist/attribute-redacting-processor-DtTS9xxh.d.cts.map +1 -0
- package/dist/attribute-redacting-processor-DtTS9xxh.d.ts +175 -0
- package/dist/attribute-redacting-processor-DtTS9xxh.d.ts.map +1 -0
- package/dist/attribute-redacting-processor.cjs +374 -33
- package/dist/attribute-redacting-processor.cjs.map +1 -1
- package/dist/attribute-redacting-processor.d.cts +2 -207
- package/dist/attribute-redacting-processor.d.ts +2 -207
- package/dist/attribute-redacting-processor.js +368 -2
- package/dist/attribute-redacting-processor.js.map +1 -1
- package/dist/attributes-D3etyRVc.cjs +713 -0
- package/dist/attributes-D3etyRVc.cjs.map +1 -0
- package/dist/attributes-ksn4HVbd.js +600 -0
- package/dist/attributes-ksn4HVbd.js.map +1 -0
- package/dist/attributes.cjs +21 -85
- package/dist/attributes.d.cts +2 -20
- package/dist/attributes.d.ts +2 -20
- package/dist/attributes.js +3 -5
- package/dist/auto.cjs +50 -28
- package/dist/auto.cjs.map +1 -1
- package/dist/auto.d.cts +1 -2
- package/dist/auto.d.ts +1 -2
- package/dist/auto.js +49 -23
- package/dist/auto.js.map +1 -1
- package/dist/business-baggage.cjs +357 -13
- package/dist/business-baggage.cjs.map +1 -1
- package/dist/business-baggage.d.cts +106 -139
- package/dist/business-baggage.d.cts.map +1 -0
- package/dist/business-baggage.d.ts +106 -139
- package/dist/business-baggage.d.ts.map +1 -0
- package/dist/business-baggage.js +357 -2
- package/dist/business-baggage.js.map +1 -1
- package/dist/canonical-log-line-processor--RlFDHhm.cjs +377 -0
- package/dist/canonical-log-line-processor--RlFDHhm.cjs.map +1 -0
- package/dist/canonical-log-line-processor-BcRuAdRk.d.ts +147 -0
- package/dist/canonical-log-line-processor-BcRuAdRk.d.ts.map +1 -0
- package/dist/canonical-log-line-processor-DbBQT5vY.js +366 -0
- package/dist/canonical-log-line-processor-DbBQT5vY.js.map +1 -0
- package/dist/canonical-log-line-processor-xvjMgtpF.d.cts +147 -0
- package/dist/canonical-log-line-processor-xvjMgtpF.d.cts.map +1 -0
- package/dist/config.cjs +118 -22
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +33 -45
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.ts +33 -45
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +116 -3
- package/dist/config.js.map +1 -1
- package/dist/correlated-events-Bzh5y-UB.js +28 -0
- package/dist/correlated-events-Bzh5y-UB.js.map +1 -0
- package/dist/correlated-events-kSwLo3mi.cjs +34 -0
- package/dist/correlated-events-kSwLo3mi.cjs.map +1 -0
- package/dist/correlation-id.cjs +11 -53
- package/dist/correlation-id.d.cts +6 -5
- package/dist/correlation-id.d.cts.map +1 -0
- package/dist/correlation-id.d.ts +6 -5
- package/dist/correlation-id.d.ts.map +1 -0
- package/dist/correlation-id.js +3 -16
- package/dist/db.cjs +244 -209
- package/dist/db.cjs.map +1 -1
- package/dist/db.d.cts +28 -26
- package/dist/db.d.cts.map +1 -0
- package/dist/db.d.ts +28 -26
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +243 -207
- package/dist/db.js.map +1 -1
- package/dist/decorators.cjs +39 -65
- package/dist/decorators.cjs.map +1 -1
- package/dist/decorators.d.cts +10 -37
- package/dist/decorators.d.cts.map +1 -0
- package/dist/decorators.d.ts +10 -37
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +38 -63
- package/dist/decorators.js.map +1 -1
- package/dist/define-event-CreknLm3.d.ts +25 -0
- package/dist/define-event-CreknLm3.d.ts.map +1 -0
- package/dist/define-event-HZRizPwz.d.cts +25 -0
- package/dist/define-event-HZRizPwz.d.cts.map +1 -0
- package/dist/drain-pipeline.cjs +111 -9
- package/dist/drain-pipeline.cjs.map +1 -1
- package/dist/drain-pipeline.d.cts +27 -32
- package/dist/drain-pipeline.d.cts.map +1 -0
- package/dist/drain-pipeline.d.ts +27 -32
- package/dist/drain-pipeline.d.ts.map +1 -0
- package/dist/drain-pipeline.js +111 -2
- package/dist/drain-pipeline.js.map +1 -1
- package/dist/enrichers.cjs +59 -66
- package/dist/enrichers.cjs.map +1 -1
- package/dist/enrichers.d.cts +15 -13
- package/dist/enrichers.d.cts.map +1 -0
- package/dist/enrichers.d.ts +15 -13
- package/dist/enrichers.d.ts.map +1 -0
- package/dist/enrichers.js +58 -65
- package/dist/enrichers.js.map +1 -1
- package/dist/event-Dlqr4ZNL.cjs +778 -0
- package/dist/event-Dlqr4ZNL.cjs.map +1 -0
- package/dist/event-_58ryBjh.js +761 -0
- package/dist/event-_58ryBjh.js.map +1 -0
- package/dist/event-subscriber-D1XLkPzi.d.cts +223 -0
- package/dist/event-subscriber-D1XLkPzi.d.cts.map +1 -0
- package/dist/event-subscriber-D1XLkPzi.d.ts +223 -0
- package/dist/event-subscriber-D1XLkPzi.d.ts.map +1 -0
- package/dist/event-subscriber.cjs +0 -6
- package/dist/event-subscriber.d.cts +2 -221
- package/dist/event-subscriber.d.ts +2 -221
- package/dist/event-subscriber.js +1 -3
- package/dist/event-testing-BqRnI0z4.d.cts +106 -0
- package/dist/event-testing-BqRnI0z4.d.cts.map +1 -0
- package/dist/event-testing-CfFs3to2.d.ts +106 -0
- package/dist/event-testing-CfFs3to2.d.ts.map +1 -0
- package/dist/event-testing.cjs +93 -17
- package/dist/event-testing.cjs.map +1 -1
- package/dist/event-testing.d.cts +2 -110
- package/dist/event-testing.d.ts +2 -110
- package/dist/event-testing.js +91 -2
- package/dist/event-testing.js.map +1 -1
- package/dist/event.cjs +5 -36
- package/dist/event.d.cts +295 -340
- package/dist/event.d.cts.map +1 -0
- package/dist/event.d.ts +295 -340
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +3 -20
- package/dist/exporters.cjs +12 -16
- package/dist/exporters.d.cts +86 -111
- package/dist/exporters.d.cts.map +1 -0
- package/dist/exporters.d.ts +86 -111
- package/dist/exporters.d.ts.map +1 -0
- package/dist/exporters.js +4 -4
- package/dist/filtering-span-processor-B8R8B7Uk.d.cts +59 -0
- package/dist/filtering-span-processor-B8R8B7Uk.d.cts.map +1 -0
- package/dist/filtering-span-processor-B8R8B7Uk.d.ts +59 -0
- package/dist/filtering-span-processor-B8R8B7Uk.d.ts.map +1 -0
- package/dist/filtering-span-processor.cjs +49 -9
- package/dist/filtering-span-processor.cjs.map +1 -1
- package/dist/filtering-span-processor.d.cts +2 -80
- package/dist/filtering-span-processor.d.ts +2 -80
- package/dist/filtering-span-processor.js +49 -2
- package/dist/filtering-span-processor.js.map +1 -1
- package/dist/functional-BGkT8J-h.js +1265 -0
- package/dist/functional-BGkT8J-h.js.map +1 -0
- package/dist/functional-C4CzoVrX.cjs +1312 -0
- package/dist/functional-C4CzoVrX.cjs.map +1 -0
- package/dist/functional.cjs +11 -56
- package/dist/functional.d.cts +96 -97
- package/dist/functional.d.cts.map +1 -0
- package/dist/functional.d.ts +96 -97
- package/dist/functional.d.ts.map +1 -0
- package/dist/functional.js +3 -19
- package/dist/http.cjs +276 -175
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +17 -37
- package/dist/http.d.cts.map +1 -0
- package/dist/http.d.ts +17 -37
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +275 -173
- package/dist/http.js.map +1 -1
- package/dist/index-CX0aG1Uh.d.ts +708 -0
- package/dist/index-CX0aG1Uh.d.ts.map +1 -0
- package/dist/index-DIWZFKUS.d.cts +708 -0
- package/dist/index-DIWZFKUS.d.cts.map +1 -0
- package/dist/index.cjs +1050 -1184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +401 -570
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +401 -570
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +913 -725
- package/dist/index.js.map +1 -1
- package/dist/init-CNp-ee80.d.cts +1157 -0
- package/dist/init-CNp-ee80.d.cts.map +1 -0
- package/dist/init-Ch6t7MNI.js +1015 -0
- package/dist/init-Ch6t7MNI.js.map +1 -0
- package/dist/init-DJQOdVlN.d.ts +1157 -0
- package/dist/init-DJQOdVlN.d.ts.map +1 -0
- package/dist/init-DvapOXCc.cjs +1092 -0
- package/dist/init-DvapOXCc.cjs.map +1 -0
- package/dist/instrumentation.cjs +159 -185
- package/dist/instrumentation.cjs.map +1 -1
- package/dist/instrumentation.d.cts +42 -40
- package/dist/instrumentation.d.cts.map +1 -0
- package/dist/instrumentation.d.ts +42 -40
- package/dist/instrumentation.d.ts.map +1 -0
- package/dist/instrumentation.js +158 -183
- package/dist/instrumentation.js.map +1 -1
- package/dist/logger-BauSUhUv.d.cts +313 -0
- package/dist/logger-BauSUhUv.d.cts.map +1 -0
- package/dist/logger-BauSUhUv.d.ts +313 -0
- package/dist/logger-BauSUhUv.d.ts.map +1 -0
- package/dist/logger.cjs +225 -25
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +2 -348
- package/dist/logger.d.ts +2 -348
- package/dist/logger.js +204 -4
- package/dist/logger.js.map +1 -1
- package/dist/messaging-adapters.cjs +292 -187
- package/dist/messaging-adapters.cjs.map +1 -1
- package/dist/messaging-adapters.d.cts +28 -66
- package/dist/messaging-adapters.d.cts.map +1 -0
- package/dist/messaging-adapters.d.ts +28 -66
- package/dist/messaging-adapters.d.ts.map +1 -0
- package/dist/messaging-adapters.js +291 -185
- package/dist/messaging-adapters.js.map +1 -1
- package/dist/messaging-testing.cjs +306 -372
- package/dist/messaging-testing.cjs.map +1 -1
- package/dist/messaging-testing.d.cts +194 -223
- package/dist/messaging-testing.d.cts.map +1 -0
- package/dist/messaging-testing.d.ts +194 -223
- package/dist/messaging-testing.d.ts.map +1 -0
- package/dist/messaging-testing.js +305 -371
- package/dist/messaging-testing.js.map +1 -1
- package/dist/messaging.cjs +757 -35
- package/dist/messaging.cjs.map +1 -1
- package/dist/messaging.d.cts +603 -644
- package/dist/messaging.d.cts.map +1 -0
- package/dist/messaging.d.ts +603 -644
- package/dist/messaging.d.ts.map +1 -0
- package/dist/messaging.js +756 -20
- package/dist/messaging.js.map +1 -1
- package/dist/metric-helpers.cjs +27 -27
- package/dist/metric-helpers.cjs.map +1 -1
- package/dist/metric-helpers.d.cts +4 -2
- package/dist/metric-helpers.d.cts.map +1 -0
- package/dist/metric-helpers.d.ts +4 -2
- package/dist/metric-helpers.d.ts.map +1 -0
- package/dist/metric-helpers.js +24 -4
- package/dist/metric-helpers.js.map +1 -1
- package/dist/metric-testing-DXdK3-Q3.d.ts +106 -0
- package/dist/metric-testing-DXdK3-Q3.d.ts.map +1 -0
- package/dist/metric-testing-MxvzChDp.d.cts +106 -0
- package/dist/metric-testing-MxvzChDp.d.cts.map +1 -0
- package/dist/metric-testing.cjs +93 -17
- package/dist/metric-testing.cjs.map +1 -1
- package/dist/metric-testing.d.cts +2 -110
- package/dist/metric-testing.d.ts +2 -110
- package/dist/metric-testing.js +91 -2
- package/dist/metric-testing.js.map +1 -1
- package/dist/metric.cjs +306 -22
- package/dist/metric.cjs.map +1 -1
- package/dist/metric.d.cts +170 -198
- package/dist/metric.d.cts.map +1 -0
- package/dist/metric.d.ts +170 -198
- package/dist/metric.d.ts.map +1 -0
- package/dist/metric.js +277 -7
- package/dist/metric.js.map +1 -1
- package/dist/node-require-DF5QBX6z.cjs +99 -0
- package/dist/node-require-DF5QBX6z.cjs.map +1 -0
- package/dist/node-require-Db1oDpLj.js +88 -0
- package/dist/node-require-Db1oDpLj.js.map +1 -0
- package/dist/operation-context-C-2hmmtP.js +59 -0
- package/dist/operation-context-C-2hmmtP.js.map +1 -0
- package/dist/operation-context-n4_obUwq.cjs +70 -0
- package/dist/operation-context-n4_obUwq.cjs.map +1 -0
- package/dist/parse-error.cjs +55 -9
- package/dist/parse-error.cjs.map +1 -1
- package/dist/parse-error.d.cts +12 -10
- package/dist/parse-error.d.cts.map +1 -0
- package/dist/parse-error.d.ts +12 -10
- package/dist/parse-error.d.ts.map +1 -0
- package/dist/parse-error.js +55 -2
- package/dist/parse-error.js.map +1 -1
- package/dist/pretty-console-exporter-CMzlrRNg.cjs +232 -0
- package/dist/pretty-console-exporter-CMzlrRNg.cjs.map +1 -0
- package/dist/pretty-console-exporter-DqKl_q9z.js +227 -0
- package/dist/pretty-console-exporter-DqKl_q9z.js.map +1 -0
- package/dist/processors.cjs +13 -17
- package/dist/processors.d.cts +3 -171
- package/dist/processors.d.ts +3 -171
- package/dist/processors.js +4 -4
- package/dist/register.cjs +35 -6
- package/dist/register.cjs.map +1 -1
- package/dist/register.d.cts +1 -2
- package/dist/register.d.ts +1 -2
- package/dist/register.js +36 -3
- package/dist/register.js.map +1 -1
- package/dist/registry-DfXA3R1L.js +184 -0
- package/dist/registry-DfXA3R1L.js.map +1 -0
- package/dist/registry-JZg2J3RZ.cjs +334 -0
- package/dist/registry-JZg2J3RZ.cjs.map +1 -0
- package/dist/sampling-CR0Va1VB.d.ts +351 -0
- package/dist/sampling-CR0Va1VB.d.ts.map +1 -0
- package/dist/sampling-DfYhDJij.d.cts +351 -0
- package/dist/sampling-DfYhDJij.d.cts.map +1 -0
- package/dist/sampling.cjs +452 -60
- package/dist/sampling.cjs.map +1 -1
- package/dist/sampling.d.cts +2 -379
- package/dist/sampling.d.ts +2 -379
- package/dist/sampling.js +441 -5
- package/dist/sampling.js.map +1 -1
- package/dist/security-schema.cjs +65 -46
- package/dist/security-schema.cjs.map +1 -1
- package/dist/security-schema.d.cts +23 -26
- package/dist/security-schema.d.cts.map +1 -0
- package/dist/security-schema.d.ts +23 -26
- package/dist/security-schema.d.ts.map +1 -0
- package/dist/security-schema.js +64 -45
- package/dist/security-schema.js.map +1 -1
- package/dist/semantic-conventions-FhSxv-bK.d.cts +32 -0
- package/dist/semantic-conventions-FhSxv-bK.d.cts.map +1 -0
- package/dist/semantic-conventions-FhSxv-bK.d.ts +32 -0
- package/dist/semantic-conventions-FhSxv-bK.d.ts.map +1 -0
- package/dist/semantic-conventions.cjs +15 -26
- package/dist/semantic-conventions.cjs.map +1 -1
- package/dist/semantic-conventions.d.cts +2 -29
- package/dist/semantic-conventions.d.ts +2 -29
- package/dist/semantic-conventions.js +12 -3
- package/dist/semantic-conventions.js.map +1 -1
- package/dist/semantic-helpers.cjs +440 -38
- package/dist/semantic-helpers.cjs.map +1 -1
- package/dist/semantic-helpers.d.cts +38 -45
- package/dist/semantic-helpers.d.cts.map +1 -0
- package/dist/semantic-helpers.d.ts +38 -45
- package/dist/semantic-helpers.d.ts.map +1 -0
- package/dist/semantic-helpers.js +438 -19
- package/dist/semantic-helpers.js.map +1 -1
- package/dist/span-name-normalizer-8ZOGJuwv.d.cts +70 -0
- package/dist/span-name-normalizer-8ZOGJuwv.d.cts.map +1 -0
- package/dist/span-name-normalizer-8ZOGJuwv.d.ts +70 -0
- package/dist/span-name-normalizer-8ZOGJuwv.d.ts.map +1 -0
- package/dist/span-name-normalizer.cjs +95 -17
- package/dist/span-name-normalizer.cjs.map +1 -1
- package/dist/span-name-normalizer.d.cts +2 -94
- package/dist/span-name-normalizer.d.ts +2 -94
- package/dist/span-name-normalizer.js +93 -2
- package/dist/span-name-normalizer.js.map +1 -1
- package/dist/stable-hash-BNTMrmdB.cjs +28 -0
- package/dist/stable-hash-BNTMrmdB.cjs.map +1 -0
- package/dist/stable-hash-Cg5cT34Q.js +23 -0
- package/dist/stable-hash-Cg5cT34Q.js.map +1 -0
- package/dist/structured-error-9--cxBay.js +143 -0
- package/dist/structured-error-9--cxBay.js.map +1 -0
- package/dist/structured-error-CHg7DoIQ.cjs +178 -0
- package/dist/structured-error-CHg7DoIQ.cjs.map +1 -0
- package/dist/tail-sampling-processor.cjs +26 -13
- package/dist/tail-sampling-processor.cjs.map +1 -1
- package/dist/tail-sampling-processor.d.cts +11 -23
- package/dist/tail-sampling-processor.d.cts.map +1 -0
- package/dist/tail-sampling-processor.d.ts +11 -23
- package/dist/tail-sampling-processor.d.ts.map +1 -0
- package/dist/tail-sampling-processor.js +27 -6
- package/dist/tail-sampling-processor.js.map +1 -1
- package/dist/test-span-collector.cjs +70 -72
- package/dist/test-span-collector.cjs.map +1 -1
- package/dist/test-span-collector.d.cts +25 -43
- package/dist/test-span-collector.d.cts.map +1 -0
- package/dist/test-span-collector.d.ts +25 -43
- package/dist/test-span-collector.d.ts.map +1 -0
- package/dist/test-span-collector.js +69 -70
- package/dist/test-span-collector.js.map +1 -1
- package/dist/testing.cjs +389 -278
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +39 -62
- package/dist/testing.d.cts.map +1 -0
- package/dist/testing.d.ts +39 -62
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +386 -265
- package/dist/testing.js.map +1 -1
- package/dist/trace-context-Cijqoi6e.d.cts +212 -0
- package/dist/trace-context-Cijqoi6e.d.cts.map +1 -0
- package/dist/trace-context-Cijqoi6e.d.ts +212 -0
- package/dist/trace-context-Cijqoi6e.d.ts.map +1 -0
- package/dist/trace-helpers.cjs +634 -54
- package/dist/trace-helpers.cjs.map +1 -1
- package/dist/trace-helpers.d.cts +17 -49
- package/dist/trace-helpers.d.cts.map +1 -0
- package/dist/trace-helpers.d.ts +17 -49
- package/dist/trace-helpers.d.ts.map +1 -0
- package/dist/trace-helpers.js +624 -3
- package/dist/trace-helpers.js.map +1 -1
- package/dist/tracer-provider.cjs +227 -16
- package/dist/tracer-provider.cjs.map +1 -1
- package/dist/tracer-provider.d.cts +5 -4
- package/dist/tracer-provider.d.cts.map +1 -0
- package/dist/tracer-provider.d.ts +5 -4
- package/dist/tracer-provider.d.ts.map +1 -0
- package/dist/tracer-provider.js +227 -2
- package/dist/tracer-provider.js.map +1 -1
- package/dist/track-3HY4NGV-.cjs +1212 -0
- package/dist/track-3HY4NGV-.cjs.map +1 -0
- package/dist/track-nsKVy-pj.js +1111 -0
- package/dist/track-nsKVy-pj.js.map +1 -0
- package/dist/validate.cjs +201 -0
- package/dist/validate.cjs.map +1 -0
- package/dist/validate.d.cts +105 -0
- package/dist/validate.d.cts.map +1 -0
- package/dist/validate.d.ts +105 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +197 -0
- package/dist/validate.js.map +1 -0
- package/dist/validation-attributes.cjs +45 -0
- package/dist/validation-attributes.cjs.map +1 -0
- package/dist/validation-attributes.d.cts +33 -0
- package/dist/validation-attributes.d.cts.map +1 -0
- package/dist/validation-attributes.d.ts +33 -0
- package/dist/validation-attributes.d.ts.map +1 -0
- package/dist/validation-attributes.js +41 -0
- package/dist/validation-attributes.js.map +1 -0
- package/dist/webhook.cjs +286 -255
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +157 -192
- package/dist/webhook.d.cts.map +1 -0
- package/dist/webhook.d.ts +157 -192
- package/dist/webhook.d.ts.map +1 -0
- package/dist/webhook.js +285 -253
- package/dist/webhook.js.map +1 -1
- package/dist/workflow-distributed.cjs +498 -411
- package/dist/workflow-distributed.cjs.map +1 -1
- package/dist/workflow-distributed.d.cts +163 -173
- package/dist/workflow-distributed.d.cts.map +1 -0
- package/dist/workflow-distributed.d.ts +163 -173
- package/dist/workflow-distributed.d.ts.map +1 -0
- package/dist/workflow-distributed.js +497 -409
- package/dist/workflow-distributed.js.map +1 -1
- package/dist/workflow.cjs +405 -39
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +78 -131
- package/dist/workflow.d.cts.map +1 -0
- package/dist/workflow.d.ts +78 -131
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +403 -20
- package/dist/workflow.js.map +1 -1
- package/dist/yaml-config-B3dQ82GR.cjs +272 -0
- package/dist/yaml-config-B3dQ82GR.cjs.map +1 -0
- package/dist/yaml-config.cjs +5 -24
- package/dist/yaml-config.d.cts +30 -64
- package/dist/yaml-config.d.cts.map +1 -0
- package/dist/yaml-config.d.ts +30 -64
- package/dist/yaml-config.d.ts.map +1 -0
- package/dist/yaml-config.js +226 -7
- package/dist/yaml-config.js.map +1 -1
- package/package.json +14 -4
- package/src/define-event.ts +2 -21
- package/src/index.ts +3 -0
- package/src/request-logger.test.ts +53 -1
- package/src/request-logger.ts +58 -0
- package/src/stable-hash.ts +27 -0
- package/src/validate.test.ts +287 -0
- package/src/validate.ts +307 -0
- package/src/validation-attributes.ts +43 -0
- package/dist/attributes.cjs.map +0 -1
- package/dist/attributes.js.map +0 -1
- package/dist/chunk-2ZKEORFN.cjs +0 -14
- package/dist/chunk-2ZKEORFN.cjs.map +0 -1
- package/dist/chunk-3QXBFGKP.js +0 -344
- package/dist/chunk-3QXBFGKP.js.map +0 -1
- package/dist/chunk-454CH4OV.js +0 -744
- package/dist/chunk-454CH4OV.js.map +0 -1
- package/dist/chunk-4A53YIAX.js +0 -180
- package/dist/chunk-4A53YIAX.js.map +0 -1
- package/dist/chunk-4IFSYQVX.js +0 -337
- package/dist/chunk-4IFSYQVX.js.map +0 -1
- package/dist/chunk-4P6ZOARG.cjs +0 -33
- package/dist/chunk-4P6ZOARG.cjs.map +0 -1
- package/dist/chunk-55ER2KD5.js +0 -228
- package/dist/chunk-55ER2KD5.js.map +0 -1
- package/dist/chunk-5ZN622AO.js +0 -73
- package/dist/chunk-5ZN622AO.js.map +0 -1
- package/dist/chunk-6S5RUKU3.cjs +0 -347
- package/dist/chunk-6S5RUKU3.cjs.map +0 -1
- package/dist/chunk-6UQRVUN3.js +0 -222
- package/dist/chunk-6UQRVUN3.js.map +0 -1
- package/dist/chunk-7552UTQW.js +0 -11
- package/dist/chunk-7552UTQW.js.map +0 -1
- package/dist/chunk-7EQ4G4SI.cjs +0 -146
- package/dist/chunk-7EQ4G4SI.cjs.map +0 -1
- package/dist/chunk-7SAWIN74.js +0 -285
- package/dist/chunk-7SAWIN74.js.map +0 -1
- package/dist/chunk-A4E5AQFK.js +0 -30
- package/dist/chunk-A4E5AQFK.js.map +0 -1
- package/dist/chunk-AC5GNZKB.cjs +0 -344
- package/dist/chunk-AC5GNZKB.cjs.map +0 -1
- package/dist/chunk-ALPYR2GC.js +0 -1061
- package/dist/chunk-ALPYR2GC.js.map +0 -1
- package/dist/chunk-BZHG5IZ4.js +0 -73
- package/dist/chunk-BZHG5IZ4.js.map +0 -1
- package/dist/chunk-CEAQK2QY.cjs +0 -32
- package/dist/chunk-CEAQK2QY.cjs.map +0 -1
- package/dist/chunk-CMHVQR6P.js +0 -170
- package/dist/chunk-CMHVQR6P.js.map +0 -1
- package/dist/chunk-CU6IDACR.cjs +0 -224
- package/dist/chunk-CU6IDACR.cjs.map +0 -1
- package/dist/chunk-DPSA4QLA.js +0 -344
- package/dist/chunk-DPSA4QLA.js.map +0 -1
- package/dist/chunk-DQEHQNQE.js +0 -795
- package/dist/chunk-DQEHQNQE.js.map +0 -1
- package/dist/chunk-ESLWRGAG.cjs +0 -92
- package/dist/chunk-ESLWRGAG.cjs.map +0 -1
- package/dist/chunk-ESMHTKLJ.cjs +0 -206
- package/dist/chunk-ESMHTKLJ.cjs.map +0 -1
- package/dist/chunk-FGNDN2FD.cjs +0 -1242
- package/dist/chunk-FGNDN2FD.cjs.map +0 -1
- package/dist/chunk-FU6R566Y.cjs +0 -236
- package/dist/chunk-FU6R566Y.cjs.map +0 -1
- package/dist/chunk-GBFTC7Q7.cjs +0 -837
- package/dist/chunk-GBFTC7Q7.cjs.map +0 -1
- package/dist/chunk-GYR5K654.js +0 -91
- package/dist/chunk-GYR5K654.js.map +0 -1
- package/dist/chunk-HA2WBOGQ.js +0 -57
- package/dist/chunk-HA2WBOGQ.js.map +0 -1
- package/dist/chunk-HT5JQKN2.js +0 -118
- package/dist/chunk-HT5JQKN2.js.map +0 -1
- package/dist/chunk-INJD3G4K.cjs +0 -340
- package/dist/chunk-INJD3G4K.cjs.map +0 -1
- package/dist/chunk-IOYFAFHJ.cjs +0 -95
- package/dist/chunk-IOYFAFHJ.cjs.map +0 -1
- package/dist/chunk-J5QENANM.js +0 -87
- package/dist/chunk-J5QENANM.js.map +0 -1
- package/dist/chunk-J7VGRIAJ.js +0 -64
- package/dist/chunk-J7VGRIAJ.js.map +0 -1
- package/dist/chunk-KFOHQK7X.js +0 -144
- package/dist/chunk-KFOHQK7X.js.map +0 -1
- package/dist/chunk-KIL5CUN6.js +0 -31
- package/dist/chunk-KIL5CUN6.js.map +0 -1
- package/dist/chunk-LITNXTTT.js +0 -3
- package/dist/chunk-LITNXTTT.js.map +0 -1
- package/dist/chunk-M3LFHHTN.cjs +0 -764
- package/dist/chunk-M3LFHHTN.cjs.map +0 -1
- package/dist/chunk-NEIB3TLD.cjs +0 -360
- package/dist/chunk-NEIB3TLD.cjs.map +0 -1
- package/dist/chunk-NVAI5CCN.cjs +0 -39
- package/dist/chunk-NVAI5CCN.cjs.map +0 -1
- package/dist/chunk-NVGPMGI4.js +0 -95
- package/dist/chunk-NVGPMGI4.js.map +0 -1
- package/dist/chunk-NZ72VDNY.cjs +0 -4
- package/dist/chunk-NZ72VDNY.cjs.map +0 -1
- package/dist/chunk-O4JZUCUE.js +0 -1174
- package/dist/chunk-O4JZUCUE.js.map +0 -1
- package/dist/chunk-O7JOKRN2.js +0 -833
- package/dist/chunk-O7JOKRN2.js.map +0 -1
- package/dist/chunk-OPPXYVEZ.cjs +0 -131
- package/dist/chunk-OPPXYVEZ.cjs.map +0 -1
- package/dist/chunk-Q4EULJQY.js +0 -35
- package/dist/chunk-Q4EULJQY.js.map +0 -1
- package/dist/chunk-QWW3E3JM.cjs +0 -178
- package/dist/chunk-QWW3E3JM.cjs.map +0 -1
- package/dist/chunk-R7QYGZUP.cjs +0 -1075
- package/dist/chunk-R7QYGZUP.cjs.map +0 -1
- package/dist/chunk-RUPKBKUF.js +0 -352
- package/dist/chunk-RUPKBKUF.js.map +0 -1
- package/dist/chunk-SEO6NAQT.js +0 -14
- package/dist/chunk-SEO6NAQT.js.map +0 -1
- package/dist/chunk-T4B5LB6E.cjs +0 -66
- package/dist/chunk-T4B5LB6E.cjs.map +0 -1
- package/dist/chunk-TC5ZPWM4.cjs +0 -289
- package/dist/chunk-TC5ZPWM4.cjs.map +0 -1
- package/dist/chunk-TQ5UWA7S.js +0 -26
- package/dist/chunk-TQ5UWA7S.js.map +0 -1
- package/dist/chunk-URHPSJW2.js +0 -339
- package/dist/chunk-URHPSJW2.js.map +0 -1
- package/dist/chunk-UY3UYPBZ.cjs +0 -77
- package/dist/chunk-UY3UYPBZ.cjs.map +0 -1
- package/dist/chunk-VG2ABKJX.cjs +0 -100
- package/dist/chunk-VG2ABKJX.cjs.map +0 -1
- package/dist/chunk-VH77IPJN.cjs +0 -358
- package/dist/chunk-VH77IPJN.cjs.map +0 -1
- package/dist/chunk-VQTCQKHQ.cjs +0 -17
- package/dist/chunk-VQTCQKHQ.cjs.map +0 -1
- package/dist/chunk-WGWSHJ2N.js +0 -38
- package/dist/chunk-WGWSHJ2N.js.map +0 -1
- package/dist/chunk-WJH6IYU2.cjs +0 -32
- package/dist/chunk-WJH6IYU2.cjs.map +0 -1
- package/dist/chunk-YREV3LGG.cjs +0 -61
- package/dist/chunk-YREV3LGG.cjs.map +0 -1
- package/dist/chunk-YTXEZ4SD.cjs +0 -77
- package/dist/chunk-YTXEZ4SD.cjs.map +0 -1
- package/dist/chunk-YWCESU4Y.js +0 -1233
- package/dist/chunk-YWCESU4Y.js.map +0 -1
- package/dist/chunk-Z6HRSM2Y.cjs +0 -799
- package/dist/chunk-Z6HRSM2Y.cjs.map +0 -1
- package/dist/chunk-Z7PW3KHL.cjs +0 -1198
- package/dist/chunk-Z7PW3KHL.cjs.map +0 -1
- package/dist/chunk-ZNMBW67B.cjs +0 -40
- package/dist/chunk-ZNMBW67B.cjs.map +0 -1
- package/dist/correlation-id.cjs.map +0 -1
- package/dist/correlation-id.js.map +0 -1
- package/dist/event-subscriber.cjs.map +0 -1
- package/dist/event-subscriber.js.map +0 -1
- package/dist/event.cjs.map +0 -1
- package/dist/event.js.map +0 -1
- package/dist/exporters.cjs.map +0 -1
- package/dist/exporters.js.map +0 -1
- package/dist/functional.cjs.map +0 -1
- package/dist/functional.js.map +0 -1
- package/dist/init-DIowiiCh.d.ts +0 -1167
- package/dist/init-j-A1zI16.d.cts +0 -1167
- package/dist/processors.cjs.map +0 -1
- package/dist/processors.js.map +0 -1
- package/dist/trace-context-DbGKd1Rn.d.cts +0 -213
- package/dist/trace-context-DbGKd1Rn.d.ts +0 -213
- package/dist/utils-BahBCFtJ.d.cts +0 -712
- package/dist/utils-CLKwaUlG.d.ts +0 -712
- package/dist/yaml-config.cjs.map +0 -1
package/dist/metric.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"metric.js"}
|
|
1
|
+
{"version":3,"file":"metric.js","names":[],"sources":["../src/metric.ts"],"sourcesContent":["/**\n * Metrics API for OpenTelemetry\n *\n * Track business metrics for OpenTelemetry (Prometheus/Grafana).\n * For business people who think in metrics.\n *\n * @example Track business metrics\n * ```typescript\n * const metrics = new Metric('checkout')\n *\n * // Track events as metrics\n * metrics.trackEvent('order.completed', {\n * amount: 99.99,\n * currency: 'USD'\n * })\n *\n * // Track conversion funnels\n * metrics.trackFunnelStep('checkout', 'started', { cartValue: 99.99 })\n * metrics.trackFunnelStep('checkout', 'completed', { cartValue: 99.99 })\n *\n * // Track outcomes\n * metrics.trackOutcome('payment.process', 'success', { amount: 99.99 })\n * metrics.trackOutcome('payment.process', 'failure', { error: 'insufficient_funds' })\n *\n * // Track values\n * metrics.trackValue('revenue', 149.99, { currency: 'USD' })\n * ```\n */\n\nimport {\n type Counter,\n type Histogram,\n type Attributes,\n} from '@opentelemetry/api';\nimport { getConfig } from './config';\nimport { type Logger } from './logger';\nimport {\n type EventAttributes,\n type FunnelStatus,\n type OutcomeStatus,\n} from './event-subscriber';\nimport { type MetricsCollector } from './metric-testing';\n\n// Re-export types for convenience\nexport type {\n EventAttributes,\n FunnelStatus,\n OutcomeStatus,\n} from './event-subscriber';\n\n/**\n * Metrics class for tracking business metrics in OpenTelemetry\n *\n * Track critical business indicators such as:\n * - User events (signups, purchases, feature usage) as metrics\n * - Conversion funnels (signup → activation → purchase)\n * - Business outcomes (success/failure rates)\n * - Value metrics (revenue, counts, etc.)\n *\n * All metrics are sent to OpenTelemetry (OTLP/Prometheus/Grafana).\n */\n/**\n * Metric configuration for customizing metric names and descriptions\n */\nexport interface MetricConfig {\n /** Metric name (e.g., 'metrics.events' or 'custom.events') */\n name?: string;\n /** Metric description */\n description?: string;\n /** Metric unit (default: '1') */\n unit?: string;\n}\n\n/**\n * Metrics options\n */\nexport interface MetricsOptions {\n /** Optional logger for audit trail */\n logger?: Logger;\n /** Optional collector for testing (captures metrics in memory) */\n collector?: MetricsCollector;\n\n /**\n * Namespace for metrics (default: 'metrics')\n * Results in metrics like: {serviceName}.{namespace}.events\n */\n namespace?: string;\n\n /**\n * Custom metric configurations\n * Override metric names, descriptions, and units\n */\n metrics?: {\n events?: MetricConfig;\n funnel?: MetricConfig;\n outcomes?: MetricConfig;\n value?: MetricConfig;\n };\n}\n\nexport class Metric {\n private serviceName: string;\n private eventCounter: Counter;\n private funnelCounter: Counter;\n private outcomeCounter: Counter;\n private valueHistogram: Histogram;\n private logger?: Logger;\n private collector?: MetricsCollector;\n\n /**\n * Create a new Metrics instance\n *\n * @param serviceName - Service name for metric namespacing\n * @param options - Optional configuration (logger, collector, namespace, metrics)\n *\n * @example Basic usage (default 'metrics' namespace)\n * ```typescript\n * const metrics = new Metric('checkout');\n * // Creates: checkout.metrics.events, checkout.metrics.funnel, etc.\n * ```\n *\n * @example Custom namespace\n * ```typescript\n * const metrics = new Metric('api', { namespace: 'business' });\n * // Creates: api.business.events, api.business.funnel, etc.\n * ```\n *\n * @example Custom metric names and descriptions\n * ```typescript\n * const metrics = new Metric('payments', {\n * metrics: {\n * outcomes: {\n * name: 'payments.transactions',\n * description: 'Payment transaction outcomes',\n * unit: 'transactions'\n * },\n * value: {\n * name: 'payments.revenue',\n * description: 'Payment revenue in USD',\n * unit: 'USD'\n * }\n * }\n * });\n * ```\n */\n constructor(serviceName: string, options: MetricsOptions = {}) {\n this.serviceName = serviceName;\n this.logger = options.logger;\n this.collector = options.collector;\n\n const config = getConfig();\n const meter = config.meter;\n\n // Default namespace and metric configurations\n const namespace = options.namespace || 'metrics';\n const metricsConfig = options.metrics || {};\n\n // Event counter configuration\n const eventsConfig = metricsConfig.events || {};\n this.eventCounter = meter.createCounter(\n eventsConfig.name || `${serviceName}.${namespace}.events`,\n {\n description: eventsConfig.description || 'Count of business events',\n unit: eventsConfig.unit || '1',\n },\n );\n\n // Funnel counter configuration\n const funnelConfig = metricsConfig.funnel || {};\n this.funnelCounter = meter.createCounter(\n funnelConfig.name || `${serviceName}.${namespace}.funnel`,\n {\n description: funnelConfig.description || 'Conversion funnel tracking',\n unit: funnelConfig.unit || '1',\n },\n );\n\n // Outcome counter configuration\n const outcomesConfig = metricsConfig.outcomes || {};\n this.outcomeCounter = meter.createCounter(\n outcomesConfig.name || `${serviceName}.${namespace}.outcomes`,\n {\n description:\n outcomesConfig.description || 'Outcome tracking (success/failure)',\n unit: outcomesConfig.unit || '1',\n },\n );\n\n // Value histogram configuration\n const valueConfig = metricsConfig.value || {};\n this.valueHistogram = meter.createHistogram(\n valueConfig.name || `${serviceName}.${namespace}.value`,\n {\n description:\n valueConfig.description || 'Value metrics (revenue, counts, etc.)',\n unit: valueConfig.unit || '1',\n },\n );\n }\n\n /**\n * Track a business event as a metric\n *\n * Use this for tracking user actions, business events, product usage as metrics:\n * - \"user.signup\"\n * - \"order.completed\"\n * - \"feature.used\"\n *\n * @example\n * ```typescript\n * // Track user signup as metric\n * metrics.trackEvent('user.signup', {\n * userId: '123',\n * plan: 'pro'\n * })\n *\n * // Track order as metric\n * metrics.trackEvent('order.completed', {\n * orderId: 'ord_123',\n * amount: 99.99\n * })\n * ```\n */\n trackEvent(eventName: string, attributes?: EventAttributes): void {\n const attrs: Attributes = {\n service: this.serviceName,\n event: eventName,\n ...attributes,\n };\n\n this.eventCounter.add(1, attrs);\n\n this.logger?.info(\n {\n event: eventName,\n attributes,\n },\n 'Metric event tracked',\n );\n\n // Record for testing\n this.collector?.recordEvent({\n event: eventName,\n attributes,\n service: this.serviceName,\n timestamp: Date.now(),\n });\n }\n\n /**\n * Track conversion funnel steps as metrics\n *\n * Monitor where users drop off in multi-step processes.\n *\n * @example\n * ```typescript\n * // Track signup funnel\n * metrics.trackFunnelStep('signup', 'started', { userId: '123' })\n * metrics.trackFunnelStep('signup', 'email_verified', { userId: '123' })\n * metrics.trackFunnelStep('signup', 'completed', { userId: '123' })\n *\n * // Track checkout flow\n * metrics.trackFunnelStep('checkout', 'started', { cartValue: 99.99 })\n * metrics.trackFunnelStep('checkout', 'payment_info', { cartValue: 99.99 })\n * metrics.trackFunnelStep('checkout', 'completed', { cartValue: 99.99 })\n * ```\n */\n trackFunnelStep(\n funnelName: string,\n status: FunnelStatus,\n attributes?: EventAttributes,\n ): void {\n const attrs: Attributes = {\n service: this.serviceName,\n funnel: funnelName,\n status,\n ...attributes,\n };\n\n this.funnelCounter.add(1, attrs);\n\n this.logger?.info(\n {\n funnel: funnelName,\n status,\n attributes,\n },\n 'Funnel step tracked',\n );\n\n // Record for testing\n this.collector?.recordFunnelStep({\n funnel: funnelName,\n status,\n attributes,\n service: this.serviceName,\n timestamp: Date.now(),\n });\n }\n\n /**\n * Track outcomes (success/failure/partial) as metrics\n *\n * Monitor success rates of critical operations.\n *\n * @example\n * ```typescript\n * // Track email delivery\n * metrics.trackOutcome('email.delivery', 'success', {\n * recipientType: 'user',\n * emailType: 'welcome'\n * })\n *\n * metrics.trackOutcome('email.delivery', 'failure', {\n * recipientType: 'user',\n * errorCode: 'invalid_email'\n * })\n *\n * // Track payment processing\n * metrics.trackOutcome('payment.process', 'success', { amount: 99.99 })\n * metrics.trackOutcome('payment.process', 'failure', { error: 'insufficient_funds' })\n * ```\n */\n trackOutcome(\n operationName: string,\n status: OutcomeStatus,\n attributes?: EventAttributes,\n ): void {\n const attrs: Attributes = {\n service: this.serviceName,\n operation: operationName,\n status,\n ...attributes,\n };\n\n this.outcomeCounter.add(1, attrs);\n\n this.logger?.info(\n {\n operation: operationName,\n status,\n attributes,\n },\n 'Outcome tracked',\n );\n\n // Record for testing\n this.collector?.recordOutcome({\n operation: operationName,\n status,\n attributes,\n service: this.serviceName,\n timestamp: Date.now(),\n });\n }\n\n /**\n * Track value metrics\n *\n * Record numerical values like revenue, transaction amounts,\n * item counts, processing times, engagement scores, etc.\n *\n * @example\n * ```typescript\n * // Track revenue\n * metrics.trackValue('order.revenue', 149.99, {\n * currency: 'USD',\n * productCategory: 'electronics'\n * })\n *\n * // Track items per cart\n * metrics.trackValue('cart.item_count', 5, {\n * userId: '123'\n * })\n *\n * // Track processing time\n * metrics.trackValue('api.response_time', 250, {\n * unit: 'ms',\n * endpoint: '/api/checkout'\n * })\n * ```\n */\n trackValue(\n metricName: string,\n value: number,\n attributes?: EventAttributes,\n ): void {\n const attrs: Attributes = {\n service: this.serviceName,\n metric: metricName,\n ...attributes,\n };\n\n this.valueHistogram.record(value, attrs);\n\n this.logger?.debug(\n {\n metric: metricName,\n value,\n attributes,\n },\n 'Value metric tracked',\n );\n\n // Record for testing\n this.collector?.recordValue({\n metric: metricName,\n value,\n attributes,\n service: this.serviceName,\n timestamp: Date.now(),\n });\n }\n}\n\n/**\n * Global metrics instances (singleton pattern)\n */\nconst metricsInstances = new Map<string, Metric>();\n\n/**\n * Get or create a Metrics instance for a service\n *\n * @param serviceName - Service name for metric namespacing\n * @param logger - Optional logger\n * @returns Metrics instance\n *\n * @example\n * ```typescript\n * const metrics = getMetrics('checkout')\n * metrics.trackEvent('order.completed', { orderId: '123' })\n * ```\n */\nexport function getMetrics(serviceName: string, logger?: Logger): Metric {\n if (!metricsInstances.has(serviceName)) {\n metricsInstances.set(serviceName, new Metric(serviceName, { logger }));\n }\n return metricsInstances.get(serviceName)!;\n}\n\n/**\n * Reset all metrics instances (mainly for testing)\n */\nexport function resetMetrics(): void {\n metricsInstances.clear();\n}\n"],"mappings":";;;;AAoGA,IAAa,SAAb,MAAoB;CAClB,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCR,YAAY,aAAqB,UAA0B,CAAC,GAAG;EAC7D,KAAK,cAAc;EACnB,KAAK,SAAS,QAAQ;EACtB,KAAK,YAAY,QAAQ;EAGzB,MAAM,QADS,UACI,CAAC,CAAC;EAGrB,MAAM,YAAY,QAAQ,aAAa;EACvC,MAAM,gBAAgB,QAAQ,WAAW,CAAC;EAG1C,MAAM,eAAe,cAAc,UAAU,CAAC;EAC9C,KAAK,eAAe,MAAM,cACxB,aAAa,QAAQ,GAAG,YAAY,GAAG,UAAU,UACjD;GACE,aAAa,aAAa,eAAe;GACzC,MAAM,aAAa,QAAQ;EAC7B,CACF;EAGA,MAAM,eAAe,cAAc,UAAU,CAAC;EAC9C,KAAK,gBAAgB,MAAM,cACzB,aAAa,QAAQ,GAAG,YAAY,GAAG,UAAU,UACjD;GACE,aAAa,aAAa,eAAe;GACzC,MAAM,aAAa,QAAQ;EAC7B,CACF;EAGA,MAAM,iBAAiB,cAAc,YAAY,CAAC;EAClD,KAAK,iBAAiB,MAAM,cAC1B,eAAe,QAAQ,GAAG,YAAY,GAAG,UAAU,YACnD;GACE,aACE,eAAe,eAAe;GAChC,MAAM,eAAe,QAAQ;EAC/B,CACF;EAGA,MAAM,cAAc,cAAc,SAAS,CAAC;EAC5C,KAAK,iBAAiB,MAAM,gBAC1B,YAAY,QAAQ,GAAG,YAAY,GAAG,UAAU,SAChD;GACE,aACE,YAAY,eAAe;GAC7B,MAAM,YAAY,QAAQ;EAC5B,CACF;CACF;;;;;;;;;;;;;;;;;;;;;;;;CAyBA,WAAW,WAAmB,YAAoC;EAChE,MAAM,QAAoB;GACxB,SAAS,KAAK;GACd,OAAO;GACP,GAAG;EACL;EAEA,KAAK,aAAa,IAAI,GAAG,KAAK;EAE9B,KAAK,QAAQ,KACX;GACE,OAAO;GACP;EACF,GACA,sBACF;EAGA,KAAK,WAAW,YAAY;GAC1B,OAAO;GACP;GACA,SAAS,KAAK;GACd,WAAW,KAAK,IAAI;EACtB,CAAC;CACH;;;;;;;;;;;;;;;;;;;CAoBA,gBACE,YACA,QACA,YACM;EACN,MAAM,QAAoB;GACxB,SAAS,KAAK;GACd,QAAQ;GACR;GACA,GAAG;EACL;EAEA,KAAK,cAAc,IAAI,GAAG,KAAK;EAE/B,KAAK,QAAQ,KACX;GACE,QAAQ;GACR;GACA;EACF,GACA,qBACF;EAGA,KAAK,WAAW,iBAAiB;GAC/B,QAAQ;GACR;GACA;GACA,SAAS,KAAK;GACd,WAAW,KAAK,IAAI;EACtB,CAAC;CACH;;;;;;;;;;;;;;;;;;;;;;;;CAyBA,aACE,eACA,QACA,YACM;EACN,MAAM,QAAoB;GACxB,SAAS,KAAK;GACd,WAAW;GACX;GACA,GAAG;EACL;EAEA,KAAK,eAAe,IAAI,GAAG,KAAK;EAEhC,KAAK,QAAQ,KACX;GACE,WAAW;GACX;GACA;EACF,GACA,iBACF;EAGA,KAAK,WAAW,cAAc;GAC5B,WAAW;GACX;GACA;GACA,SAAS,KAAK;GACd,WAAW,KAAK,IAAI;EACtB,CAAC;CACH;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BA,WACE,YACA,OACA,YACM;EACN,MAAM,QAAoB;GACxB,SAAS,KAAK;GACd,QAAQ;GACR,GAAG;EACL;EAEA,KAAK,eAAe,OAAO,OAAO,KAAK;EAEvC,KAAK,QAAQ,MACX;GACE,QAAQ;GACR;GACA;EACF,GACA,sBACF;EAGA,KAAK,WAAW,YAAY;GAC1B,QAAQ;GACR;GACA;GACA,SAAS,KAAK;GACd,WAAW,KAAK,IAAI;EACtB,CAAC;CACH;AACF;;;;AAKA,MAAM,mCAAmB,IAAI,IAAoB;;;;;;;;;;;;;;AAejD,SAAgB,WAAW,aAAqB,QAAyB;CACvE,IAAI,CAAC,iBAAiB,IAAI,WAAW,GACnC,iBAAiB,IAAI,aAAa,IAAI,OAAO,aAAa,EAAE,OAAO,CAAC,CAAC;CAEvE,OAAO,iBAAiB,IAAI,WAAW;AACzC;;;;AAKA,SAAgB,eAAqB;CACnC,iBAAiB,MAAM;AACzB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
let node_module = require("node:module");
|
|
2
|
+
|
|
3
|
+
//#region src/node-require.ts
|
|
4
|
+
/**
|
|
5
|
+
* Cross-format require() helper for CJS and ESM compatibility
|
|
6
|
+
*
|
|
7
|
+
* Provides a synchronous `require()` function that works in both:
|
|
8
|
+
* - CJS builds: Uses native `require`
|
|
9
|
+
* - ESM builds: Uses `createRequire(import.meta.url)`
|
|
10
|
+
*
|
|
11
|
+
* This allows optional peer dependencies and dynamic module loading
|
|
12
|
+
* to work synchronously in both module formats.
|
|
13
|
+
*/
|
|
14
|
+
let cachedRequire;
|
|
15
|
+
function getNodeRequire() {
|
|
16
|
+
if (cachedRequire) return cachedRequire;
|
|
17
|
+
const base = typeof __filename === "string" ? __filename : require("url").pathToFileURL(__filename).href;
|
|
18
|
+
if (!base) throw Object.assign(/* @__PURE__ */ new Error("node require() is unavailable in this runtime"), { code: "MODULE_NOT_FOUND" });
|
|
19
|
+
cachedRequire = (0, node_module.createRequire)(base);
|
|
20
|
+
return cachedRequire;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Synchronously require a module (works in both CJS and ESM)
|
|
24
|
+
*
|
|
25
|
+
* @param id - Module ID to require
|
|
26
|
+
* @returns The required module
|
|
27
|
+
* @throws Error if module cannot be loaded
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { safeRequire } from './node-require';
|
|
32
|
+
*
|
|
33
|
+
* const traceloop = safeRequire('@traceloop/node-server-sdk');
|
|
34
|
+
* if (traceloop) {
|
|
35
|
+
* traceloop.initialize({ ... });
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function safeRequire(id) {
|
|
40
|
+
try {
|
|
41
|
+
return getNodeRequire()(id);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error && error.code === "MODULE_NOT_FOUND") return;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Synchronously require a module (throws if not found)
|
|
49
|
+
*
|
|
50
|
+
* Use this when the module is required (not optional).
|
|
51
|
+
*
|
|
52
|
+
* @param id - Module ID to require
|
|
53
|
+
* @returns The required module
|
|
54
|
+
* @throws Error if module cannot be loaded
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { requireModule } from './node-require';
|
|
59
|
+
*
|
|
60
|
+
* const fs = requireModule<typeof import('node:fs')>('node:fs');
|
|
61
|
+
* const content = fs.readFileSync('file.txt', 'utf8');
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function requireModule(id) {
|
|
65
|
+
return getNodeRequire()(id);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Direct access to the nodeRequire function (for advanced use cases).
|
|
69
|
+
*
|
|
70
|
+
* Lazily resolves the underlying Node `require` on first call, so importing
|
|
71
|
+
* this binding never triggers `createRequire` in runtimes that lack a module
|
|
72
|
+
* path (e.g. Cloudflare Workers).
|
|
73
|
+
*
|
|
74
|
+
* Only the call signature and `resolve` (including `resolve.paths`) are
|
|
75
|
+
* forwarded. The live, mutable members of a real `require` — `.cache`,
|
|
76
|
+
* `.main`, `.extensions` — are intentionally NOT exposed: a lazy wrapper
|
|
77
|
+
* can't mirror that shared state without resolving eagerly, which would
|
|
78
|
+
* reintroduce the workerd crash. Use `createRequire` directly if you need
|
|
79
|
+
* them.
|
|
80
|
+
*/
|
|
81
|
+
const nodeRequire = ((id) => getNodeRequire()(id));
|
|
82
|
+
const lazyResolve = ((id, options) => getNodeRequire().resolve(id, options));
|
|
83
|
+
lazyResolve.paths = (request) => getNodeRequire().resolve.paths(request);
|
|
84
|
+
nodeRequire.resolve = lazyResolve;
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
Object.defineProperty(exports, 'requireModule', {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return requireModule;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, 'safeRequire', {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function () {
|
|
96
|
+
return safeRequire;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=node-require-DF5QBX6z.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-require-DF5QBX6z.cjs","names":[],"sources":["../src/node-require.ts"],"sourcesContent":["/**\n * Cross-format require() helper for CJS and ESM compatibility\n *\n * Provides a synchronous `require()` function that works in both:\n * - CJS builds: Uses native `require`\n * - ESM builds: Uses `createRequire(import.meta.url)`\n *\n * This allows optional peer dependencies and dynamic module loading\n * to work synchronously in both module formats.\n */\n\nimport { createRequire } from 'node:module';\n\n// `__filename` is provided by CJS and by esbuild's CJS output wrapper, but\n// is undefined under pure ESM. `import.meta.url` is provided by ESM. Pick\n// whichever is available so the helper works in:\n// - native CJS (autotel's published `.cjs`)\n// - native ESM (autotel's published `.js`)\n// - ESM-bundled-into-CJS by a downstream consumer (e.g. CDK's\n// `aws-lambda-nodejs` → esbuild with `format: cjs`). esbuild rewrites\n// `import.meta` to `{}` in this case, so `createRequire(import.meta.url)`\n// alone collapses to `createRequire(undefined)` and crashes at load.\n// `typeof __filename` does NOT throw when the identifier is undeclared, so\n// the ESM build evaluates the conditional safely.\ndeclare const __filename: string | undefined;\n\n// Build the Node `require` lazily on first use. Calling `createRequire`\n// eagerly at module load crashes in runtimes where neither `__filename` nor\n// `import.meta.url` resolves to a path — e.g. Cloudflare Workers / workerd,\n// where the bundle has no module path and `createRequire(undefined)` throws\n// synchronously at import. Deferring the call keeps merely importing this\n// module (and therefore anything that re-exports it, such as `track`)\n// side-effect-free; Node/CJS/ESM still get a real `require` on first call.\nlet cachedRequire: NodeRequire | undefined;\n\nfunction getNodeRequire(): NodeRequire {\n if (cachedRequire) return cachedRequire;\n const base = typeof __filename === 'string' ? __filename : import.meta.url;\n if (!base) {\n // No module path in this runtime. Surface as a missing-module error so\n // optional lookups via `safeRequire()` degrade gracefully to `undefined`.\n throw Object.assign(\n new Error('node require() is unavailable in this runtime'),\n { code: 'MODULE_NOT_FOUND' },\n );\n }\n cachedRequire = createRequire(base);\n return cachedRequire;\n}\n\n/**\n * Synchronously require a module (works in both CJS and ESM)\n *\n * @param id - Module ID to require\n * @returns The required module\n * @throws Error if module cannot be loaded\n *\n * @example\n * ```typescript\n * import { safeRequire } from './node-require';\n *\n * const traceloop = safeRequire('@traceloop/node-server-sdk');\n * if (traceloop) {\n * traceloop.initialize({ ... });\n * }\n * ```\n */\nexport function safeRequire<T = unknown>(id: string): T | undefined {\n try {\n return getNodeRequire()(id) as T;\n } catch (error) {\n if (error && (error as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n // Optional dependency missing – return undefined\n return undefined;\n }\n // Any other error is a real bug: rethrow\n throw error;\n }\n}\n\n/**\n * Synchronously require a module (throws if not found)\n *\n * Use this when the module is required (not optional).\n *\n * @param id - Module ID to require\n * @returns The required module\n * @throws Error if module cannot be loaded\n *\n * @example\n * ```typescript\n * import { requireModule } from './node-require';\n *\n * const fs = requireModule<typeof import('node:fs')>('node:fs');\n * const content = fs.readFileSync('file.txt', 'utf8');\n * ```\n */\nexport function requireModule<T = unknown>(id: string): T {\n return getNodeRequire()(id) as T;\n}\n\n/**\n * Direct access to the nodeRequire function (for advanced use cases).\n *\n * Lazily resolves the underlying Node `require` on first call, so importing\n * this binding never triggers `createRequire` in runtimes that lack a module\n * path (e.g. Cloudflare Workers).\n *\n * Only the call signature and `resolve` (including `resolve.paths`) are\n * forwarded. The live, mutable members of a real `require` — `.cache`,\n * `.main`, `.extensions` — are intentionally NOT exposed: a lazy wrapper\n * can't mirror that shared state without resolving eagerly, which would\n * reintroduce the workerd crash. Use `createRequire` directly if you need\n * them.\n */\nconst nodeRequire = ((id: string) => getNodeRequire()(id)) as NodeRequire;\nconst lazyResolve = ((id: string, options?: { paths?: string[] }) =>\n getNodeRequire().resolve(id, options)) as NodeRequire['resolve'];\nlazyResolve.paths = (request: string) =>\n getNodeRequire().resolve.paths(request);\nnodeRequire.resolve = lazyResolve;\n\nexport { nodeRequire };\n"],"mappings":";;;;;;;;;;;;;AAiCA,IAAI;AAEJ,SAAS,iBAA8B;CACrC,IAAI,eAAe,OAAO;CAC1B,MAAM,OAAO,OAAO,eAAe,WAAW;CAC9C,IAAI,CAAC,MAGH,MAAM,OAAO,uBACX,IAAI,MAAM,+CAA+C,GACzD,EAAE,MAAM,mBAAmB,CAC7B;CAEF,+CAA8B,IAAI;CAClC,OAAO;AACT;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,YAAyB,IAA2B;CAClE,IAAI;EACF,OAAO,eAAe,CAAC,CAAC,EAAE;CAC5B,SAAS,OAAO;EACd,IAAI,SAAU,MAAgC,SAAS,oBAErD;EAGF,MAAM;CACR;AACF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,cAA2B,IAAe;CACxD,OAAO,eAAe,CAAC,CAAC,EAAE;AAC5B;;;;;;;;;;;;;;;AAgBA,MAAM,gBAAgB,OAAe,eAAe,CAAC,CAAC,EAAE;AACxD,MAAM,gBAAgB,IAAY,YAChC,eAAe,CAAC,CAAC,QAAQ,IAAI,OAAO;AACtC,YAAY,SAAS,YACnB,eAAe,CAAC,CAAC,QAAQ,MAAM,OAAO;AACxC,YAAY,UAAU"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region src/node-require.ts
|
|
4
|
+
/**
|
|
5
|
+
* Cross-format require() helper for CJS and ESM compatibility
|
|
6
|
+
*
|
|
7
|
+
* Provides a synchronous `require()` function that works in both:
|
|
8
|
+
* - CJS builds: Uses native `require`
|
|
9
|
+
* - ESM builds: Uses `createRequire(import.meta.url)`
|
|
10
|
+
*
|
|
11
|
+
* This allows optional peer dependencies and dynamic module loading
|
|
12
|
+
* to work synchronously in both module formats.
|
|
13
|
+
*/
|
|
14
|
+
let cachedRequire;
|
|
15
|
+
function getNodeRequire() {
|
|
16
|
+
if (cachedRequire) return cachedRequire;
|
|
17
|
+
const base = typeof __filename === "string" ? __filename : import.meta.url;
|
|
18
|
+
if (!base) throw Object.assign(/* @__PURE__ */ new Error("node require() is unavailable in this runtime"), { code: "MODULE_NOT_FOUND" });
|
|
19
|
+
cachedRequire = createRequire(base);
|
|
20
|
+
return cachedRequire;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Synchronously require a module (works in both CJS and ESM)
|
|
24
|
+
*
|
|
25
|
+
* @param id - Module ID to require
|
|
26
|
+
* @returns The required module
|
|
27
|
+
* @throws Error if module cannot be loaded
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { safeRequire } from './node-require';
|
|
32
|
+
*
|
|
33
|
+
* const traceloop = safeRequire('@traceloop/node-server-sdk');
|
|
34
|
+
* if (traceloop) {
|
|
35
|
+
* traceloop.initialize({ ... });
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function safeRequire(id) {
|
|
40
|
+
try {
|
|
41
|
+
return getNodeRequire()(id);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error && error.code === "MODULE_NOT_FOUND") return;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Synchronously require a module (throws if not found)
|
|
49
|
+
*
|
|
50
|
+
* Use this when the module is required (not optional).
|
|
51
|
+
*
|
|
52
|
+
* @param id - Module ID to require
|
|
53
|
+
* @returns The required module
|
|
54
|
+
* @throws Error if module cannot be loaded
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { requireModule } from './node-require';
|
|
59
|
+
*
|
|
60
|
+
* const fs = requireModule<typeof import('node:fs')>('node:fs');
|
|
61
|
+
* const content = fs.readFileSync('file.txt', 'utf8');
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function requireModule(id) {
|
|
65
|
+
return getNodeRequire()(id);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Direct access to the nodeRequire function (for advanced use cases).
|
|
69
|
+
*
|
|
70
|
+
* Lazily resolves the underlying Node `require` on first call, so importing
|
|
71
|
+
* this binding never triggers `createRequire` in runtimes that lack a module
|
|
72
|
+
* path (e.g. Cloudflare Workers).
|
|
73
|
+
*
|
|
74
|
+
* Only the call signature and `resolve` (including `resolve.paths`) are
|
|
75
|
+
* forwarded. The live, mutable members of a real `require` — `.cache`,
|
|
76
|
+
* `.main`, `.extensions` — are intentionally NOT exposed: a lazy wrapper
|
|
77
|
+
* can't mirror that shared state without resolving eagerly, which would
|
|
78
|
+
* reintroduce the workerd crash. Use `createRequire` directly if you need
|
|
79
|
+
* them.
|
|
80
|
+
*/
|
|
81
|
+
const nodeRequire = ((id) => getNodeRequire()(id));
|
|
82
|
+
const lazyResolve = ((id, options) => getNodeRequire().resolve(id, options));
|
|
83
|
+
lazyResolve.paths = (request) => getNodeRequire().resolve.paths(request);
|
|
84
|
+
nodeRequire.resolve = lazyResolve;
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { safeRequire as n, requireModule as t };
|
|
88
|
+
//# sourceMappingURL=node-require-Db1oDpLj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-require-Db1oDpLj.js","names":[],"sources":["../src/node-require.ts"],"sourcesContent":["/**\n * Cross-format require() helper for CJS and ESM compatibility\n *\n * Provides a synchronous `require()` function that works in both:\n * - CJS builds: Uses native `require`\n * - ESM builds: Uses `createRequire(import.meta.url)`\n *\n * This allows optional peer dependencies and dynamic module loading\n * to work synchronously in both module formats.\n */\n\nimport { createRequire } from 'node:module';\n\n// `__filename` is provided by CJS and by esbuild's CJS output wrapper, but\n// is undefined under pure ESM. `import.meta.url` is provided by ESM. Pick\n// whichever is available so the helper works in:\n// - native CJS (autotel's published `.cjs`)\n// - native ESM (autotel's published `.js`)\n// - ESM-bundled-into-CJS by a downstream consumer (e.g. CDK's\n// `aws-lambda-nodejs` → esbuild with `format: cjs`). esbuild rewrites\n// `import.meta` to `{}` in this case, so `createRequire(import.meta.url)`\n// alone collapses to `createRequire(undefined)` and crashes at load.\n// `typeof __filename` does NOT throw when the identifier is undeclared, so\n// the ESM build evaluates the conditional safely.\ndeclare const __filename: string | undefined;\n\n// Build the Node `require` lazily on first use. Calling `createRequire`\n// eagerly at module load crashes in runtimes where neither `__filename` nor\n// `import.meta.url` resolves to a path — e.g. Cloudflare Workers / workerd,\n// where the bundle has no module path and `createRequire(undefined)` throws\n// synchronously at import. Deferring the call keeps merely importing this\n// module (and therefore anything that re-exports it, such as `track`)\n// side-effect-free; Node/CJS/ESM still get a real `require` on first call.\nlet cachedRequire: NodeRequire | undefined;\n\nfunction getNodeRequire(): NodeRequire {\n if (cachedRequire) return cachedRequire;\n const base = typeof __filename === 'string' ? __filename : import.meta.url;\n if (!base) {\n // No module path in this runtime. Surface as a missing-module error so\n // optional lookups via `safeRequire()` degrade gracefully to `undefined`.\n throw Object.assign(\n new Error('node require() is unavailable in this runtime'),\n { code: 'MODULE_NOT_FOUND' },\n );\n }\n cachedRequire = createRequire(base);\n return cachedRequire;\n}\n\n/**\n * Synchronously require a module (works in both CJS and ESM)\n *\n * @param id - Module ID to require\n * @returns The required module\n * @throws Error if module cannot be loaded\n *\n * @example\n * ```typescript\n * import { safeRequire } from './node-require';\n *\n * const traceloop = safeRequire('@traceloop/node-server-sdk');\n * if (traceloop) {\n * traceloop.initialize({ ... });\n * }\n * ```\n */\nexport function safeRequire<T = unknown>(id: string): T | undefined {\n try {\n return getNodeRequire()(id) as T;\n } catch (error) {\n if (error && (error as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n // Optional dependency missing – return undefined\n return undefined;\n }\n // Any other error is a real bug: rethrow\n throw error;\n }\n}\n\n/**\n * Synchronously require a module (throws if not found)\n *\n * Use this when the module is required (not optional).\n *\n * @param id - Module ID to require\n * @returns The required module\n * @throws Error if module cannot be loaded\n *\n * @example\n * ```typescript\n * import { requireModule } from './node-require';\n *\n * const fs = requireModule<typeof import('node:fs')>('node:fs');\n * const content = fs.readFileSync('file.txt', 'utf8');\n * ```\n */\nexport function requireModule<T = unknown>(id: string): T {\n return getNodeRequire()(id) as T;\n}\n\n/**\n * Direct access to the nodeRequire function (for advanced use cases).\n *\n * Lazily resolves the underlying Node `require` on first call, so importing\n * this binding never triggers `createRequire` in runtimes that lack a module\n * path (e.g. Cloudflare Workers).\n *\n * Only the call signature and `resolve` (including `resolve.paths`) are\n * forwarded. The live, mutable members of a real `require` — `.cache`,\n * `.main`, `.extensions` — are intentionally NOT exposed: a lazy wrapper\n * can't mirror that shared state without resolving eagerly, which would\n * reintroduce the workerd crash. Use `createRequire` directly if you need\n * them.\n */\nconst nodeRequire = ((id: string) => getNodeRequire()(id)) as NodeRequire;\nconst lazyResolve = ((id: string, options?: { paths?: string[] }) =>\n getNodeRequire().resolve(id, options)) as NodeRequire['resolve'];\nlazyResolve.paths = (request: string) =>\n getNodeRequire().resolve.paths(request);\nnodeRequire.resolve = lazyResolve;\n\nexport { nodeRequire };\n"],"mappings":";;;;;;;;;;;;;AAiCA,IAAI;AAEJ,SAAS,iBAA8B;CACrC,IAAI,eAAe,OAAO;CAC1B,MAAM,OAAO,OAAO,eAAe,WAAW,aAAa,OAAO,KAAK;CACvE,IAAI,CAAC,MAGH,MAAM,OAAO,uBACX,IAAI,MAAM,+CAA+C,GACzD,EAAE,MAAM,mBAAmB,CAC7B;CAEF,gBAAgB,cAAc,IAAI;CAClC,OAAO;AACT;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,YAAyB,IAA2B;CAClE,IAAI;EACF,OAAO,eAAe,CAAC,CAAC,EAAE;CAC5B,SAAS,OAAO;EACd,IAAI,SAAU,MAAgC,SAAS,oBAErD;EAGF,MAAM;CACR;AACF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,cAA2B,IAAe;CACxD,OAAO,eAAe,CAAC,CAAC,EAAE;AAC5B;;;;;;;;;;;;;;;AAgBA,MAAM,gBAAgB,OAAe,eAAe,CAAC,CAAC,EAAE;AACxD,MAAM,gBAAgB,IAAY,YAChC,eAAe,CAAC,CAAC,QAAQ,IAAI,OAAO;AACtC,YAAY,SAAS,YACnB,eAAe,CAAC,CAAC,QAAQ,MAAM,OAAO;AACxC,YAAY,UAAU"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
|
|
3
|
+
//#region src/operation-context.ts
|
|
4
|
+
/**
|
|
5
|
+
* Operation context tracking using AsyncLocalStorage
|
|
6
|
+
*
|
|
7
|
+
* This module provides a way to track operation names across async boundaries
|
|
8
|
+
* so they can be automatically captured in events events.
|
|
9
|
+
*
|
|
10
|
+
* We cannot read span attributes from OpenTelemetry's API (it's write-only),
|
|
11
|
+
* so we maintain our own async context storage.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* AsyncLocalStorage instance for tracking operation context
|
|
15
|
+
*/
|
|
16
|
+
const operationStorage = new AsyncLocalStorage();
|
|
17
|
+
/**
|
|
18
|
+
* Get the current operation context (if any)
|
|
19
|
+
*
|
|
20
|
+
* @returns The current operation context, or undefined if not in an operation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const ctx = getOperationContext();
|
|
25
|
+
* if (ctx) {
|
|
26
|
+
* console.log('Current operation:', ctx.name);
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function getOperationContext() {
|
|
31
|
+
return operationStorage.getStore();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Run a function within an operation context
|
|
35
|
+
*
|
|
36
|
+
* This sets the operation name for the duration of the function execution,
|
|
37
|
+
* including all async operations spawned from it.
|
|
38
|
+
*
|
|
39
|
+
* @param name - The operation name to set
|
|
40
|
+
* @param fn - The function to execute within the context
|
|
41
|
+
* @returns The result of the function
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const result = await runInOperationContext('user.create', async () => {
|
|
46
|
+
* // Any events.trackEvent() calls here will automatically capture
|
|
47
|
+
* // 'operation.name': 'user.create'
|
|
48
|
+
* await createUser();
|
|
49
|
+
* return 'success';
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
function runInOperationContext(name, fn) {
|
|
54
|
+
return operationStorage.run({ name }, fn);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { runInOperationContext as n, getOperationContext as t };
|
|
59
|
+
//# sourceMappingURL=operation-context-C-2hmmtP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-context-C-2hmmtP.js","names":[],"sources":["../src/operation-context.ts"],"sourcesContent":["/**\n * Operation context tracking using AsyncLocalStorage\n *\n * This module provides a way to track operation names across async boundaries\n * so they can be automatically captured in events events.\n *\n * We cannot read span attributes from OpenTelemetry's API (it's write-only),\n * so we maintain our own async context storage.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\n/**\n * Operation context that flows through async operations\n */\nexport interface OperationContext {\n /**\n * The name of the current operation\n * This is set by trace() or span() and can be read by events\n */\n name: string;\n}\n\n/**\n * AsyncLocalStorage instance for tracking operation context\n */\nconst operationStorage = new AsyncLocalStorage<OperationContext>();\n\n/**\n * Get the current operation context (if any)\n *\n * @returns The current operation context, or undefined if not in an operation\n *\n * @example\n * ```typescript\n * const ctx = getOperationContext();\n * if (ctx) {\n * console.log('Current operation:', ctx.name);\n * }\n * ```\n */\nexport function getOperationContext(): OperationContext | undefined {\n return operationStorage.getStore();\n}\n\n/**\n * Run a function within an operation context\n *\n * This sets the operation name for the duration of the function execution,\n * including all async operations spawned from it.\n *\n * @param name - The operation name to set\n * @param fn - The function to execute within the context\n * @returns The result of the function\n *\n * @example\n * ```typescript\n * const result = await runInOperationContext('user.create', async () => {\n * // Any events.trackEvent() calls here will automatically capture\n * // 'operation.name': 'user.create'\n * await createUser();\n * return 'success';\n * });\n * ```\n */\nexport function runInOperationContext<T>(name: string, fn: () => T): T {\n return operationStorage.run({ name }, fn);\n}\n\n/**\n * Update the operation name in the current context\n *\n * This is useful when you want to change the operation name within\n * an already-established context (e.g., when entering a nested span).\n *\n * @param name - The new operation name\n *\n * @example\n * ```typescript\n * runInOperationContext('parent.operation', () => {\n * // operation.name is 'parent.operation'\n *\n * updateOperationName('nested.operation');\n * // operation.name is now 'nested.operation'\n * });\n * ```\n */\nexport function updateOperationName(name: string): void {\n const store = operationStorage.getStore();\n if (store) {\n store.name = name;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,mBAAmB,IAAI,kBAAoC;;;;;;;;;;;;;;AAejE,SAAgB,sBAAoD;CAClE,OAAO,iBAAiB,SAAS;AACnC;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,sBAAyB,MAAc,IAAgB;CACrE,OAAO,iBAAiB,IAAI,EAAE,KAAK,GAAG,EAAE;AAC1C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
let node_async_hooks = require("node:async_hooks");
|
|
2
|
+
|
|
3
|
+
//#region src/operation-context.ts
|
|
4
|
+
/**
|
|
5
|
+
* Operation context tracking using AsyncLocalStorage
|
|
6
|
+
*
|
|
7
|
+
* This module provides a way to track operation names across async boundaries
|
|
8
|
+
* so they can be automatically captured in events events.
|
|
9
|
+
*
|
|
10
|
+
* We cannot read span attributes from OpenTelemetry's API (it's write-only),
|
|
11
|
+
* so we maintain our own async context storage.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* AsyncLocalStorage instance for tracking operation context
|
|
15
|
+
*/
|
|
16
|
+
const operationStorage = new node_async_hooks.AsyncLocalStorage();
|
|
17
|
+
/**
|
|
18
|
+
* Get the current operation context (if any)
|
|
19
|
+
*
|
|
20
|
+
* @returns The current operation context, or undefined if not in an operation
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const ctx = getOperationContext();
|
|
25
|
+
* if (ctx) {
|
|
26
|
+
* console.log('Current operation:', ctx.name);
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function getOperationContext() {
|
|
31
|
+
return operationStorage.getStore();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Run a function within an operation context
|
|
35
|
+
*
|
|
36
|
+
* This sets the operation name for the duration of the function execution,
|
|
37
|
+
* including all async operations spawned from it.
|
|
38
|
+
*
|
|
39
|
+
* @param name - The operation name to set
|
|
40
|
+
* @param fn - The function to execute within the context
|
|
41
|
+
* @returns The result of the function
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const result = await runInOperationContext('user.create', async () => {
|
|
46
|
+
* // Any events.trackEvent() calls here will automatically capture
|
|
47
|
+
* // 'operation.name': 'user.create'
|
|
48
|
+
* await createUser();
|
|
49
|
+
* return 'success';
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
function runInOperationContext(name, fn) {
|
|
54
|
+
return operationStorage.run({ name }, fn);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
Object.defineProperty(exports, 'getOperationContext', {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () {
|
|
61
|
+
return getOperationContext;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, 'runInOperationContext', {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return runInOperationContext;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=operation-context-n4_obUwq.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-context-n4_obUwq.cjs","names":["AsyncLocalStorage"],"sources":["../src/operation-context.ts"],"sourcesContent":["/**\n * Operation context tracking using AsyncLocalStorage\n *\n * This module provides a way to track operation names across async boundaries\n * so they can be automatically captured in events events.\n *\n * We cannot read span attributes from OpenTelemetry's API (it's write-only),\n * so we maintain our own async context storage.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\n/**\n * Operation context that flows through async operations\n */\nexport interface OperationContext {\n /**\n * The name of the current operation\n * This is set by trace() or span() and can be read by events\n */\n name: string;\n}\n\n/**\n * AsyncLocalStorage instance for tracking operation context\n */\nconst operationStorage = new AsyncLocalStorage<OperationContext>();\n\n/**\n * Get the current operation context (if any)\n *\n * @returns The current operation context, or undefined if not in an operation\n *\n * @example\n * ```typescript\n * const ctx = getOperationContext();\n * if (ctx) {\n * console.log('Current operation:', ctx.name);\n * }\n * ```\n */\nexport function getOperationContext(): OperationContext | undefined {\n return operationStorage.getStore();\n}\n\n/**\n * Run a function within an operation context\n *\n * This sets the operation name for the duration of the function execution,\n * including all async operations spawned from it.\n *\n * @param name - The operation name to set\n * @param fn - The function to execute within the context\n * @returns The result of the function\n *\n * @example\n * ```typescript\n * const result = await runInOperationContext('user.create', async () => {\n * // Any events.trackEvent() calls here will automatically capture\n * // 'operation.name': 'user.create'\n * await createUser();\n * return 'success';\n * });\n * ```\n */\nexport function runInOperationContext<T>(name: string, fn: () => T): T {\n return operationStorage.run({ name }, fn);\n}\n\n/**\n * Update the operation name in the current context\n *\n * This is useful when you want to change the operation name within\n * an already-established context (e.g., when entering a nested span).\n *\n * @param name - The new operation name\n *\n * @example\n * ```typescript\n * runInOperationContext('parent.operation', () => {\n * // operation.name is 'parent.operation'\n *\n * updateOperationName('nested.operation');\n * // operation.name is now 'nested.operation'\n * });\n * ```\n */\nexport function updateOperationName(name: string): void {\n const store = operationStorage.getStore();\n if (store) {\n store.name = name;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,mBAAmB,IAAIA,mCAAoC;;;;;;;;;;;;;;AAejE,SAAgB,sBAAoD;CAClE,OAAO,iBAAiB,SAAS;AACnC;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,sBAAyB,MAAc,IAAgB;CACrE,OAAO,iBAAiB,IAAI,EAAE,KAAK,GAAG,EAAE;AAC1C"}
|
package/dist/parse-error.cjs
CHANGED
|
@@ -1,12 +1,58 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/parse-error.ts
|
|
4
|
+
function toStatus(value) {
|
|
5
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
const n = Number(value);
|
|
8
|
+
if (Number.isFinite(n)) return n;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function pickString(value) {
|
|
12
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
13
|
+
}
|
|
14
|
+
function pickCode(value) {
|
|
15
|
+
if (typeof value === "string" || typeof value === "number") return value;
|
|
16
|
+
}
|
|
17
|
+
function pickDetails(value) {
|
|
18
|
+
if (value && typeof value === "object" && value.constructor === Object) return value;
|
|
19
|
+
}
|
|
20
|
+
function parseError(error) {
|
|
21
|
+
if (error instanceof Error) {
|
|
22
|
+
const structured = error;
|
|
23
|
+
return {
|
|
24
|
+
message: error.message || "An error occurred",
|
|
25
|
+
status: toStatus(structured.status) ?? 500,
|
|
26
|
+
why: pickString(structured.why),
|
|
27
|
+
fix: pickString(structured.fix),
|
|
28
|
+
link: pickString(structured.link),
|
|
29
|
+
code: pickCode(structured.code),
|
|
30
|
+
details: pickDetails(structured.details),
|
|
31
|
+
raw: error
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (error && typeof error === "object") {
|
|
35
|
+
const err = error;
|
|
36
|
+
const data = err.data && typeof err.data === "object" ? err.data : void 0;
|
|
37
|
+
const payload = (data?.data && typeof data.data === "object" ? data.data : void 0) ?? data;
|
|
38
|
+
return {
|
|
39
|
+
message: pickString(data?.statusText) || pickString(data?.statusMessage) || pickString(data?.message) || pickString(payload?.statusText) || pickString(payload?.statusMessage) || pickString(payload?.message) || pickString(err.message) || "An error occurred",
|
|
40
|
+
status: toStatus(payload?.status) || toStatus(payload?.statusCode) || toStatus(err.status) || toStatus(err.statusCode) || 500,
|
|
41
|
+
why: pickString(payload?.why) || pickString(err.why),
|
|
42
|
+
fix: pickString(payload?.fix) || pickString(err.fix),
|
|
43
|
+
link: pickString(payload?.link) || pickString(err.link),
|
|
44
|
+
code: pickCode(payload?.code) || pickCode(err.code),
|
|
45
|
+
details: pickDetails(payload?.details) || pickDetails(err.details),
|
|
46
|
+
raw: error
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
message: String(error),
|
|
51
|
+
status: 500,
|
|
52
|
+
raw: error
|
|
53
|
+
};
|
|
54
|
+
}
|
|
4
55
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "parseError", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () { return chunkT4B5LB6E_cjs.parseError; }
|
|
10
|
-
});
|
|
11
|
-
//# sourceMappingURL=parse-error.cjs.map
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.parseError = parseError;
|
|
12
58
|
//# sourceMappingURL=parse-error.cjs.map
|
package/dist/parse-error.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"parse-error.cjs","names":[],"sources":["../src/parse-error.ts"],"sourcesContent":["import type { StructuredError } from './structured-error';\n\nexport interface ParsedError {\n message: string;\n status: number;\n why?: string;\n fix?: string;\n link?: string;\n code?: string | number;\n details?: Record<string, unknown>;\n raw: unknown;\n}\n\ntype ErrorLike = {\n message?: unknown;\n status?: unknown;\n statusCode?: unknown;\n data?: unknown;\n code?: unknown;\n why?: unknown;\n fix?: unknown;\n link?: unknown;\n details?: unknown;\n};\n\nfunction toStatus(value: unknown): number | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) return value;\n if (typeof value === 'string') {\n const n = Number(value);\n if (Number.isFinite(n)) return n;\n }\n return undefined;\n}\n\nfunction pickString(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction pickCode(value: unknown): string | number | undefined {\n if (typeof value === 'string' || typeof value === 'number') return value;\n return undefined;\n}\n\nfunction pickDetails(value: unknown): Record<string, unknown> | undefined {\n if (value && typeof value === 'object' && value.constructor === Object) {\n return value as Record<string, unknown>;\n }\n return undefined;\n}\n\nexport function parseError(error: unknown): ParsedError {\n if (error instanceof Error) {\n const structured = error as StructuredError;\n return {\n message: error.message || 'An error occurred',\n status: toStatus(structured.status) ?? 500,\n why: pickString(structured.why),\n fix: pickString(structured.fix),\n link: pickString(structured.link),\n code: pickCode(structured.code),\n details: pickDetails(structured.details),\n raw: error,\n };\n }\n\n if (error && typeof error === 'object') {\n const err = error as ErrorLike;\n const data =\n err.data && typeof err.data === 'object'\n ? (err.data as Record<string, unknown>)\n : undefined;\n const nested =\n data?.data && typeof data.data === 'object'\n ? (data.data as Record<string, unknown>)\n : undefined;\n const payload = nested ?? data;\n\n const message =\n pickString(data?.statusText) ||\n pickString(data?.statusMessage) ||\n pickString(data?.message) ||\n pickString(payload?.statusText) ||\n pickString(payload?.statusMessage) ||\n pickString(payload?.message) ||\n pickString(err.message) ||\n 'An error occurred';\n\n const status =\n toStatus(payload?.status) ||\n toStatus(payload?.statusCode) ||\n toStatus(err.status) ||\n toStatus(err.statusCode) ||\n 500;\n\n return {\n message,\n status,\n why: pickString(payload?.why) || pickString(err.why),\n fix: pickString(payload?.fix) || pickString(err.fix),\n link: pickString(payload?.link) || pickString(err.link),\n code: pickCode(payload?.code) || pickCode(err.code),\n details: pickDetails(payload?.details) || pickDetails(err.details),\n raw: error,\n };\n }\n\n return {\n message: String(error),\n status: 500,\n raw: error,\n };\n}\n"],"mappings":";;;AAyBA,SAAS,SAAS,OAAoC;CACpD,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG,OAAO;CAChE,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,IAAI,OAAO,KAAK;EACtB,IAAI,OAAO,SAAS,CAAC,GAAG,OAAO;CACjC;AAEF;AAEA,SAAS,WAAW,OAAoC;CACtD,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAS,SAAS,OAA6C;CAC7D,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAU,OAAO;AAErE;AAEA,SAAS,YAAY,OAAqD;CACxE,IAAI,SAAS,OAAO,UAAU,YAAY,MAAM,gBAAgB,QAC9D,OAAO;AAGX;AAEA,SAAgB,WAAW,OAA6B;CACtD,IAAI,iBAAiB,OAAO;EAC1B,MAAM,aAAa;EACnB,OAAO;GACL,SAAS,MAAM,WAAW;GAC1B,QAAQ,SAAS,WAAW,MAAM,KAAK;GACvC,KAAK,WAAW,WAAW,GAAG;GAC9B,KAAK,WAAW,WAAW,GAAG;GAC9B,MAAM,WAAW,WAAW,IAAI;GAChC,MAAM,SAAS,WAAW,IAAI;GAC9B,SAAS,YAAY,WAAW,OAAO;GACvC,KAAK;EACP;CACF;CAEA,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,MAAM;EACZ,MAAM,OACJ,IAAI,QAAQ,OAAO,IAAI,SAAS,WAC3B,IAAI,OACL;EAKN,MAAM,WAHJ,MAAM,QAAQ,OAAO,KAAK,SAAS,WAC9B,KAAK,OACN,WACoB;EAmB1B,OAAO;GACL,SAjBA,WAAW,MAAM,UAAU,KAC3B,WAAW,MAAM,aAAa,KAC9B,WAAW,MAAM,OAAO,KACxB,WAAW,SAAS,UAAU,KAC9B,WAAW,SAAS,aAAa,KACjC,WAAW,SAAS,OAAO,KAC3B,WAAW,IAAI,OAAO,KACtB;GAWA,QARA,SAAS,SAAS,MAAM,KACxB,SAAS,SAAS,UAAU,KAC5B,SAAS,IAAI,MAAM,KACnB,SAAS,IAAI,UAAU,KACvB;GAKA,KAAK,WAAW,SAAS,GAAG,KAAK,WAAW,IAAI,GAAG;GACnD,KAAK,WAAW,SAAS,GAAG,KAAK,WAAW,IAAI,GAAG;GACnD,MAAM,WAAW,SAAS,IAAI,KAAK,WAAW,IAAI,IAAI;GACtD,MAAM,SAAS,SAAS,IAAI,KAAK,SAAS,IAAI,IAAI;GAClD,SAAS,YAAY,SAAS,OAAO,KAAK,YAAY,IAAI,OAAO;GACjE,KAAK;EACP;CACF;CAEA,OAAO;EACL,SAAS,OAAO,KAAK;EACrB,QAAQ;EACR,KAAK;CACP;AACF"}
|
package/dist/parse-error.d.cts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
//#region src/parse-error.d.ts
|
|
1
2
|
interface ParsedError {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
message: string;
|
|
4
|
+
status: number;
|
|
5
|
+
why?: string;
|
|
6
|
+
fix?: string;
|
|
7
|
+
link?: string;
|
|
8
|
+
code?: string | number;
|
|
9
|
+
details?: Record<string, unknown>;
|
|
10
|
+
raw: unknown;
|
|
10
11
|
}
|
|
11
12
|
declare function parseError(error: unknown): ParsedError;
|
|
12
|
-
|
|
13
|
-
export {
|
|
13
|
+
//#endregion
|
|
14
|
+
export { ParsedError, parseError };
|
|
15
|
+
//# sourceMappingURL=parse-error.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-error.d.cts","names":[],"sources":["../src/parse-error.ts"],"mappings":";UAEiB,WAAA;EACf,OAAA;EACA,MAAA;EACA,GAAA;EACA,GAAA;EACA,IAAA;EACA,IAAA;EACA,OAAA,GAAU,MAAM;EAChB,GAAA;AAAA;AAAA,iBAwCc,UAAA,CAAW,KAAA,YAAiB,WAAW"}
|
package/dist/parse-error.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
//#region src/parse-error.d.ts
|
|
1
2
|
interface ParsedError {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
message: string;
|
|
4
|
+
status: number;
|
|
5
|
+
why?: string;
|
|
6
|
+
fix?: string;
|
|
7
|
+
link?: string;
|
|
8
|
+
code?: string | number;
|
|
9
|
+
details?: Record<string, unknown>;
|
|
10
|
+
raw: unknown;
|
|
10
11
|
}
|
|
11
12
|
declare function parseError(error: unknown): ParsedError;
|
|
12
|
-
|
|
13
|
-
export {
|
|
13
|
+
//#endregion
|
|
14
|
+
export { ParsedError, parseError };
|
|
15
|
+
//# sourceMappingURL=parse-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-error.d.ts","names":[],"sources":["../src/parse-error.ts"],"mappings":";UAEiB,WAAA;EACf,OAAA;EACA,MAAA;EACA,GAAA;EACA,GAAA;EACA,IAAA;EACA,IAAA;EACA,OAAA,GAAU,MAAM;EAChB,GAAA;AAAA;AAAA,iBAwCc,UAAA,CAAW,KAAA,YAAiB,WAAW"}
|
package/dist/parse-error.js
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/parse-error.ts
|
|
2
|
+
function toStatus(value) {
|
|
3
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
4
|
+
if (typeof value === "string") {
|
|
5
|
+
const n = Number(value);
|
|
6
|
+
if (Number.isFinite(n)) return n;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function pickString(value) {
|
|
10
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
11
|
+
}
|
|
12
|
+
function pickCode(value) {
|
|
13
|
+
if (typeof value === "string" || typeof value === "number") return value;
|
|
14
|
+
}
|
|
15
|
+
function pickDetails(value) {
|
|
16
|
+
if (value && typeof value === "object" && value.constructor === Object) return value;
|
|
17
|
+
}
|
|
18
|
+
function parseError(error) {
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
const structured = error;
|
|
21
|
+
return {
|
|
22
|
+
message: error.message || "An error occurred",
|
|
23
|
+
status: toStatus(structured.status) ?? 500,
|
|
24
|
+
why: pickString(structured.why),
|
|
25
|
+
fix: pickString(structured.fix),
|
|
26
|
+
link: pickString(structured.link),
|
|
27
|
+
code: pickCode(structured.code),
|
|
28
|
+
details: pickDetails(structured.details),
|
|
29
|
+
raw: error
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (error && typeof error === "object") {
|
|
33
|
+
const err = error;
|
|
34
|
+
const data = err.data && typeof err.data === "object" ? err.data : void 0;
|
|
35
|
+
const payload = (data?.data && typeof data.data === "object" ? data.data : void 0) ?? data;
|
|
36
|
+
return {
|
|
37
|
+
message: pickString(data?.statusText) || pickString(data?.statusMessage) || pickString(data?.message) || pickString(payload?.statusText) || pickString(payload?.statusMessage) || pickString(payload?.message) || pickString(err.message) || "An error occurred",
|
|
38
|
+
status: toStatus(payload?.status) || toStatus(payload?.statusCode) || toStatus(err.status) || toStatus(err.statusCode) || 500,
|
|
39
|
+
why: pickString(payload?.why) || pickString(err.why),
|
|
40
|
+
fix: pickString(payload?.fix) || pickString(err.fix),
|
|
41
|
+
link: pickString(payload?.link) || pickString(err.link),
|
|
42
|
+
code: pickCode(payload?.code) || pickCode(err.code),
|
|
43
|
+
details: pickDetails(payload?.details) || pickDetails(err.details),
|
|
44
|
+
raw: error
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
message: String(error),
|
|
49
|
+
status: 500,
|
|
50
|
+
raw: error
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { parseError };
|
|
3
56
|
//# sourceMappingURL=parse-error.js.map
|
package/dist/parse-error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"parse-error.js","names":[],"sources":["../src/parse-error.ts"],"sourcesContent":["import type { StructuredError } from './structured-error';\n\nexport interface ParsedError {\n message: string;\n status: number;\n why?: string;\n fix?: string;\n link?: string;\n code?: string | number;\n details?: Record<string, unknown>;\n raw: unknown;\n}\n\ntype ErrorLike = {\n message?: unknown;\n status?: unknown;\n statusCode?: unknown;\n data?: unknown;\n code?: unknown;\n why?: unknown;\n fix?: unknown;\n link?: unknown;\n details?: unknown;\n};\n\nfunction toStatus(value: unknown): number | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) return value;\n if (typeof value === 'string') {\n const n = Number(value);\n if (Number.isFinite(n)) return n;\n }\n return undefined;\n}\n\nfunction pickString(value: unknown): string | undefined {\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\nfunction pickCode(value: unknown): string | number | undefined {\n if (typeof value === 'string' || typeof value === 'number') return value;\n return undefined;\n}\n\nfunction pickDetails(value: unknown): Record<string, unknown> | undefined {\n if (value && typeof value === 'object' && value.constructor === Object) {\n return value as Record<string, unknown>;\n }\n return undefined;\n}\n\nexport function parseError(error: unknown): ParsedError {\n if (error instanceof Error) {\n const structured = error as StructuredError;\n return {\n message: error.message || 'An error occurred',\n status: toStatus(structured.status) ?? 500,\n why: pickString(structured.why),\n fix: pickString(structured.fix),\n link: pickString(structured.link),\n code: pickCode(structured.code),\n details: pickDetails(structured.details),\n raw: error,\n };\n }\n\n if (error && typeof error === 'object') {\n const err = error as ErrorLike;\n const data =\n err.data && typeof err.data === 'object'\n ? (err.data as Record<string, unknown>)\n : undefined;\n const nested =\n data?.data && typeof data.data === 'object'\n ? (data.data as Record<string, unknown>)\n : undefined;\n const payload = nested ?? data;\n\n const message =\n pickString(data?.statusText) ||\n pickString(data?.statusMessage) ||\n pickString(data?.message) ||\n pickString(payload?.statusText) ||\n pickString(payload?.statusMessage) ||\n pickString(payload?.message) ||\n pickString(err.message) ||\n 'An error occurred';\n\n const status =\n toStatus(payload?.status) ||\n toStatus(payload?.statusCode) ||\n toStatus(err.status) ||\n toStatus(err.statusCode) ||\n 500;\n\n return {\n message,\n status,\n why: pickString(payload?.why) || pickString(err.why),\n fix: pickString(payload?.fix) || pickString(err.fix),\n link: pickString(payload?.link) || pickString(err.link),\n code: pickCode(payload?.code) || pickCode(err.code),\n details: pickDetails(payload?.details) || pickDetails(err.details),\n raw: error,\n };\n }\n\n return {\n message: String(error),\n status: 500,\n raw: error,\n };\n}\n"],"mappings":";AAyBA,SAAS,SAAS,OAAoC;CACpD,IAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,GAAG,OAAO;CAChE,IAAI,OAAO,UAAU,UAAU;EAC7B,MAAM,IAAI,OAAO,KAAK;EACtB,IAAI,OAAO,SAAS,CAAC,GAAG,OAAO;CACjC;AAEF;AAEA,SAAS,WAAW,OAAoC;CACtD,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAS,SAAS,OAA6C;CAC7D,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAU,OAAO;AAErE;AAEA,SAAS,YAAY,OAAqD;CACxE,IAAI,SAAS,OAAO,UAAU,YAAY,MAAM,gBAAgB,QAC9D,OAAO;AAGX;AAEA,SAAgB,WAAW,OAA6B;CACtD,IAAI,iBAAiB,OAAO;EAC1B,MAAM,aAAa;EACnB,OAAO;GACL,SAAS,MAAM,WAAW;GAC1B,QAAQ,SAAS,WAAW,MAAM,KAAK;GACvC,KAAK,WAAW,WAAW,GAAG;GAC9B,KAAK,WAAW,WAAW,GAAG;GAC9B,MAAM,WAAW,WAAW,IAAI;GAChC,MAAM,SAAS,WAAW,IAAI;GAC9B,SAAS,YAAY,WAAW,OAAO;GACvC,KAAK;EACP;CACF;CAEA,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,MAAM;EACZ,MAAM,OACJ,IAAI,QAAQ,OAAO,IAAI,SAAS,WAC3B,IAAI,OACL;EAKN,MAAM,WAHJ,MAAM,QAAQ,OAAO,KAAK,SAAS,WAC9B,KAAK,OACN,WACoB;EAmB1B,OAAO;GACL,SAjBA,WAAW,MAAM,UAAU,KAC3B,WAAW,MAAM,aAAa,KAC9B,WAAW,MAAM,OAAO,KACxB,WAAW,SAAS,UAAU,KAC9B,WAAW,SAAS,aAAa,KACjC,WAAW,SAAS,OAAO,KAC3B,WAAW,IAAI,OAAO,KACtB;GAWA,QARA,SAAS,SAAS,MAAM,KACxB,SAAS,SAAS,UAAU,KAC5B,SAAS,IAAI,MAAM,KACnB,SAAS,IAAI,UAAU,KACvB;GAKA,KAAK,WAAW,SAAS,GAAG,KAAK,WAAW,IAAI,GAAG;GACnD,KAAK,WAAW,SAAS,GAAG,KAAK,WAAW,IAAI,GAAG;GACnD,MAAM,WAAW,SAAS,IAAI,KAAK,WAAW,IAAI,IAAI;GACtD,MAAM,SAAS,SAAS,IAAI,KAAK,SAAS,IAAI,IAAI;GAClD,SAAS,YAAY,SAAS,OAAO,KAAK,YAAY,IAAI,OAAO;GACjE,KAAK;EACP;CACF;CAEA,OAAO;EACL,SAAS,OAAO,KAAK;EACrB,QAAQ;EACR,KAAK;CACP;AACF"}
|