@sakeetech/viva-payments-core 0.2.1
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 +21 -0
- package/README.md +413 -0
- package/dist/auth/http.d.ts +44 -0
- package/dist/auth/http.d.ts.map +1 -0
- package/dist/auth/http.js +80 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/index.d.ts +19 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +18 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/oauth2-strategy.d.ts +117 -0
- package/dist/auth/oauth2-strategy.d.ts.map +1 -0
- package/dist/auth/oauth2-strategy.js +217 -0
- package/dist/auth/oauth2-strategy.js.map +1 -0
- package/dist/auth/reseller-strategy.d.ts +65 -0
- package/dist/auth/reseller-strategy.d.ts.map +1 -0
- package/dist/auth/reseller-strategy.js +68 -0
- package/dist/auth/reseller-strategy.js.map +1 -0
- package/dist/auth/single-flight.d.ts +81 -0
- package/dist/auth/single-flight.d.ts.map +1 -0
- package/dist/auth/single-flight.js +160 -0
- package/dist/auth/single-flight.js.map +1 -0
- package/dist/auth/token-cache.d.ts +50 -0
- package/dist/auth/token-cache.d.ts.map +1 -0
- package/dist/auth/token-cache.js +59 -0
- package/dist/auth/token-cache.js.map +1 -0
- package/dist/errors/api-error.d.ts +15 -0
- package/dist/errors/api-error.d.ts.map +1 -0
- package/dist/errors/api-error.js +18 -0
- package/dist/errors/api-error.js.map +1 -0
- package/dist/errors/auth-error.d.ts +14 -0
- package/dist/errors/auth-error.d.ts.map +1 -0
- package/dist/errors/auth-error.js +17 -0
- package/dist/errors/auth-error.js.map +1 -0
- package/dist/errors/base.d.ts +59 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +51 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/index.d.ts +18 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +16 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/mode-mismatch-error.d.ts +19 -0
- package/dist/errors/mode-mismatch-error.d.ts.map +1 -0
- package/dist/errors/mode-mismatch-error.js +22 -0
- package/dist/errors/mode-mismatch-error.js.map +1 -0
- package/dist/errors/rate-limit-error.d.ts +20 -0
- package/dist/errors/rate-limit-error.d.ts.map +1 -0
- package/dist/errors/rate-limit-error.js +20 -0
- package/dist/errors/rate-limit-error.js.map +1 -0
- package/dist/errors/validation-error.d.ts +14 -0
- package/dist/errors/validation-error.d.ts.map +1 -0
- package/dist/errors/validation-error.js +17 -0
- package/dist/errors/validation-error.js.map +1 -0
- package/dist/errors/webhook-error.d.ts +14 -0
- package/dist/errors/webhook-error.d.ts.map +1 -0
- package/dist/errors/webhook-error.js +17 -0
- package/dist/errors/webhook-error.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/isv/accounts.d.ts +38 -0
- package/dist/isv/accounts.d.ts.map +1 -0
- package/dist/isv/accounts.js +60 -0
- package/dist/isv/accounts.js.map +1 -0
- package/dist/isv/client.d.ts +187 -0
- package/dist/isv/client.d.ts.map +1 -0
- package/dist/isv/client.js +465 -0
- package/dist/isv/client.js.map +1 -0
- package/dist/isv/index.d.ts +52 -0
- package/dist/isv/index.d.ts.map +1 -0
- package/dist/isv/index.js +53 -0
- package/dist/isv/index.js.map +1 -0
- package/dist/isv/legacy-basic-client.d.ts +122 -0
- package/dist/isv/legacy-basic-client.d.ts.map +1 -0
- package/dist/isv/legacy-basic-client.js +281 -0
- package/dist/isv/legacy-basic-client.js.map +1 -0
- package/dist/isv/payments.d.ts +199 -0
- package/dist/isv/payments.d.ts.map +1 -0
- package/dist/isv/payments.js +385 -0
- package/dist/isv/payments.js.map +1 -0
- package/dist/isv/sources.d.ts +80 -0
- package/dist/isv/sources.d.ts.map +1 -0
- package/dist/isv/sources.js +112 -0
- package/dist/isv/sources.js.map +1 -0
- package/dist/isv/webhooks-api.d.ts +48 -0
- package/dist/isv/webhooks-api.d.ts.map +1 -0
- package/dist/isv/webhooks-api.js +66 -0
- package/dist/isv/webhooks-api.js.map +1 -0
- package/dist/legacy/client.d.ts +199 -0
- package/dist/legacy/client.d.ts.map +1 -0
- package/dist/legacy/client.js +351 -0
- package/dist/legacy/client.js.map +1 -0
- package/dist/legacy/index.d.ts +15 -0
- package/dist/legacy/index.d.ts.map +1 -0
- package/dist/legacy/index.js +14 -0
- package/dist/legacy/index.js.map +1 -0
- package/dist/observability/context.d.ts +30 -0
- package/dist/observability/context.d.ts.map +1 -0
- package/dist/observability/context.js +40 -0
- package/dist/observability/context.js.map +1 -0
- package/dist/observability/index.d.ts +15 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +11 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/logger.d.ts +81 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +127 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +37 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +40 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/redact.d.ts +21 -0
- package/dist/observability/redact.d.ts.map +1 -0
- package/dist/observability/redact.js +72 -0
- package/dist/observability/redact.js.map +1 -0
- package/dist/observability/tracer.d.ts +25 -0
- package/dist/observability/tracer.d.ts.map +1 -0
- package/dist/observability/tracer.js +18 -0
- package/dist/observability/tracer.js.map +1 -0
- package/dist/payments/client.d.ts +247 -0
- package/dist/payments/client.d.ts.map +1 -0
- package/dist/payments/client.js +488 -0
- package/dist/payments/client.js.map +1 -0
- package/dist/payments/index.d.ts +14 -0
- package/dist/payments/index.d.ts.map +1 -0
- package/dist/payments/index.js +13 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/refunds/fast-refund-client.d.ts +128 -0
- package/dist/refunds/fast-refund-client.d.ts.map +1 -0
- package/dist/refunds/fast-refund-client.js +138 -0
- package/dist/refunds/fast-refund-client.js.map +1 -0
- package/dist/refunds/index.d.ts +19 -0
- package/dist/refunds/index.d.ts.map +1 -0
- package/dist/refunds/index.js +17 -0
- package/dist/refunds/index.js.map +1 -0
- package/dist/refunds/strategy.d.ts +78 -0
- package/dist/refunds/strategy.d.ts.map +1 -0
- package/dist/refunds/strategy.js +75 -0
- package/dist/refunds/strategy.js.map +1 -0
- package/dist/types/auth.d.ts +80 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +12 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/card-types.d.ts +48 -0
- package/dist/types/card-types.d.ts.map +1 -0
- package/dist/types/card-types.js +62 -0
- package/dist/types/card-types.js.map +1 -0
- package/dist/types/common.d.ts +160 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +70 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/isv-accounts.d.ts +109 -0
- package/dist/types/isv-accounts.d.ts.map +1 -0
- package/dist/types/isv-accounts.js +22 -0
- package/dist/types/isv-accounts.js.map +1 -0
- package/dist/types/isv-payments.d.ts +262 -0
- package/dist/types/isv-payments.d.ts.map +1 -0
- package/dist/types/isv-payments.js +19 -0
- package/dist/types/isv-payments.js.map +1 -0
- package/dist/types/status.d.ts +125 -0
- package/dist/types/status.d.ts.map +1 -0
- package/dist/types/status.js +19 -0
- package/dist/types/status.js.map +1 -0
- package/dist/types/webhook-events.d.ts +447 -0
- package/dist/types/webhook-events.d.ts.map +1 -0
- package/dist/types/webhook-events.js +76 -0
- package/dist/types/webhook-events.js.map +1 -0
- package/dist/webhooks/challenge-response.d.ts +28 -0
- package/dist/webhooks/challenge-response.d.ts.map +1 -0
- package/dist/webhooks/challenge-response.js +35 -0
- package/dist/webhooks/challenge-response.js.map +1 -0
- package/dist/webhooks/event-types.d.ts +44 -0
- package/dist/webhooks/event-types.d.ts.map +1 -0
- package/dist/webhooks/event-types.js +50 -0
- package/dist/webhooks/event-types.js.map +1 -0
- package/dist/webhooks/extract-client-ip.d.ts +40 -0
- package/dist/webhooks/extract-client-ip.d.ts.map +1 -0
- package/dist/webhooks/extract-client-ip.js +72 -0
- package/dist/webhooks/extract-client-ip.js.map +1 -0
- package/dist/webhooks/hmac-verify.d.ts +38 -0
- package/dist/webhooks/hmac-verify.d.ts.map +1 -0
- package/dist/webhooks/hmac-verify.js +92 -0
- package/dist/webhooks/hmac-verify.js.map +1 -0
- package/dist/webhooks/index.d.ts +19 -0
- package/dist/webhooks/index.d.ts.map +1 -0
- package/dist/webhooks/index.js +19 -0
- package/dist/webhooks/index.js.map +1 -0
- package/dist/webhooks/ip-allowlist.d.ts +59 -0
- package/dist/webhooks/ip-allowlist.d.ts.map +1 -0
- package/dist/webhooks/ip-allowlist.js +147 -0
- package/dist/webhooks/ip-allowlist.js.map +1 -0
- package/dist/webhooks/status-lattice.d.ts +72 -0
- package/dist/webhooks/status-lattice.d.ts.map +1 -0
- package/dist/webhooks/status-lattice.js +208 -0
- package/dist/webhooks/status-lattice.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* viva-payments-core/legacy — barrel export.
|
|
3
|
+
*
|
|
4
|
+
* Subpath: `viva-payments-core/legacy`
|
|
5
|
+
*
|
|
6
|
+
* BasicAuthClient covers Viva's legacy host endpoints (Basic auth +
|
|
7
|
+
* MerchantId/ApiKey). Currently the only path that works for refunds —
|
|
8
|
+
* Viva returns 405 on the v2/OAuth2 refund route.
|
|
9
|
+
*
|
|
10
|
+
* @see references/viva-docs/md/tut-create-recurring-payment.txt:288
|
|
11
|
+
* @see references/viva-docs/md/merchant-id-and-api-key.txt:1
|
|
12
|
+
*/
|
|
13
|
+
export { BasicAuthClient } from './client.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/legacy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* context.ts — ObservabilityContext composite type and defaultContext() factory.
|
|
3
|
+
*
|
|
4
|
+
* The SaaS wrapper builds one ObservabilityContext at startup and threads it
|
|
5
|
+
* through provider construction. defaultContext() returns a fully-wired
|
|
6
|
+
* context suitable for standalone use (StructuredJsonLogger → stdout, etc.).
|
|
7
|
+
*
|
|
8
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 observability)
|
|
9
|
+
*/
|
|
10
|
+
import type { Logger } from './logger.js';
|
|
11
|
+
import type { MetricsHook } from './metrics.js';
|
|
12
|
+
import type { OTelTracerHook } from './tracer.js';
|
|
13
|
+
export interface ObservabilityContext {
|
|
14
|
+
readonly logger: Logger;
|
|
15
|
+
readonly metrics: MetricsHook;
|
|
16
|
+
readonly tracer: OTelTracerHook;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns a ready-to-use ObservabilityContext with:
|
|
20
|
+
* - StructuredJsonLogger (stdout) wrapped in RedactingLogger
|
|
21
|
+
* - NoopMetricsHook (replaced by PromMetricsHook in medusa package)
|
|
22
|
+
* - NoopTracerHook
|
|
23
|
+
*/
|
|
24
|
+
export declare function defaultContext(): ObservabilityContext;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a silent ObservabilityContext suitable for tests.
|
|
27
|
+
* Suppresses all log output; metrics are no-op.
|
|
28
|
+
*/
|
|
29
|
+
export declare function silentContext(): ObservabilityContext;
|
|
30
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/observability/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASlD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;CACjC;AAMD;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,oBAAoB,CAMrD;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,oBAAoB,CAMpD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* context.ts — ObservabilityContext composite type and defaultContext() factory.
|
|
3
|
+
*
|
|
4
|
+
* The SaaS wrapper builds one ObservabilityContext at startup and threads it
|
|
5
|
+
* through provider construction. defaultContext() returns a fully-wired
|
|
6
|
+
* context suitable for standalone use (StructuredJsonLogger → stdout, etc.).
|
|
7
|
+
*
|
|
8
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 observability)
|
|
9
|
+
*/
|
|
10
|
+
import { StructuredJsonLogger, RedactingLogger, SilentLogger } from './logger.js';
|
|
11
|
+
import { NoopMetricsHook } from './metrics.js';
|
|
12
|
+
import { NoopTracerHook } from './tracer.js';
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// defaultContext
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
/**
|
|
17
|
+
* Returns a ready-to-use ObservabilityContext with:
|
|
18
|
+
* - StructuredJsonLogger (stdout) wrapped in RedactingLogger
|
|
19
|
+
* - NoopMetricsHook (replaced by PromMetricsHook in medusa package)
|
|
20
|
+
* - NoopTracerHook
|
|
21
|
+
*/
|
|
22
|
+
export function defaultContext() {
|
|
23
|
+
return {
|
|
24
|
+
logger: new RedactingLogger(new StructuredJsonLogger()),
|
|
25
|
+
metrics: new NoopMetricsHook(),
|
|
26
|
+
tracer: new NoopTracerHook(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns a silent ObservabilityContext suitable for tests.
|
|
31
|
+
* Suppresses all log output; metrics are no-op.
|
|
32
|
+
*/
|
|
33
|
+
export function silentContext() {
|
|
34
|
+
return {
|
|
35
|
+
logger: new SilentLogger(),
|
|
36
|
+
metrics: new NoopMetricsHook(),
|
|
37
|
+
tracer: new NoopTracerHook(),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/observability/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAY7C,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO;QACL,MAAM,EAAE,IAAI,eAAe,CAAC,IAAI,oBAAoB,EAAE,CAAC;QACvD,OAAO,EAAE,IAAI,eAAe,EAAE;QAC9B,MAAM,EAAE,IAAI,cAAc,EAAE;KAC7B,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO;QACL,MAAM,EAAE,IAAI,YAAY,EAAE;QAC1B,OAAO,EAAE,IAAI,eAAe,EAAE;QAC9B,MAAM,EAAE,IAAI,cAAc,EAAE;KAC7B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* viva-payments-core/observability — barrel re-exports.
|
|
3
|
+
*
|
|
4
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 observability)
|
|
5
|
+
*/
|
|
6
|
+
export type { LogContext, Logger } from './logger.js';
|
|
7
|
+
export { StructuredJsonLogger, RedactingLogger, SilentLogger } from './logger.js';
|
|
8
|
+
export type { MetricLabels, MetricsHook } from './metrics.js';
|
|
9
|
+
export { NoopMetricsHook } from './metrics.js';
|
|
10
|
+
export type { OTelTracerHook } from './tracer.js';
|
|
11
|
+
export { NoopTracerHook } from './tracer.js';
|
|
12
|
+
export type { ObservabilityContext } from './context.js';
|
|
13
|
+
export { defaultContext, silentContext } from './context.js';
|
|
14
|
+
export { redact } from './redact.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAElF,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* viva-payments-core/observability — barrel re-exports.
|
|
3
|
+
*
|
|
4
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 observability)
|
|
5
|
+
*/
|
|
6
|
+
export { StructuredJsonLogger, RedactingLogger, SilentLogger } from './logger.js';
|
|
7
|
+
export { NoopMetricsHook } from './metrics.js';
|
|
8
|
+
export { NoopTracerHook } from './tracer.js';
|
|
9
|
+
export { defaultContext, silentContext } from './context.js';
|
|
10
|
+
export { redact } from './redact.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/observability/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGlF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logger.ts — Structured JSON logger types and implementations.
|
|
3
|
+
*
|
|
4
|
+
* Logger interface mandated by P16:
|
|
5
|
+
* - debug / info / warn / error with LogContext
|
|
6
|
+
* - child() for bound-context loggers
|
|
7
|
+
*
|
|
8
|
+
* StructuredJsonLogger: emits one JSON line per call to stdout.
|
|
9
|
+
* - bigint values serialized to string
|
|
10
|
+
* - Error causes serialized to { name, message, stack }
|
|
11
|
+
*
|
|
12
|
+
* RedactingLogger: wraps another logger; redacts PCI fields from ctx before
|
|
13
|
+
* forwarding via redact() from redact.ts.
|
|
14
|
+
*
|
|
15
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 observability)
|
|
16
|
+
*/
|
|
17
|
+
export interface LogContext {
|
|
18
|
+
trace_id?: string;
|
|
19
|
+
tenant_id?: string;
|
|
20
|
+
viva_merchant_id?: string;
|
|
21
|
+
/** bigint serialized to string for log lines */
|
|
22
|
+
viva_order_code?: string;
|
|
23
|
+
viva_transaction_id?: string;
|
|
24
|
+
event_type_id?: number;
|
|
25
|
+
[k: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface Logger {
|
|
28
|
+
debug(msg: string, ctx?: LogContext): void;
|
|
29
|
+
info(msg: string, ctx?: LogContext): void;
|
|
30
|
+
warn(msg: string, ctx?: LogContext): void;
|
|
31
|
+
error(msg: string, ctx?: LogContext & {
|
|
32
|
+
cause?: unknown;
|
|
33
|
+
}): void;
|
|
34
|
+
/** Returns a new logger with these fields auto-merged into every log call. */
|
|
35
|
+
child(bind: LogContext): Logger;
|
|
36
|
+
}
|
|
37
|
+
export declare class SilentLogger implements Logger {
|
|
38
|
+
debug(_msg: string, _ctx?: LogContext): void;
|
|
39
|
+
info(_msg: string, _ctx?: LogContext): void;
|
|
40
|
+
warn(_msg: string, _ctx?: LogContext): void;
|
|
41
|
+
error(_msg: string, _ctx?: LogContext & {
|
|
42
|
+
cause?: unknown;
|
|
43
|
+
}): void;
|
|
44
|
+
child(_bind: LogContext): Logger;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Emits to stdout one JSON object per line.
|
|
48
|
+
* Bigints → string. Errors → { name, message, stack }.
|
|
49
|
+
*/
|
|
50
|
+
export declare class StructuredJsonLogger implements Logger {
|
|
51
|
+
private readonly _bound;
|
|
52
|
+
private readonly _out;
|
|
53
|
+
constructor(opts?: {
|
|
54
|
+
bound?: LogContext;
|
|
55
|
+
out?: (line: string) => void;
|
|
56
|
+
});
|
|
57
|
+
debug(msg: string, ctx?: LogContext): void;
|
|
58
|
+
info(msg: string, ctx?: LogContext): void;
|
|
59
|
+
warn(msg: string, ctx?: LogContext): void;
|
|
60
|
+
error(msg: string, ctx?: LogContext & {
|
|
61
|
+
cause?: unknown;
|
|
62
|
+
}): void;
|
|
63
|
+
child(bind: LogContext): Logger;
|
|
64
|
+
private _emit;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Wraps another logger; redacts known PCI fields from ctx.* before forwarding.
|
|
68
|
+
*/
|
|
69
|
+
export declare class RedactingLogger implements Logger {
|
|
70
|
+
private readonly _inner;
|
|
71
|
+
constructor(_inner: Logger);
|
|
72
|
+
debug(msg: string, ctx?: LogContext): void;
|
|
73
|
+
info(msg: string, ctx?: LogContext): void;
|
|
74
|
+
warn(msg: string, ctx?: LogContext): void;
|
|
75
|
+
error(msg: string, ctx?: LogContext & {
|
|
76
|
+
cause?: unknown;
|
|
77
|
+
}): void;
|
|
78
|
+
child(bind: LogContext): Logger;
|
|
79
|
+
private _redactCtx;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/observability/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gDAAgD;IAChD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AAMD,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC3C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1C,KAAK,CAAC,GAAG,EAAE,MAAM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O,CAAA;KAAE,GAAG,IAAI;IAIhE,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAO/B,OAAO,CAAC,KAAK;CAgBd;AAMD;;GAEG;AACH,qBAAa,eAAgB,YAAW,MAAM;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI;IAI1C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI;IAIzC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI;IAIzC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAIhE,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAI/B,OAAO,CAAC,UAAU;CAInB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logger.ts — Structured JSON logger types and implementations.
|
|
3
|
+
*
|
|
4
|
+
* Logger interface mandated by P16:
|
|
5
|
+
* - debug / info / warn / error with LogContext
|
|
6
|
+
* - child() for bound-context loggers
|
|
7
|
+
*
|
|
8
|
+
* StructuredJsonLogger: emits one JSON line per call to stdout.
|
|
9
|
+
* - bigint values serialized to string
|
|
10
|
+
* - Error causes serialized to { name, message, stack }
|
|
11
|
+
*
|
|
12
|
+
* RedactingLogger: wraps another logger; redacts PCI fields from ctx before
|
|
13
|
+
* forwarding via redact() from redact.ts.
|
|
14
|
+
*
|
|
15
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 observability)
|
|
16
|
+
*/
|
|
17
|
+
import { redact } from './redact.js';
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// No-op logger (for tests)
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
export class SilentLogger {
|
|
22
|
+
debug(_msg, _ctx) { }
|
|
23
|
+
info(_msg, _ctx) { }
|
|
24
|
+
warn(_msg, _ctx) { }
|
|
25
|
+
error(_msg, _ctx) { }
|
|
26
|
+
child(_bind) { return this; }
|
|
27
|
+
}
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Bigint-safe JSON serializer
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
function bigintSafeReplacer(_key, val) {
|
|
32
|
+
if (typeof val === 'bigint')
|
|
33
|
+
return val.toString();
|
|
34
|
+
if (val instanceof Error) {
|
|
35
|
+
return {
|
|
36
|
+
name: val.name,
|
|
37
|
+
message: val.message,
|
|
38
|
+
stack: val.stack?.slice(0, 2000),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return val;
|
|
42
|
+
}
|
|
43
|
+
function serialize(obj) {
|
|
44
|
+
return JSON.stringify(obj, bigintSafeReplacer);
|
|
45
|
+
}
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// StructuredJsonLogger
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
/**
|
|
50
|
+
* Emits to stdout one JSON object per line.
|
|
51
|
+
* Bigints → string. Errors → { name, message, stack }.
|
|
52
|
+
*/
|
|
53
|
+
export class StructuredJsonLogger {
|
|
54
|
+
_bound;
|
|
55
|
+
_out;
|
|
56
|
+
constructor(opts) {
|
|
57
|
+
this._bound = opts?.bound ?? {};
|
|
58
|
+
this._out = opts?.out ?? ((line) => process.stdout.write(line + '\n'));
|
|
59
|
+
}
|
|
60
|
+
debug(msg, ctx) {
|
|
61
|
+
this._emit('debug', msg, ctx);
|
|
62
|
+
}
|
|
63
|
+
info(msg, ctx) {
|
|
64
|
+
this._emit('info', msg, ctx);
|
|
65
|
+
}
|
|
66
|
+
warn(msg, ctx) {
|
|
67
|
+
this._emit('warn', msg, ctx);
|
|
68
|
+
}
|
|
69
|
+
error(msg, ctx) {
|
|
70
|
+
this._emit('error', msg, ctx);
|
|
71
|
+
}
|
|
72
|
+
child(bind) {
|
|
73
|
+
return new StructuredJsonLogger({
|
|
74
|
+
bound: { ...this._bound, ...bind },
|
|
75
|
+
out: this._out,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
_emit(level, msg, ctx) {
|
|
79
|
+
const { cause, ...rest } = ctx ?? {};
|
|
80
|
+
const line = {
|
|
81
|
+
level,
|
|
82
|
+
msg,
|
|
83
|
+
time: new Date().toISOString(),
|
|
84
|
+
...this._bound,
|
|
85
|
+
...rest,
|
|
86
|
+
};
|
|
87
|
+
if (cause !== undefined) {
|
|
88
|
+
line['cause'] = cause instanceof Error
|
|
89
|
+
? { name: cause.name, message: cause.message, stack: cause.stack?.slice(0, 2000) }
|
|
90
|
+
: cause;
|
|
91
|
+
}
|
|
92
|
+
this._out(serialize(line));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// RedactingLogger
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
/**
|
|
99
|
+
* Wraps another logger; redacts known PCI fields from ctx.* before forwarding.
|
|
100
|
+
*/
|
|
101
|
+
export class RedactingLogger {
|
|
102
|
+
_inner;
|
|
103
|
+
constructor(_inner) {
|
|
104
|
+
this._inner = _inner;
|
|
105
|
+
}
|
|
106
|
+
debug(msg, ctx) {
|
|
107
|
+
this._inner.debug(msg, this._redactCtx(ctx));
|
|
108
|
+
}
|
|
109
|
+
info(msg, ctx) {
|
|
110
|
+
this._inner.info(msg, this._redactCtx(ctx));
|
|
111
|
+
}
|
|
112
|
+
warn(msg, ctx) {
|
|
113
|
+
this._inner.warn(msg, this._redactCtx(ctx));
|
|
114
|
+
}
|
|
115
|
+
error(msg, ctx) {
|
|
116
|
+
this._inner.error(msg, this._redactCtx(ctx));
|
|
117
|
+
}
|
|
118
|
+
child(bind) {
|
|
119
|
+
return new RedactingLogger(this._inner.child(this._redactCtx(bind) ?? {}));
|
|
120
|
+
}
|
|
121
|
+
_redactCtx(ctx) {
|
|
122
|
+
if (ctx === undefined)
|
|
123
|
+
return ctx;
|
|
124
|
+
return redact(ctx);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/observability/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA8BrC,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E,MAAM,OAAO,YAAY;IACvB,KAAK,CAAC,IAAY,EAAE,IAAiB,IAAS,CAAC;IAC/C,IAAI,CAAC,IAAY,EAAE,IAAiB,IAAS,CAAC;IAC9C,IAAI,CAAC,IAAY,EAAE,IAAiB,IAAS,CAAC;IAC9C,KAAK,CAAC,IAAY,EAAE,IAAuC,IAAS,CAAC;IACrE,KAAK,CAAC,KAAiB,IAAY,OAAO,IAAI,CAAC,CAAC,CAAC;CAClD;AAED,8EAA8E;AAC9E,8BAA8B;AAC9B,8EAA8E;AAE9E,SAAS,kBAAkB,CAAC,IAAY,EAAE,GAAY;IACpD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACnD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO;YACL,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;SACjC,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,SAAS,CAAC,GAA4B;IAC7C,OAAO,IAAI,CAAC,SAAS,CAAC,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AK,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,IAAgB;QACpB,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC;IAEO,UAAU,CAAmC,GAAM;QACzD,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,GAAG,CAAC;QAClC,OAAO,MAAM,CAAC,GAAG,CAAM,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* metrics.ts — MetricsHook interface, NoopMetricsHook, and helpers.
|
|
3
|
+
*
|
|
4
|
+
* MetricsHook is the canonical observability hook for Viva payment metrics.
|
|
5
|
+
* The SaaS wrapper injects a real implementation; the default is NoopMetricsHook.
|
|
6
|
+
*
|
|
7
|
+
* Metric names (P16):
|
|
8
|
+
* viva_auth_token_refresh_duration_seconds (histogram)
|
|
9
|
+
* viva_api_request_duration_seconds (histogram, labels: endpoint, status)
|
|
10
|
+
* viva_webhook_received_total (counter, labels: event_type_id, result)
|
|
11
|
+
* viva_webhook_processing_lag_seconds (histogram)
|
|
12
|
+
* viva_tenant_resolution_failures_total (counter)
|
|
13
|
+
* viva_webhook_lattice_reject_total (counter, labels: reason)
|
|
14
|
+
* viva_tenant_resolution_retry_resolved_total (counter)
|
|
15
|
+
* viva_tenant_resolution_abandoned_total (counter)
|
|
16
|
+
*
|
|
17
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 observability)
|
|
18
|
+
*/
|
|
19
|
+
export type MetricLabels = Readonly<Record<string, string | number>>;
|
|
20
|
+
export interface MetricsHook {
|
|
21
|
+
/** Increment a counter. Default value: 1. */
|
|
22
|
+
counter(name: string, labels?: MetricLabels, value?: number): void;
|
|
23
|
+
/** Record a histogram observation (value in seconds). */
|
|
24
|
+
histogram(name: string, valueSeconds: number, labels?: MetricLabels): void;
|
|
25
|
+
/**
|
|
26
|
+
* Wraps a promise: measures wall-clock duration, records as histogram.
|
|
27
|
+
* On success: histogram(name, durationSec, labels).
|
|
28
|
+
* On rejection: histogram(name, durationSec, { ...labels, status: 'error' }) then rethrow.
|
|
29
|
+
*/
|
|
30
|
+
timeAsync<T>(name: string, fn: () => Promise<T>, labels?: MetricLabels): Promise<T>;
|
|
31
|
+
}
|
|
32
|
+
export declare class NoopMetricsHook implements MetricsHook {
|
|
33
|
+
counter(_name: string, _labels?: MetricLabels, _value?: number): void;
|
|
34
|
+
histogram(_name: string, _valueSeconds: number, _labels?: MetricLabels): void;
|
|
35
|
+
timeAsync<T>(name: string, fn: () => Promise<T>, labels?: MetricLabels): Promise<T>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/observability/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;AAErE,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnE,yDAAyD;IACzD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3E;;;;OAIG;IACH,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACrF;AAMD,qBAAa,eAAgB,YAAW,WAAW;IACjD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAErE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI;IAEvE,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC;CAa1F"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* metrics.ts — MetricsHook interface, NoopMetricsHook, and helpers.
|
|
3
|
+
*
|
|
4
|
+
* MetricsHook is the canonical observability hook for Viva payment metrics.
|
|
5
|
+
* The SaaS wrapper injects a real implementation; the default is NoopMetricsHook.
|
|
6
|
+
*
|
|
7
|
+
* Metric names (P16):
|
|
8
|
+
* viva_auth_token_refresh_duration_seconds (histogram)
|
|
9
|
+
* viva_api_request_duration_seconds (histogram, labels: endpoint, status)
|
|
10
|
+
* viva_webhook_received_total (counter, labels: event_type_id, result)
|
|
11
|
+
* viva_webhook_processing_lag_seconds (histogram)
|
|
12
|
+
* viva_tenant_resolution_failures_total (counter)
|
|
13
|
+
* viva_webhook_lattice_reject_total (counter, labels: reason)
|
|
14
|
+
* viva_tenant_resolution_retry_resolved_total (counter)
|
|
15
|
+
* viva_tenant_resolution_abandoned_total (counter)
|
|
16
|
+
*
|
|
17
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 observability)
|
|
18
|
+
*/
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// NoopMetricsHook
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
export class NoopMetricsHook {
|
|
23
|
+
counter(_name, _labels, _value) { }
|
|
24
|
+
histogram(_name, _valueSeconds, _labels) { }
|
|
25
|
+
async timeAsync(name, fn, labels) {
|
|
26
|
+
const start = process.hrtime.bigint();
|
|
27
|
+
try {
|
|
28
|
+
const result = await fn();
|
|
29
|
+
const durationSec = Number(process.hrtime.bigint() - start) / 1e9;
|
|
30
|
+
this.histogram(name, durationSec, labels);
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
const durationSec = Number(process.hrtime.bigint() - start) / 1e9;
|
|
35
|
+
this.histogram(name, durationSec, { ...labels, status: 'error' });
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/observability/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAqBH,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E,MAAM,OAAO,eAAe;IAC1B,OAAO,CAAC,KAAa,EAAE,OAAsB,EAAE,MAAe,IAAS,CAAC;IAExE,SAAS,CAAC,KAAa,EAAE,aAAqB,EAAE,OAAsB,IAAS,CAAC;IAEhF,KAAK,CAAC,SAAS,CAAI,IAAY,EAAE,EAAoB,EAAE,MAAqB;QAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACtC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;YAC1B,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;YAClE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAC1C,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;YAClE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;YAClE,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* redact.ts — PCI field redaction for log contexts.
|
|
3
|
+
*
|
|
4
|
+
* Strips known cardholder-data fields from arbitrary objects before logging.
|
|
5
|
+
* Uses a fixed allowlist — no heuristics.
|
|
6
|
+
*
|
|
7
|
+
* Redacted fields (case-sensitive): CardNumber, Cvc2, CardHolderName, Track2,
|
|
8
|
+
* Pan, cardNumber, cvv, cvc, pan, track2, cardHolderName.
|
|
9
|
+
*
|
|
10
|
+
* @see references/viva-docs/md/webhooks-for-payments.txt:495 (PAN masking)
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Recursively redacts PCI fields from an arbitrary value.
|
|
14
|
+
*
|
|
15
|
+
* - Replaces string/number values for known keys with `'<redacted>'`.
|
|
16
|
+
* - Already-redacted sentinel values are left unchanged.
|
|
17
|
+
* - Arrays are mapped element-by-element.
|
|
18
|
+
* - Non-plain-object values (Date, null, primitives) are returned as-is.
|
|
19
|
+
*/
|
|
20
|
+
export declare function redact<T>(value: T): T;
|
|
21
|
+
//# sourceMappingURL=redact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../src/observability/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA4BH;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAErC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* redact.ts — PCI field redaction for log contexts.
|
|
3
|
+
*
|
|
4
|
+
* Strips known cardholder-data fields from arbitrary objects before logging.
|
|
5
|
+
* Uses a fixed allowlist — no heuristics.
|
|
6
|
+
*
|
|
7
|
+
* Redacted fields (case-sensitive): CardNumber, Cvc2, CardHolderName, Track2,
|
|
8
|
+
* Pan, cardNumber, cvv, cvc, pan, track2, cardHolderName.
|
|
9
|
+
*
|
|
10
|
+
* @see references/viva-docs/md/webhooks-for-payments.txt:495 (PAN masking)
|
|
11
|
+
*/
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Redacted field names
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
const REDACTED_KEYS = new Set([
|
|
16
|
+
// Viva API / webhook names (PascalCase)
|
|
17
|
+
'CardNumber',
|
|
18
|
+
'Cvc2',
|
|
19
|
+
'CardHolderName',
|
|
20
|
+
'Track2',
|
|
21
|
+
'Pan',
|
|
22
|
+
// camelCase aliases
|
|
23
|
+
'cardNumber',
|
|
24
|
+
'cvv',
|
|
25
|
+
'cvc',
|
|
26
|
+
'pan',
|
|
27
|
+
'track2',
|
|
28
|
+
'cardHolderName',
|
|
29
|
+
]);
|
|
30
|
+
const REDACTED_SENTINEL = '<redacted>';
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Public API
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
/**
|
|
35
|
+
* Recursively redacts PCI fields from an arbitrary value.
|
|
36
|
+
*
|
|
37
|
+
* - Replaces string/number values for known keys with `'<redacted>'`.
|
|
38
|
+
* - Already-redacted sentinel values are left unchanged.
|
|
39
|
+
* - Arrays are mapped element-by-element.
|
|
40
|
+
* - Non-plain-object values (Date, null, primitives) are returned as-is.
|
|
41
|
+
*/
|
|
42
|
+
export function redact(value) {
|
|
43
|
+
return _redact(value);
|
|
44
|
+
}
|
|
45
|
+
function _redact(value) {
|
|
46
|
+
if (value === null || value === undefined)
|
|
47
|
+
return value;
|
|
48
|
+
if (typeof value !== 'object' && !Array.isArray(value))
|
|
49
|
+
return value;
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
return value.map(_redact);
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === 'object') {
|
|
54
|
+
// Skip non-plain objects (Date, Buffer, etc.)
|
|
55
|
+
if (Object.prototype.toString.call(value) !== '[object Object]')
|
|
56
|
+
return value;
|
|
57
|
+
const src = value;
|
|
58
|
+
const out = {};
|
|
59
|
+
for (const key of Object.keys(src)) {
|
|
60
|
+
if (REDACTED_KEYS.has(key)) {
|
|
61
|
+
// Leave already-redacted sentinels unchanged
|
|
62
|
+
out[key] = src[key] === REDACTED_SENTINEL ? REDACTED_SENTINEL : REDACTED_SENTINEL;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
out[key] = _redact(src[key]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=redact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../src/observability/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E,MAAM,aAAa,GAAG,IAAI,GAAG,CAAS;IACpC,wCAAwC;IACxC,YAAY;IACZ,MAAM;IACN,gBAAgB;IAChB,QAAQ;IACR,KAAK;IACL,oBAAoB;IACpB,YAAY;IACZ,KAAK;IACL,KAAK;IACL,KAAK;IACL,QAAQ;IACR,gBAAgB;CACjB,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,YAAqB,CAAC;AAEhD,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAI,KAAQ;IAChC,OAAO,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3
|
+
*
|
|
4
|
+
* Pass-through (no-op) by default. The SaaS wrapper wires a real tracer
|
|
5
|
+
* implementing OTelTracerHook and injects it via ObservabilityContext.
|
|
6
|
+
*
|
|
7
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 OTel hook)
|
|
8
|
+
*/
|
|
9
|
+
export interface OTelTracerHook {
|
|
10
|
+
/**
|
|
11
|
+
* Wraps fn in a span named `name`.
|
|
12
|
+
* No-op implementation just calls fn() directly.
|
|
13
|
+
*/
|
|
14
|
+
startActiveSpan<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Adds an attribute to the current active span (if any).
|
|
17
|
+
* No-op implementation is a silent stub.
|
|
18
|
+
*/
|
|
19
|
+
setAttribute(key: string, value: string | number | boolean): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class NoopTracerHook implements OTelTracerHook {
|
|
22
|
+
startActiveSpan<T>(_name: string, fn: () => Promise<T>): Promise<T>;
|
|
23
|
+
setAttribute(_key: string, _value: string | number | boolean): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=tracer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../src/observability/tracer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAEnE;;;OAGG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;CACnE;AAMD,qBAAa,cAAe,YAAW,cAAc;IAC7C,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIzE,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI;CACpE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tracer.ts — OpenTelemetry tracer hook interface and no-op default.
|
|
3
|
+
*
|
|
4
|
+
* Pass-through (no-op) by default. The SaaS wrapper wires a real tracer
|
|
5
|
+
* implementing OTelTracerHook and injects it via ObservabilityContext.
|
|
6
|
+
*
|
|
7
|
+
* @see references/viva-docs/md/isv-partner-program.txt:61 (P16 OTel hook)
|
|
8
|
+
*/
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// NoopTracerHook
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export class NoopTracerHook {
|
|
13
|
+
async startActiveSpan(_name, fn) {
|
|
14
|
+
return fn();
|
|
15
|
+
}
|
|
16
|
+
setAttribute(_key, _value) { }
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=tracer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracer.js","sourceRoot":"","sources":["../../src/observability/tracer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoBH,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,MAAM,OAAO,cAAc;IACzB,KAAK,CAAC,eAAe,CAAI,KAAa,EAAE,EAAoB;QAC1D,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;IAED,YAAY,CAAC,IAAY,EAAE,MAAiC,IAAS,CAAC;CACvE"}
|