@mushi-mushi/web 1.27.0 → 1.29.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/otel.cjs CHANGED
@@ -3,15 +3,17 @@
3
3
  // src/otel.ts
4
4
  var SPAN_STATUS_ERROR = 2;
5
5
  var warnedMissing = false;
6
+ var noopOnStart = (_span, _parentContext) => {
7
+ };
8
+ var noopOnEnd = (_span) => {
9
+ };
6
10
  function createBrowserOtelSpanProcessor(mushi, options = {}) {
7
11
  const errorsOnly = options.errorsOnly ?? true;
8
12
  const noOp = {
9
13
  // mushi-mushi-allowlist: OTel SpanProcessor requires onStart/onEnd; this no-op processor intentionally does nothing
10
- onStart: () => {
11
- },
14
+ onStart: noopOnStart,
12
15
  // mushi-mushi-allowlist: no-op processor — nothing to forward
13
- onEnd: () => {
14
- },
16
+ onEnd: noopOnEnd,
15
17
  shutdown: () => Promise.resolve(),
16
18
  forceFlush: () => Promise.resolve()
17
19
  };
@@ -26,8 +28,7 @@ function createBrowserOtelSpanProcessor(mushi, options = {}) {
26
28
  }
27
29
  return {
28
30
  // mushi-mushi-allowlist: OTel SpanProcessor requires onStart; this processor only acts on onEnd
29
- onStart: () => {
30
- },
31
+ onStart: noopOnStart,
31
32
  onEnd(span) {
32
33
  try {
33
34
  const isError = span.status.code === SPAN_STATUS_ERROR;
package/dist/otel.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/otel.ts"],"names":[],"mappings":";;;AA4EA,IAAM,iBAAA,GAAoB,CAAA;AAE1B,IAAI,aAAA,GAAgB,KAAA;AAQb,SAAS,8BAAA,CACd,KAAA,EACA,OAAA,GAA2C,EAAC,EAClB;AAC1B,EAAA,MAAM,UAAA,GAAa,QAAQ,UAAA,IAAc,IAAA;AAEzC,EAAA,MAAM,IAAA,GAAiC;AAAA;AAAA,IAErC,SAAS,MAAM;AAAA,IAAC,CAAA;AAAA;AAAA,IAEhB,OAAO,MAAM;AAAA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,QACH;AAAA,MACF,CAAA,CAAA,MAAQ;AAAA,MAER;AAAA,IACF,CAAA;AAAA,IAEA,QAAA,EAAU,MAAM,OAAA,CAAQ,OAAA,EAAQ;AAAA,IAChC,UAAA,EAAY,MAAM,OAAA,CAAQ,OAAA;AAAQ,GACpC;AACF","file":"otel.cjs","sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2024–2026 Kenji Sakuramoto (kensaurus) — Mushi Mushi\n/**\n * FILE: packages/web/src/otel.ts\n * PURPOSE: Optional OpenTelemetry SpanProcessor bridge for the browser SDK.\n *\n * Forwards error spans from the browser OTel pipeline to Mushi as reports.\n * Bundled in its own subpath (`@mushi-mushi/web/otel`) so applications that\n * don't use OTel pay **zero bytes** — this entry is never included in the main\n * `@mushi-mushi/web` bundle.\n *\n * `@opentelemetry/api` is an OPTIONAL peer dependency. The caller imports it\n * and passes the `context` module handle (or any truthy sentinel) to signal\n * OTel is present. This avoids a dynamic-import probe that breaks Vite's\n * static analysis and means bundlers tree-shake the entire module when OTel\n * is absent.\n *\n * Usage (TypeScript):\n *\n * ```ts\n * import { createBrowserOtelSpanProcessor } from '@mushi-mushi/web/otel'\n * import { context } from '@opentelemetry/api' // your own dep\n * import { Mushi } from '@mushi-mushi/web'\n *\n * const mushi = new Mushi({ projectId: '…', apiKey: '…' })\n * const processor = createBrowserOtelSpanProcessor(mushi, { otelPresent: context })\n * provider.addSpanProcessor(processor)\n * ```\n *\n * Without `otelPresent` (or with `otelPresent: null`) the factory returns a\n * no-op processor and emits a one-time `console.warn`.\n */\n\nimport type { MushiSDKInstance } from '@mushi-mushi/core'\n\n// ── Minimal OTel type surface ─────────────────────────────────────────────────\n// We only use the structural types — the real @opentelemetry/api package is\n// never imported here. Callers bring their own import.\n\nexport interface BrowserOtelSpan {\n /** SpanStatusCode: UNSET=0, OK=1, ERROR=2 */\n status: { code: number }\n attributes: Record<string, unknown>\n name: string\n spanContext(): { traceId: string; spanId: string }\n startTime: [number, number] // HrTime: [seconds, nanoseconds]\n endTime: [number, number]\n}\n\nexport interface BrowserOtelSpanProcessor {\n onStart(span: BrowserOtelSpan, parentContext: unknown): void\n onEnd(span: BrowserOtelSpan): void\n shutdown(): Promise<void>\n forceFlush(): Promise<void>\n}\n\nexport interface BrowserOtelSpanProcessorOptions {\n /**\n * Pass any truthy value from your `@opentelemetry/api` import to signal the\n * package is present. Typically `import { context } from '@opentelemetry/api'`.\n *\n * When absent or `null/undefined`, a no-op processor is returned.\n *\n * @example\n * import { context } from '@opentelemetry/api'\n * createBrowserOtelSpanProcessor(mushi, { otelPresent: context })\n */\n otelPresent?: unknown\n /**\n * When `true` (default), only ERROR spans (status.code === 2) trigger a\n * Mushi report. Set to `false` to call `report()` for every finished span.\n */\n errorsOnly?: boolean\n}\n\n// SpanStatusCode.ERROR is 2 — inlined so we never import the real package.\nconst SPAN_STATUS_ERROR = 2\n\nlet warnedMissing = false\n\n/**\n * Create a SpanProcessor that forwards browser OTel error spans to Mushi.\n *\n * The processor is synchronous. `mushi.report()` is called fire-and-forget\n * (`void`) so it never blocks the OTel pipeline's `onEnd` call path.\n */\nexport function createBrowserOtelSpanProcessor(\n mushi: MushiSDKInstance,\n options: BrowserOtelSpanProcessorOptions = {},\n): BrowserOtelSpanProcessor {\n const errorsOnly = options.errorsOnly ?? true\n\n const noOp: BrowserOtelSpanProcessor = {\n // mushi-mushi-allowlist: OTel SpanProcessor requires onStart/onEnd; this no-op processor intentionally does nothing\n onStart: () => {},\n // mushi-mushi-allowlist: no-op processor — nothing to forward\n onEnd: () => {},\n shutdown: () => Promise.resolve(),\n forceFlush: () => Promise.resolve(),\n }\n\n if (!options.otelPresent) {\n if (!warnedMissing) {\n warnedMissing = true\n console.warn(\n '[mushi-mushi/web] createBrowserOtelSpanProcessor: `otelPresent` was not provided. ' +\n 'Pass a value from your @opentelemetry/api import (e.g. `{ otelPresent: context }`) ' +\n 'to enable OTel span → Mushi error forwarding. ' +\n 'A no-op SpanProcessor has been returned.',\n )\n }\n return noOp\n }\n\n return {\n // mushi-mushi-allowlist: OTel SpanProcessor requires onStart; this processor only acts on onEnd\n onStart: () => {},\n\n onEnd(span: BrowserOtelSpan): void {\n try {\n const isError = span.status.code === SPAN_STATUS_ERROR\n\n if (!isError && errorsOnly) return\n\n if (isError) {\n const message =\n (span.attributes['exception.message'] as string | undefined) ??\n (span.attributes['error.message'] as string | undefined) ??\n `OTel error span: ${span.name}`\n\n // Build W3C traceparent from span context so the Mushi report is\n // correlated to the same distributed trace.\n const ctx = span.spanContext()\n const traceparent = `00-${ctx.traceId}-${ctx.spanId}-01`\n\n // Fire-and-forget — never block the OTel pipeline on a network call.\n void mushi.captureEvent({\n description: message,\n category: 'bug',\n component: `otel:${span.name}`,\n metadata: {\n otelSpanName: span.name,\n otelAttributes: span.attributes,\n traceparent,\n },\n })\n }\n } catch {\n // Never let the span processor crash the host page.\n }\n },\n\n shutdown: () => Promise.resolve(),\n forceFlush: () => Promise.resolve(),\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/otel.ts"],"names":[],"mappings":";;;AA4EA,IAAM,iBAAA,GAAoB,CAAA;AAE1B,IAAI,aAAA,GAAgB,KAAA;AAEpB,IAAM,WAAA,GAAc,CAAC,KAAA,EAAwB,cAAA,KAAkC;AAAC,CAAA;AAChF,IAAM,SAAA,GAAY,CAAC,KAAA,KAAiC;AAAC,CAAA;AAQ9C,SAAS,8BAAA,CACd,KAAA,EACA,OAAA,GAA2C,EAAC,EAClB;AAC1B,EAAA,MAAM,UAAA,GAAa,QAAQ,UAAA,IAAc,IAAA;AAEzC,EAAA,MAAM,IAAA,GAAiC;AAAA;AAAA,IAErC,OAAA,EAAS,WAAA;AAAA;AAAA,IAET,KAAA,EAAO,SAAA;AAAA,IACP,QAAA,EAAU,MAAM,OAAA,CAAQ,OAAA,EAAQ;AAAA,IAChC,UAAA,EAAY,MAAM,OAAA,CAAQ,OAAA;AAAQ,GACpC;AAEA,EAAA,IAAI,CAAC,QAAQ,WAAA,EAAa;AACx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el.cjs","sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2024–2026 Kenji Sakuramoto (kensaurus) — Mushi Mushi\n/**\n * FILE: packages/web/src/otel.ts\n * PURPOSE: Optional OpenTelemetry SpanProcessor bridge for the browser SDK.\n *\n * Forwards error spans from the browser OTel pipeline to Mushi as reports.\n * Bundled in its own subpath (`@mushi-mushi/web/otel`) so applications that\n * don't use OTel pay **zero bytes** — this entry is never included in the main\n * `@mushi-mushi/web` bundle.\n *\n * `@opentelemetry/api` is an OPTIONAL peer dependency. The caller imports it\n * and passes the `context` module handle (or any truthy sentinel) to signal\n * OTel is present. This avoids a dynamic-import probe that breaks Vite's\n * static analysis and means bundlers tree-shake the entire module when OTel\n * is absent.\n *\n * Usage (TypeScript):\n *\n * ```ts\n * import { createBrowserOtelSpanProcessor } from '@mushi-mushi/web/otel'\n * import { context } from '@opentelemetry/api' // your own dep\n * import { Mushi } from '@mushi-mushi/web'\n *\n * const mushi = new Mushi({ projectId: '…', apiKey: '…' })\n * const processor = createBrowserOtelSpanProcessor(mushi, { otelPresent: context })\n * provider.addSpanProcessor(processor)\n * ```\n *\n * Without `otelPresent` (or with `otelPresent: null`) the factory returns a\n * no-op processor and emits a one-time `console.warn`.\n */\n\nimport type { MushiSDKInstance } from '@mushi-mushi/core'\n\n// ── Minimal OTel type surface ─────────────────────────────────────────────────\n// We only use the structural types — the real @opentelemetry/api package is\n// never imported here. Callers bring their own import.\n\nexport interface BrowserOtelSpan {\n /** SpanStatusCode: UNSET=0, OK=1, ERROR=2 */\n status: { code: number }\n attributes: Record<string, unknown>\n name: string\n spanContext(): { traceId: string; spanId: string }\n startTime: [number, number] // HrTime: [seconds, nanoseconds]\n endTime: [number, number]\n}\n\nexport interface BrowserOtelSpanProcessor {\n onStart(span: BrowserOtelSpan, parentContext: unknown): void\n onEnd(span: BrowserOtelSpan): void\n shutdown(): Promise<void>\n forceFlush(): Promise<void>\n}\n\nexport interface BrowserOtelSpanProcessorOptions {\n /**\n * Pass any truthy value from your `@opentelemetry/api` import to signal the\n * package is present. Typically `import { context } from '@opentelemetry/api'`.\n *\n * When absent or `null/undefined`, a no-op processor is returned.\n *\n * @example\n * import { context } from '@opentelemetry/api'\n * createBrowserOtelSpanProcessor(mushi, { otelPresent: context })\n */\n otelPresent?: unknown\n /**\n * When `true` (default), only ERROR spans (status.code === 2) trigger a\n * Mushi report. Set to `false` to call `report()` for every finished span.\n */\n errorsOnly?: boolean\n}\n\n// SpanStatusCode.ERROR is 2 — inlined so we never import the real package.\nconst SPAN_STATUS_ERROR = 2\n\nlet warnedMissing = false\n\nconst noopOnStart = (_span: BrowserOtelSpan, _parentContext: unknown): void => {}\nconst noopOnEnd = (_span: BrowserOtelSpan): void => {}\n\n/**\n * Create a SpanProcessor that forwards browser OTel error spans to Mushi.\n *\n * The processor is synchronous. `mushi.report()` is called fire-and-forget\n * (`void`) so it never blocks the OTel pipeline's `onEnd` call path.\n */\nexport function createBrowserOtelSpanProcessor(\n mushi: MushiSDKInstance,\n options: BrowserOtelSpanProcessorOptions = {},\n): BrowserOtelSpanProcessor {\n const errorsOnly = options.errorsOnly ?? true\n\n const noOp: BrowserOtelSpanProcessor = {\n // mushi-mushi-allowlist: OTel SpanProcessor requires onStart/onEnd; this no-op processor intentionally does nothing\n onStart: noopOnStart,\n // mushi-mushi-allowlist: no-op processor — nothing to forward\n onEnd: noopOnEnd,\n shutdown: () => Promise.resolve(),\n forceFlush: () => Promise.resolve(),\n }\n\n if (!options.otelPresent) {\n if (!warnedMissing) {\n warnedMissing = true\n console.warn(\n '[mushi-mushi/web] createBrowserOtelSpanProcessor: `otelPresent` was not provided. ' +\n 'Pass a value from your @opentelemetry/api import (e.g. `{ otelPresent: context }`) ' +\n 'to enable OTel span → Mushi error forwarding. ' +\n 'A no-op SpanProcessor has been returned.',\n )\n }\n return noOp\n }\n\n return {\n // mushi-mushi-allowlist: OTel SpanProcessor requires onStart; this processor only acts on onEnd\n onStart: noopOnStart,\n\n onEnd(span: BrowserOtelSpan): void {\n try {\n const isError = span.status.code === SPAN_STATUS_ERROR\n\n if (!isError && errorsOnly) return\n\n if (isError) {\n const message =\n (span.attributes['exception.message'] as string | undefined) ??\n (span.attributes['error.message'] as string | undefined) ??\n `OTel error span: ${span.name}`\n\n // Build W3C traceparent from span context so the Mushi report is\n // correlated to the same distributed trace.\n const ctx = span.spanContext()\n const traceparent = `00-${ctx.traceId}-${ctx.spanId}-01`\n\n // Fire-and-forget — never block the OTel pipeline on a network call.\n void mushi.captureEvent({\n description: message,\n category: 'bug',\n component: `otel:${span.name}`,\n metadata: {\n otelSpanName: span.name,\n otelAttributes: span.attributes,\n traceparent,\n },\n })\n }\n } catch {\n // Never let the span processor crash the host page.\n }\n },\n\n shutdown: () => Promise.resolve(),\n forceFlush: () => Promise.resolve(),\n }\n}\n"]}
package/dist/otel.js CHANGED
@@ -1,15 +1,17 @@
1
1
  // src/otel.ts
2
2
  var SPAN_STATUS_ERROR = 2;
3
3
  var warnedMissing = false;
4
+ var noopOnStart = (_span, _parentContext) => {
5
+ };
6
+ var noopOnEnd = (_span) => {
7
+ };
4
8
  function createBrowserOtelSpanProcessor(mushi, options = {}) {
5
9
  const errorsOnly = options.errorsOnly ?? true;
6
10
  const noOp = {
7
11
  // mushi-mushi-allowlist: OTel SpanProcessor requires onStart/onEnd; this no-op processor intentionally does nothing
8
- onStart: () => {
9
- },
12
+ onStart: noopOnStart,
10
13
  // mushi-mushi-allowlist: no-op processor — nothing to forward
11
- onEnd: () => {
12
- },
14
+ onEnd: noopOnEnd,
13
15
  shutdown: () => Promise.resolve(),
14
16
  forceFlush: () => Promise.resolve()
15
17
  };
@@ -24,8 +26,7 @@ function createBrowserOtelSpanProcessor(mushi, options = {}) {
24
26
  }
25
27
  return {
26
28
  // mushi-mushi-allowlist: OTel SpanProcessor requires onStart; this processor only acts on onEnd
27
- onStart: () => {
28
- },
29
+ onStart: noopOnStart,
29
30
  onEnd(span) {
30
31
  try {
31
32
  const isError = span.status.code === S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AAc,CAAA,GAAA,EAAM,GAAA,CAAI,OAAO,CAAA,CAAA,EAAI,IAAI,MAAM,CAAA,GAAA,CAAA;AAGnD,UAAA,KAAK,MAAM,YAAA,CAAa;AAAA,YACtB,WAAA,EAAa,OAAA;AAAA,YACb,QAAA,EAAU,KAAA;AAAA,YACV,SAAA,EAAW,CAAA,KAAA,EAAQ,IAAA,CAAK,IAAI,CAAA,CAAA;AAAA,YAC5B,QAAA,EAAU;AAAA,cACR,cAAc,IAAA,CAAK,IAAA;AAAA,cACnB,gBAAgB,IAAA,CAAK,UAAA;AAAA,cACrB;AAAA;AACF,WACD,CAAA;AAAA,QACH;AAAA,MACF,CAAA,CAAA,MAAQ;AAAA,MAER;AAAA,IACF,CAAA;AAAA,IAEA,QAAA,EAAU,MAAM,OAAA,CAAQ,OAAA,EAAQ;AAAA,IAChC,UAAA,EAAY,MAAM,OAAA,CAAQ,OAAA;AAAQ,GACpC;AACF","file":"otel.js","sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2024–2026 Kenji Sakuramoto (kensaurus) — Mushi Mushi\n/**\n * FILE: packages/web/src/otel.ts\n * PURPOSE: Optional OpenTelemetry SpanProcessor bridge for the browser SDK.\n *\n * Forwards error spans from the browser OTel pipeline to Mushi as reports.\n * Bundled in its own subpath (`@mushi-mushi/web/otel`) so applications that\n * don't use OTel pay **zero bytes** — this entry is never included in the main\n * `@mushi-mushi/web` bundle.\n *\n * `@opentelemetry/api` is an OPTIONAL peer dependency. The caller imports it\n * and passes the `context` module handle (or any truthy sentinel) to signal\n * OTel is present. This avoids a dynamic-import probe that breaks Vite's\n * static analysis and means bundlers tree-shake the entire module when OTel\n * is absent.\n *\n * Usage (TypeScript):\n *\n * ```ts\n * import { createBrowserOtelSpanProcessor } from '@mushi-mushi/web/otel'\n * import { context } from '@opentelemetry/api' // your own dep\n * import { Mushi } from '@mushi-mushi/web'\n *\n * const mushi = new Mushi({ projectId: '…', apiKey: '…' })\n * const processor = createBrowserOtelSpanProcessor(mushi, { otelPresent: context })\n * provider.addSpanProcessor(processor)\n * ```\n *\n * Without `otelPresent` (or with `otelPresent: null`) the factory returns a\n * no-op processor and emits a one-time `console.warn`.\n */\n\nimport type { MushiSDKInstance } from '@mushi-mushi/core'\n\n// ── Minimal OTel type surface ─────────────────────────────────────────────────\n// We only use the structural types — the real @opentelemetry/api package is\n// never imported here. Callers bring their own import.\n\nexport interface BrowserOtelSpan {\n /** SpanStatusCode: UNSET=0, OK=1, ERROR=2 */\n status: { code: number }\n attributes: Record<string, unknown>\n name: string\n spanContext(): { traceId: string; spanId: string }\n startTime: [number, number] // HrTime: [seconds, nanoseconds]\n endTime: [number, number]\n}\n\nexport interface BrowserOtelSpanProcessor {\n onStart(span: BrowserOtelSpan, parentContext: unknown): void\n onEnd(span: BrowserOtelSpan): void\n shutdown(): Promise<void>\n forceFlush(): Promise<void>\n}\n\nexport interface BrowserOtelSpanProcessorOptions {\n /**\n * Pass any truthy value from your `@opentelemetry/api` import to signal the\n * package is present. Typically `import { context } from '@opentelemetry/api'`.\n *\n * When absent or `null/undefined`, a no-op processor is returned.\n *\n * @example\n * import { context } from '@opentelemetry/api'\n * createBrowserOtelSpanProcessor(mushi, { otelPresent: context })\n */\n otelPresent?: unknown\n /**\n * When `true` (default), only ERROR spans (status.code === 2) trigger a\n * Mushi report. Set to `false` to call `report()` for every finished span.\n */\n errorsOnly?: boolean\n}\n\n// SpanStatusCode.ERROR is 2 — inlined so we never import the real package.\nconst SPAN_STATUS_ERROR = 2\n\nlet warnedMissing = false\n\n/**\n * Create a SpanProcessor that forwards browser OTel error spans to Mushi.\n *\n * The processor is synchronous. `mushi.report()` is called fire-and-forget\n * (`void`) so it never blocks the OTel pipeline's `onEnd` call path.\n */\nexport function createBrowserOtelSpanProcessor(\n mushi: MushiSDKInstance,\n options: BrowserOtelSpanProcessorOptions = {},\n): BrowserOtelSpanProcessor {\n const errorsOnly = options.errorsOnly ?? true\n\n const noOp: BrowserOtelSpanProcessor = {\n // mushi-mushi-allowlist: OTel SpanProcessor requires onStart/onEnd; this no-op processor intentionally does nothing\n onStart: () => {},\n // mushi-mushi-allowlist: no-op processor — nothing to forward\n onEnd: () => {},\n shutdown: () => Promise.resolve(),\n forceFlush: () => Promise.resolve(),\n }\n\n if (!options.otelPresent) {\n if (!warnedMissing) {\n warnedMissing = true\n console.warn(\n '[mushi-mushi/web] createBrowserOtelSpanProcessor: `otelPresent` was not provided. ' +\n 'Pass a value from your @opentelemetry/api import (e.g. `{ otelPresent: context }`) ' +\n 'to enable OTel span → Mushi error forwarding. ' +\n 'A no-op SpanProcessor has been returned.',\n )\n }\n return noOp\n }\n\n return {\n // mushi-mushi-allowlist: OTel SpanProcessor requires onStart; this processor only acts on onEnd\n onStart: () => {},\n\n onEnd(span: BrowserOtelSpan): void {\n try {\n const isError = span.status.code === SPAN_STATUS_ERROR\n\n if (!isError && errorsOnly) return\n\n if (isError) {\n const message =\n (span.attributes['exception.message'] as string | undefined) ??\n (span.attributes['error.message'] as string | undefined) ??\n `OTel error span: ${span.name}`\n\n // Build W3C traceparent from span context so the Mushi report is\n // correlated to the same distributed trace.\n const ctx = span.spanContext()\n const traceparent = `00-${ctx.traceId}-${ctx.spanId}-01`\n\n // Fire-and-forget — never block the OTel pipeline on a network call.\n void mushi.captureEvent({\n description: message,\n category: 'bug',\n component: `otel:${span.name}`,\n metadata: {\n otelSpanName: span.name,\n otelAttributes: span.attributes,\n traceparent,\n },\n })\n }\n } catch {\n // Never let the span processor crash the host page.\n }\n },\n\n shutdown: () => Promise.resolve(),\n forceFlush: () => Promise.resolve(),\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/otel.ts"],"names":[],"mappings":";AA4EA,IAAM,iBAAA,GAAoB,CAAA;AAE1B,IAAI,aAAA,GAAgB,KAAA;AAEpB,IAAM,WAAA,GAAc,CAAC,KAAA,EAAwB,cAAA,KAAkC;AAAC,CAAA;AAChF,IAAM,SAAA,GAAY,CAAC,KAAA,KAAiC;AAAC,CAA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AAA,EAAW,CAAA,KAAA,EAAQ,IAAA,CAAK,IAAI,CAAA,CAAA;AAAA,YAC5B,QAAA,EAAU;AAAA,cACR,cAAc,IAAA,CAAK,IAAA;AAAA,cACnB,gBAAgB,IAAA,CAAK,UAAA;AAAA,cACrB;AAAA;AACF,WACD,CAAA;AAAA,QACH;AAAA,MACF,CAAA,CAAA,MAAQ;AAAA,MAER;AAAA,IACF,CAAA;AAAA,IAEA,QAAA,EAAU,MAAM,OAAA,CAAQ,OAAA,EAAQ;AAAA,IAChC,UAAA,EAAY,MAAM,OAAA,CAAQ,OAAA;AAAQ,GACpC;AACF","file":"otel.js","sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2024–2026 Kenji Sakuramoto (kensaurus) — Mushi Mushi\n/**\n * FILE: packages/web/src/otel.ts\n * PURPOSE: Optional OpenTelemetry SpanProcessor bridge for the browser SDK.\n *\n * Forwards error spans from the browser OTel pipeline to Mushi as reports.\n * Bundled in its own subpath (`@mushi-mushi/web/otel`) so applications that\n * don't use OTel pay **zero bytes** — this entry is never included in the main\n * `@mushi-mushi/web` bundle.\n *\n * `@opentelemetry/api` is an OPTIONAL peer dependency. The caller imports it\n * and passes the `context` module handle (or any truthy sentinel) to signal\n * OTel is present. This avoids a dynamic-import probe that breaks Vite's\n * static analysis and means bundlers tree-shake the entire module when OTel\n * is absent.\n *\n * Usage (TypeScript):\n *\n * ```ts\n * import { createBrowserOtelSpanProcessor } from '@mushi-mushi/web/otel'\n * import { context } from '@opentelemetry/api' // your own dep\n * import { Mushi } from '@mushi-mushi/web'\n *\n * const mushi = new Mushi({ projectId: '…', apiKey: '…' })\n * const processor = createBrowserOtelSpanProcessor(mushi, { otelPresent: context })\n * provider.addSpanProcessor(processor)\n * ```\n *\n * Without `otelPresent` (or with `otelPresent: null`) the factory returns a\n * no-op processor and emits a one-time `console.warn`.\n */\n\nimport type { MushiSDKInstance } from '@mushi-mushi/core'\n\n// ── Minimal OTel type surface ─────────────────────────────────────────────────\n// We only use the structural types — the real @opentelemetry/api package is\n// never imported here. Callers bring their own import.\n\nexport interface BrowserOtelSpan {\n /** SpanStatusCode: UNSET=0, OK=1, ERROR=2 */\n status: { code: number }\n attributes: Record<string, unknown>\n name: string\n spanContext(): { traceId: string; spanId: string }\n startTime: [number, number] // HrTime: [seconds, nanoseconds]\n endTime: [number, number]\n}\n\nexport interface BrowserOtelSpanProcessor {\n onStart(span: BrowserOtelSpan, parentContext: unknown): void\n onEnd(span: BrowserOtelSpan): void\n shutdown(): Promise<void>\n forceFlush(): Promise<void>\n}\n\nexport interface BrowserOtelSpanProcessorOptions {\n /**\n * Pass any truthy value from your `@opentelemetry/api` import to signal the\n * package is present. Typically `import { context } from '@opentelemetry/api'`.\n *\n * When absent or `null/undefined`, a no-op processor is returned.\n *\n * @example\n * import { context } from '@opentelemetry/api'\n * createBrowserOtelSpanProcessor(mushi, { otelPresent: context })\n */\n otelPresent?: unknown\n /**\n * When `true` (default), only ERROR spans (status.code === 2) trigger a\n * Mushi report. Set to `false` to call `report()` for every finished span.\n */\n errorsOnly?: boolean\n}\n\n// SpanStatusCode.ERROR is 2 — inlined so we never import the real package.\nconst SPAN_STATUS_ERROR = 2\n\nlet warnedMissing = false\n\nconst noopOnStart = (_span: BrowserOtelSpan, _parentContext: unknown): void => {}\nconst noopOnEnd = (_span: BrowserOtelSpan): void => {}\n\n/**\n * Create a SpanProcessor that forwards browser OTel error spans to Mushi.\n *\n * The processor is synchronous. `mushi.report()` is called fire-and-forget\n * (`void`) so it never blocks the OTel pipeline's `onEnd` call path.\n */\nexport function createBrowserOtelSpanProcessor(\n mushi: MushiSDKInstance,\n options: BrowserOtelSpanProcessorOptions = {},\n): BrowserOtelSpanProcessor {\n const errorsOnly = options.errorsOnly ?? true\n\n const noOp: BrowserOtelSpanProcessor = {\n // mushi-mushi-allowlist: OTel SpanProcessor requires onStart/onEnd; this no-op processor intentionally does nothing\n onStart: noopOnStart,\n // mushi-mushi-allowlist: no-op processor — nothing to forward\n onEnd: noopOnEnd,\n shutdown: () => Promise.resolve(),\n forceFlush: () => Promise.resolve(),\n }\n\n if (!options.otelPresent) {\n if (!warnedMissing) {\n warnedMissing = true\n console.warn(\n '[mushi-mushi/web] createBrowserOtelSpanProcessor: `otelPresent` was not provided. ' +\n 'Pass a value from your @opentelemetry/api import (e.g. `{ otelPresent: context }`) ' +\n 'to enable OTel span → Mushi error forwarding. ' +\n 'A no-op SpanProcessor has been returned.',\n )\n }\n return noOp\n }\n\n return {\n // mushi-mushi-allowlist: OTel SpanProcessor requires onStart; this processor only acts on onEnd\n onStart: noopOnStart,\n\n onEnd(span: BrowserOtelSpan): void {\n try {\n const isError = span.status.code === SPAN_STATUS_ERROR\n\n if (!isError && errorsOnly) return\n\n if (isError) {\n const message =\n (span.attributes['exception.message'] as string | undefined) ??\n (span.attributes['error.message'] as string | undefined) ??\n `OTel error span: ${span.name}`\n\n // Build W3C traceparent from span context so the Mushi report is\n // correlated to the same distributed trace.\n const ctx = span.spanContext()\n const traceparent = `00-${ctx.traceId}-${ctx.spanId}-01`\n\n // Fire-and-forget — never block the OTel pipeline on a network call.\n void mushi.captureEvent({\n description: message,\n category: 'bug',\n component: `otel:${span.name}`,\n metadata: {\n otelSpanName: span.name,\n otelAttributes: span.attributes,\n traceparent,\n },\n })\n }\n } catch {\n // Never let the span processor crash the host page.\n }\n },\n\n shutdown: () => Promise.resolve(),\n forceFlush: () => Promise.resolve(),\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/test-utils.ts"],"names":[],"mappings":";;;;;;;AAuDA,eAAsB,UAAA,CAAW,IAAA,GAA0B,EAAC,EAA2B;AAErF,EAAU,OAAO,IAAA;AAqBnB;AAOO,SAAS,WAAW,QAAA,EAAsC;AAE/D,EAAU;AAEZ;AAGO,SAAS,gBAAgB,QAAA,EAAsC;AAEtE;AAOA,eAAsB,gBAAA,CAAiB,OAAA,GAAkC,EAAC,EAAoC;AAC5G,EAAA,MAAM,SAAA,GAAY,QAAQ,SAAA,IAAa,GAAA;AACvC,EAAA,MAAM,OAAA,GAAU,KAAK,GAAA,EAAI;AACzB,EAAA,IAAI,eAAA,GAAiD,IAAA;AAErD,EAAA,OAAO,IAAA,CAAK,GAAA,EAAI,GAAI,OAAA,GAAU,SAAA,EAAW;AAQvC,IAAA,MAAM,IAAI,OAAA,CAAQ,CAAC,MAAM,UAAA,CAAW,CAAA,EAAG,GAAG,CAAC,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,KAAK,SAAA,CAAU,eAAe,CAAC,CAAA,CAAE,CAAA;AACxF;AAOA,eAAsB,wBAAA,CAAyB,OAAA,GAG3C,EAAC,EAAkB;AAErB,EAAU;AAgBZ;AAOA,eAAsB,iBAAA,CAAkB,OAAA,GAAkC,EAAC,EAAoB;AAE7F,EAAU,OAAO,CAAA;AAenB","file":"test-utils.cjs","sourcesContent":["/**\n * @mushi-mushi/web/test-utils\n *\n * Playwright / jsdom helpers for deterministic SDK tests. This module is\n * published as a separate entry-point so production bundles never pay the\n * cost — import it via `import { triggerBug, openReport } from\n * '@mushi-mushi/web/test-utils'`.\n *\n * Design goals:\n * 1. Zero production footprint. Nothing here is imported from `./mushi`,\n * `./widget`, or any runtime module. We reach for the live SDK via\n * `Mushi.getInstance()` so the test process sees exactly what the app\n * bootstrapped — no duplicate SDK singletons, no double-init races.\n * 2. Safe in a test harness even when Mushi is disabled. Every helper\n * no-ops when `Mushi.getInstance()` returns `null`, so Playwright\n * specs that conditionally wire Mushi (e.g. cloud vs local targets)\n * don't have to branch.\n * 3. Flat surface. Tests want 3 verbs: \"open the widget\", \"submit a\n * report programmatically\", \"wait until the SDK confirms the POST\n * landed\". Anything beyond that belongs in the app under test.\n */\n\nimport { Mushi } from './mushi';\nimport type {\n MushiDiagnosticsResult,\n MushiReportCategory,\n MushiSDKInstance,\n} from '@mushi-mushi/core';\n\n/** Options accepted by `triggerBug`. Mirrors the core report contract but\n * keeps every field optional so a Playwright test can say\n * `triggerBug({ description: 'button dead' })` without a category. */\nexport interface TriggerBugOptions {\n /** Short free-text description of the issue. Defaults to a marker\n * string so tests that forget to pass a description still produce a\n * distinguishable report in the admin console. */\n description?: string;\n /** Severity-free category tag. */\n category?: MushiReportCategory;\n /** Arbitrary metadata the test wants to round-trip. Merged on top of\n * whatever `setMetadata` has already stored. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Submit a report bypassing the widget UI. Returns the server-assigned\n * `reportId` when the POST lands, or `null` if Mushi isn't initialised in\n * this test context (or the submit failed — the SDK swallows network\n * errors silently by design).\n *\n * Use this from Playwright `page.evaluate(...)` calls to round-trip a\n * report into the backend without needing to drive the widget's DOM. It's\n * the fastest way to assert \"a bug report made it from the browser into\n * reports/ in Supabase\".\n */\nexport async function triggerBug(opts: TriggerBugOptions = {}): Promise<string | null> {\n const sdk = Mushi.getInstance();\n if (!sdk) return null;\n\n const description = opts.description\n ?? `[test-utils] triggerBug marker ${new Date().toISOString()}`;\n\n if (opts.metadata) {\n for (const [k, v] of Object.entries(opts.metadata)) {\n try { sdk.setMetadata(k, v); } catch { /* ignore */ }\n }\n }\n\n // `captureEvent` is the documented programmatic-submit API since 0.3.0\n // — it bypasses the widget, resolves with the server-assigned report\n // id, and participates in the same offline queue / pre-filter pipeline\n // as a widget submission.\n return await sdk.captureEvent({\n description,\n source: 'test-utils',\n ...(opts.category ? { category: opts.category } : {}),\n ...(opts.metadata ? { metadata: opts.metadata } : {}),\n });\n}\n\n/**\n * Programmatically open the Mushi widget without submitting anything. Use\n * for interaction tests that want to assert \"the widget is mounted and\n * reachable\" or to drive a user-like flow via Playwright selectors.\n */\nexport function openReport(category?: MushiReportCategory): void {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n sdk.report(category ? { category } : undefined);\n}\n\n/** Alias with language that reads better in Playwright smoke tests. */\nexport function openMushiWidget(category?: MushiReportCategory): void {\n openReport(category);\n}\n\n/**\n * Wait until the live SDK instance exists and reports a mounted widget.\n * Throws with the diagnostics payload so CI failures point at CSP / Shadow DOM\n * / capture setup instead of a generic timeout.\n */\nexport async function expectMushiReady(options: { timeoutMs?: number } = {}): Promise<MushiDiagnosticsResult> {\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n let lastDiagnostics: MushiDiagnosticsResult | null = null;\n\n while (Date.now() - started < timeoutMs) {\n const sdk = Mushi.getInstance();\n if (sdk) {\n lastDiagnostics = await sdk.diagnose();\n if (lastDiagnostics.widgetMounted && lastDiagnostics.shadowDomAvailable) {\n return lastDiagnostics;\n }\n }\n await new Promise((r) => setTimeout(r, 100));\n }\n\n throw new Error(`[mushi:test-utils] SDK not ready: ${JSON.stringify(lastDiagnostics)}`);\n}\n\n/**\n * Run an optional action and fail if the SDK fires an api_cascade proactive\n * prompt during the observation window. This catches the exact glot.it class\n * of bug where Mushi reports on its own runtime-config/report endpoints.\n */\nexport async function expectNoMushiSelfCascade(options: {\n timeoutMs?: number;\n action?: () => void | Promise<void>;\n} = {}): Promise<void> {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n const timeoutMs = options.timeoutMs ?? 1_000;\n let cascade: unknown = null;\n const unsubscribe = sdk.on('proactive:triggered', (event) => {\n const payload = event.data as { type?: string } | undefined;\n if (payload?.type === 'api_cascade') cascade = event.data ?? true;\n });\n try {\n await options.action?.();\n await new Promise((r) => setTimeout(r, timeoutMs));\n } finally {\n unsubscribe();\n }\n if (cascade) {\n throw new Error(`[mushi:test-utils] unexpected api_cascade from SDK self-noise: ${JSON.stringify(cascade)}`);\n }\n}\n\n/**\n * Wait until the offline queue drains — useful after `triggerBug` in tests\n * that submit while offline then assert the report eventually syncs.\n * Resolves with the number of queued items remaining (0 = fully drained).\n */\nexport async function waitForQueueDrain(options: { timeoutMs?: number } = {}): Promise<number> {\n const sdk = Mushi.getInstance();\n if (!sdk) return 0;\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n // The SDK instance doesn't publicly expose the queue, but `getQueueSize`\n // has been in the contract since 0.2.x. We tolerate its absence so\n // upgrading doesn't break tests that only need triggerBug/openReport.\n const getQueueSize = (sdk as MushiSDKInstance & { getQueueSize?: () => number }).getQueueSize;\n if (typeof getQueueSize !== 'function') return 0;\n\n while (Date.now() - started < timeoutMs) {\n const remaining = getQueueSize.call(sdk);\n if (remaining === 0) return 0;\n await new Promise((r) => setTimeout(r, 100));\n }\n return getQueueSize.call(sdk);\n}\n"]}
1
+ {"version":3,"sources":["../src/test-utils.ts"],"names":[],"mappings":";;;;;;;AAyDA,eAAsB,UAAA,CAAW,IAAA,GAA0B,EAAC,EAA2B;AAErF,EAAU,OAAO,IAAA;AAqBnB;AAOO,SAAS,WAAW,QAAA,EAAsC;AAE/D,EAAU;AAEZ;AAGO,SAAS,gBAAgB,QAAA,EAAsC;AAEtE;AAOA,eAAsB,gBAAA,CAAiB,OAAA,GAAkC,EAAC,EAAoC;AAC5G,EAAA,MAAM,SAAA,GAAY,QAAQ,SAAA,IAAa,GAAA;AACvC,EAAA,MAAM,OAAA,GAAU,KAAK,GAAA,EAAI;AACzB,EAAA,IAAI,eAAA,GAAiD,IAAA;AAErD,EAAA,OAAO,IAAA,CAAK,GAAA,EAAI,GAAI,OAAA,GAAU,SAAA,EAAW;AAQvC,IAAA,MAAM,IAAI,OAAA,CAAQ,CAAC,MAAM,UAAA,CAAW,CAAA,EAAG,GAAG,CAAC,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,KAAK,SAAA,CAAU,eAAe,CAAC,CAAA,CAAE,CAAA;AACxF;AAOA,eAAsB,wBAAA,CAAyB,OAAA,GAG3C,EAAC,EAAkB;AAErB,EAAU;AAgBZ;AAOA,eAAsB,iBAAA,CAAkB,OAAA,GAAkC,EAAC,EAAoB;AAE7F,EAAU,OAAO,CAAA;AAenB","file":"test-utils.cjs","sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2024–2026 Kenji Sakuramoto (kensaurus) — Mushi Mushi\n/**\n * @mushi-mushi/web/test-utils\n *\n * Playwright / jsdom helpers for deterministic SDK tests. This module is\n * published as a separate entry-point so production bundles never pay the\n * cost — import it via `import { triggerBug, openReport } from\n * '@mushi-mushi/web/test-utils'`.\n *\n * Design goals:\n * 1. Zero production footprint. Nothing here is imported from `./mushi`,\n * `./widget`, or any runtime module. We reach for the live SDK via\n * `Mushi.getInstance()` so the test process sees exactly what the app\n * bootstrapped — no duplicate SDK singletons, no double-init races.\n * 2. Safe in a test harness even when Mushi is disabled. Every helper\n * no-ops when `Mushi.getInstance()` returns `null`, so Playwright\n * specs that conditionally wire Mushi (e.g. cloud vs local targets)\n * don't have to branch.\n * 3. Flat surface. Tests want 3 verbs: \"open the widget\", \"submit a\n * report programmatically\", \"wait until the SDK confirms the POST\n * landed\". Anything beyond that belongs in the app under test.\n */\n\nimport { Mushi } from './mushi';\nimport type {\n MushiDiagnosticsResult,\n MushiReportCategory,\n MushiSDKInstance,\n} from '@mushi-mushi/core';\n\n/** Options accepted by `triggerBug`. Mirrors the core report contract but\n * keeps every field optional so a Playwright test can say\n * `triggerBug({ description: 'button dead' })` without a category. */\nexport interface TriggerBugOptions {\n /** Short free-text description of the issue. Defaults to a marker\n * string so tests that forget to pass a description still produce a\n * distinguishable report in the admin console. */\n description?: string;\n /** Severity-free category tag. */\n category?: MushiReportCategory;\n /** Arbitrary metadata the test wants to round-trip. Merged on top of\n * whatever `setMetadata` has already stored. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Submit a report bypassing the widget UI. Returns the server-assigned\n * `reportId` when the POST lands, or `null` if Mushi isn't initialised in\n * this test context (or the submit failed — the SDK swallows network\n * errors silently by design).\n *\n * Use this from Playwright `page.evaluate(...)` calls to round-trip a\n * report into the backend without needing to drive the widget's DOM. It's\n * the fastest way to assert \"a bug report made it from the browser into\n * reports/ in Supabase\".\n */\nexport async function triggerBug(opts: TriggerBugOptions = {}): Promise<string | null> {\n const sdk = Mushi.getInstance();\n if (!sdk) return null;\n\n const description = opts.description\n ?? `[test-utils] triggerBug marker ${new Date().toISOString()}`;\n\n if (opts.metadata) {\n for (const [k, v] of Object.entries(opts.metadata)) {\n try { sdk.setMetadata(k, v); } catch { /* ignore */ }\n }\n }\n\n // `captureEvent` is the documented programmatic-submit API since 0.3.0\n // — it bypasses the widget, resolves with the server-assigned report\n // id, and participates in the same offline queue / pre-filter pipeline\n // as a widget submission.\n return await sdk.captureEvent({\n description,\n source: 'test-utils',\n ...(opts.category ? { category: opts.category } : {}),\n ...(opts.metadata ? { metadata: opts.metadata } : {}),\n });\n}\n\n/**\n * Programmatically open the Mushi widget without submitting anything. Use\n * for interaction tests that want to assert \"the widget is mounted and\n * reachable\" or to drive a user-like flow via Playwright selectors.\n */\nexport function openReport(category?: MushiReportCategory): void {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n sdk.report(category ? { category } : undefined);\n}\n\n/** Alias with language that reads better in Playwright smoke tests. */\nexport function openMushiWidget(category?: MushiReportCategory): void {\n openReport(category);\n}\n\n/**\n * Wait until the live SDK instance exists and reports a mounted widget.\n * Throws with the diagnostics payload so CI failures point at CSP / Shadow DOM\n * / capture setup instead of a generic timeout.\n */\nexport async function expectMushiReady(options: { timeoutMs?: number } = {}): Promise<MushiDiagnosticsResult> {\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n let lastDiagnostics: MushiDiagnosticsResult | null = null;\n\n while (Date.now() - started < timeoutMs) {\n const sdk = Mushi.getInstance();\n if (sdk) {\n lastDiagnostics = await sdk.diagnose();\n if (lastDiagnostics.widgetMounted && lastDiagnostics.shadowDomAvailable) {\n return lastDiagnostics;\n }\n }\n await new Promise((r) => setTimeout(r, 100));\n }\n\n throw new Error(`[mushi:test-utils] SDK not ready: ${JSON.stringify(lastDiagnostics)}`);\n}\n\n/**\n * Run an optional action and fail if the SDK fires an api_cascade proactive\n * prompt during the observation window. This catches the exact glot.it class\n * of bug where Mushi reports on its own runtime-config/report endpoints.\n */\nexport async function expectNoMushiSelfCascade(options: {\n timeoutMs?: number;\n action?: () => void | Promise<void>;\n} = {}): Promise<void> {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n const timeoutMs = options.timeoutMs ?? 1_000;\n let cascade: unknown = null;\n const unsubscribe = sdk.on('proactive:triggered', (event) => {\n const payload = event.data as { type?: string } | undefined;\n if (payload?.type === 'api_cascade') cascade = event.data ?? true;\n });\n try {\n await options.action?.();\n await new Promise((r) => setTimeout(r, timeoutMs));\n } finally {\n unsubscribe();\n }\n if (cascade) {\n throw new Error(`[mushi:test-utils] unexpected api_cascade from SDK self-noise: ${JSON.stringify(cascade)}`);\n }\n}\n\n/**\n * Wait until the offline queue drains — useful after `triggerBug` in tests\n * that submit while offline then assert the report eventually syncs.\n * Resolves with the number of queued items remaining (0 = fully drained).\n */\nexport async function waitForQueueDrain(options: { timeoutMs?: number } = {}): Promise<number> {\n const sdk = Mushi.getInstance();\n if (!sdk) return 0;\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n // The SDK instance doesn't publicly expose the queue, but `getQueueSize`\n // has been in the contract since 0.2.x. We tolerate its absence so\n // upgrading doesn't break tests that only need triggerBug/openReport.\n const getQueueSize = (sdk as MushiSDKInstance & { getQueueSize?: () => number }).getQueueSize;\n if (typeof getQueueSize !== 'function') return 0;\n\n while (Date.now() - started < timeoutMs) {\n const remaining = getQueueSize.call(sdk);\n if (remaining === 0) return 0;\n await new Promise((r) => setTimeout(r, 100));\n }\n return getQueueSize.call(sdk);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/test-utils.ts"],"names":[],"mappings":";;;;;AAuDA,eAAsB,UAAA,CAAW,IAAA,GAA0B,EAAC,EAA2B;AAErF,EAAU,OAAO,IAAA;AAqBnB;AAOO,SAAS,WAAW,QAAA,EAAsC;AAE/D,EAAU;AAEZ;AAGO,SAAS,gBAAgB,QAAA,EAAsC;AAEtE;AAOA,eAAsB,gBAAA,CAAiB,OAAA,GAAkC,EAAC,EAAoC;AAC5G,EAAA,MAAM,SAAA,GAAY,QAAQ,SAAA,IAAa,GAAA;AACvC,EAAA,MAAM,OAAA,GAAU,KAAK,GAAA,EAAI;AACzB,EAAA,IAAI,eAAA,GAAiD,IAAA;AAErD,EAAA,OAAO,IAAA,CAAK,GAAA,EAAI,GAAI,OAAA,GAAU,SAAA,EAAW;AAQvC,IAAA,MAAM,IAAI,OAAA,CAAQ,CAAC,MAAM,UAAA,CAAW,CAAA,EAAG,GAAG,CAAC,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,KAAK,SAAA,CAAU,eAAe,CAAC,CAAA,CAAE,CAAA;AACxF;AAOA,eAAsB,wBAAA,CAAyB,OAAA,GAG3C,EAAC,EAAkB;AAErB,EAAU;AAgBZ;AAOA,eAAsB,iBAAA,CAAkB,OAAA,GAAkC,EAAC,EAAoB;AAE7F,EAAU,OAAO,CAAA;AAenB","file":"test-utils.js","sourcesContent":["/**\n * @mushi-mushi/web/test-utils\n *\n * Playwright / jsdom helpers for deterministic SDK tests. This module is\n * published as a separate entry-point so production bundles never pay the\n * cost — import it via `import { triggerBug, openReport } from\n * '@mushi-mushi/web/test-utils'`.\n *\n * Design goals:\n * 1. Zero production footprint. Nothing here is imported from `./mushi`,\n * `./widget`, or any runtime module. We reach for the live SDK via\n * `Mushi.getInstance()` so the test process sees exactly what the app\n * bootstrapped — no duplicate SDK singletons, no double-init races.\n * 2. Safe in a test harness even when Mushi is disabled. Every helper\n * no-ops when `Mushi.getInstance()` returns `null`, so Playwright\n * specs that conditionally wire Mushi (e.g. cloud vs local targets)\n * don't have to branch.\n * 3. Flat surface. Tests want 3 verbs: \"open the widget\", \"submit a\n * report programmatically\", \"wait until the SDK confirms the POST\n * landed\". Anything beyond that belongs in the app under test.\n */\n\nimport { Mushi } from './mushi';\nimport type {\n MushiDiagnosticsResult,\n MushiReportCategory,\n MushiSDKInstance,\n} from '@mushi-mushi/core';\n\n/** Options accepted by `triggerBug`. Mirrors the core report contract but\n * keeps every field optional so a Playwright test can say\n * `triggerBug({ description: 'button dead' })` without a category. */\nexport interface TriggerBugOptions {\n /** Short free-text description of the issue. Defaults to a marker\n * string so tests that forget to pass a description still produce a\n * distinguishable report in the admin console. */\n description?: string;\n /** Severity-free category tag. */\n category?: MushiReportCategory;\n /** Arbitrary metadata the test wants to round-trip. Merged on top of\n * whatever `setMetadata` has already stored. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Submit a report bypassing the widget UI. Returns the server-assigned\n * `reportId` when the POST lands, or `null` if Mushi isn't initialised in\n * this test context (or the submit failed — the SDK swallows network\n * errors silently by design).\n *\n * Use this from Playwright `page.evaluate(...)` calls to round-trip a\n * report into the backend without needing to drive the widget's DOM. It's\n * the fastest way to assert \"a bug report made it from the browser into\n * reports/ in Supabase\".\n */\nexport async function triggerBug(opts: TriggerBugOptions = {}): Promise<string | null> {\n const sdk = Mushi.getInstance();\n if (!sdk) return null;\n\n const description = opts.description\n ?? `[test-utils] triggerBug marker ${new Date().toISOString()}`;\n\n if (opts.metadata) {\n for (const [k, v] of Object.entries(opts.metadata)) {\n try { sdk.setMetadata(k, v); } catch { /* ignore */ }\n }\n }\n\n // `captureEvent` is the documented programmatic-submit API since 0.3.0\n // — it bypasses the widget, resolves with the server-assigned report\n // id, and participates in the same offline queue / pre-filter pipeline\n // as a widget submission.\n return await sdk.captureEvent({\n description,\n source: 'test-utils',\n ...(opts.category ? { category: opts.category } : {}),\n ...(opts.metadata ? { metadata: opts.metadata } : {}),\n });\n}\n\n/**\n * Programmatically open the Mushi widget without submitting anything. Use\n * for interaction tests that want to assert \"the widget is mounted and\n * reachable\" or to drive a user-like flow via Playwright selectors.\n */\nexport function openReport(category?: MushiReportCategory): void {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n sdk.report(category ? { category } : undefined);\n}\n\n/** Alias with language that reads better in Playwright smoke tests. */\nexport function openMushiWidget(category?: MushiReportCategory): void {\n openReport(category);\n}\n\n/**\n * Wait until the live SDK instance exists and reports a mounted widget.\n * Throws with the diagnostics payload so CI failures point at CSP / Shadow DOM\n * / capture setup instead of a generic timeout.\n */\nexport async function expectMushiReady(options: { timeoutMs?: number } = {}): Promise<MushiDiagnosticsResult> {\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n let lastDiagnostics: MushiDiagnosticsResult | null = null;\n\n while (Date.now() - started < timeoutMs) {\n const sdk = Mushi.getInstance();\n if (sdk) {\n lastDiagnostics = await sdk.diagnose();\n if (lastDiagnostics.widgetMounted && lastDiagnostics.shadowDomAvailable) {\n return lastDiagnostics;\n }\n }\n await new Promise((r) => setTimeout(r, 100));\n }\n\n throw new Error(`[mushi:test-utils] SDK not ready: ${JSON.stringify(lastDiagnostics)}`);\n}\n\n/**\n * Run an optional action and fail if the SDK fires an api_cascade proactive\n * prompt during the observation window. This catches the exact glot.it class\n * of bug where Mushi reports on its own runtime-config/report endpoints.\n */\nexport async function expectNoMushiSelfCascade(options: {\n timeoutMs?: number;\n action?: () => void | Promise<void>;\n} = {}): Promise<void> {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n const timeoutMs = options.timeoutMs ?? 1_000;\n let cascade: unknown = null;\n const unsubscribe = sdk.on('proactive:triggered', (event) => {\n const payload = event.data as { type?: string } | undefined;\n if (payload?.type === 'api_cascade') cascade = event.data ?? true;\n });\n try {\n await options.action?.();\n await new Promise((r) => setTimeout(r, timeoutMs));\n } finally {\n unsubscribe();\n }\n if (cascade) {\n throw new Error(`[mushi:test-utils] unexpected api_cascade from SDK self-noise: ${JSON.stringify(cascade)}`);\n }\n}\n\n/**\n * Wait until the offline queue drains — useful after `triggerBug` in tests\n * that submit while offline then assert the report eventually syncs.\n * Resolves with the number of queued items remaining (0 = fully drained).\n */\nexport async function waitForQueueDrain(options: { timeoutMs?: number } = {}): Promise<number> {\n const sdk = Mushi.getInstance();\n if (!sdk) return 0;\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n // The SDK instance doesn't publicly expose the queue, but `getQueueSize`\n // has been in the contract since 0.2.x. We tolerate its absence so\n // upgrading doesn't break tests that only need triggerBug/openReport.\n const getQueueSize = (sdk as MushiSDKInstance & { getQueueSize?: () => number }).getQueueSize;\n if (typeof getQueueSize !== 'function') return 0;\n\n while (Date.now() - started < timeoutMs) {\n const remaining = getQueueSize.call(sdk);\n if (remaining === 0) return 0;\n await new Promise((r) => setTimeout(r, 100));\n }\n return getQueueSize.call(sdk);\n}\n"]}
1
+ {"version":3,"sources":["../src/test-utils.ts"],"names":[],"mappings":";;;;;AAyDA,eAAsB,UAAA,CAAW,IAAA,GAA0B,EAAC,EAA2B;AAErF,EAAU,OAAO,IAAA;AAqBnB;AAOO,SAAS,WAAW,QAAA,EAAsC;AAE/D,EAAU;AAEZ;AAGO,SAAS,gBAAgB,QAAA,EAAsC;AAEtE;AAOA,eAAsB,gBAAA,CAAiB,OAAA,GAAkC,EAAC,EAAoC;AAC5G,EAAA,MAAM,SAAA,GAAY,QAAQ,SAAA,IAAa,GAAA;AACvC,EAAA,MAAM,OAAA,GAAU,KAAK,GAAA,EAAI;AACzB,EAAA,IAAI,eAAA,GAAiD,IAAA;AAErD,EAAA,OAAO,IAAA,CAAK,GAAA,EAAI,GAAI,OAAA,GAAU,SAAA,EAAW;AAQvC,IAAA,MAAM,IAAI,OAAA,CAAQ,CAAC,MAAM,UAAA,CAAW,CAAA,EAAG,GAAG,CAAC,CAAA;AAAA,EAC7C;AAEA,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,KAAK,SAAA,CAAU,eAAe,CAAC,CAAA,CAAE,CAAA;AACxF;AAOA,eAAsB,wBAAA,CAAyB,OAAA,GAG3C,EAAC,EAAkB;AAErB,EAAU;AAgBZ;AAOA,eAAsB,iBAAA,CAAkB,OAAA,GAAkC,EAAC,EAAoB;AAE7F,EAAU,OAAO,CAAA;AAenB","file":"test-utils.js","sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2024–2026 Kenji Sakuramoto (kensaurus) — Mushi Mushi\n/**\n * @mushi-mushi/web/test-utils\n *\n * Playwright / jsdom helpers for deterministic SDK tests. This module is\n * published as a separate entry-point so production bundles never pay the\n * cost — import it via `import { triggerBug, openReport } from\n * '@mushi-mushi/web/test-utils'`.\n *\n * Design goals:\n * 1. Zero production footprint. Nothing here is imported from `./mushi`,\n * `./widget`, or any runtime module. We reach for the live SDK via\n * `Mushi.getInstance()` so the test process sees exactly what the app\n * bootstrapped — no duplicate SDK singletons, no double-init races.\n * 2. Safe in a test harness even when Mushi is disabled. Every helper\n * no-ops when `Mushi.getInstance()` returns `null`, so Playwright\n * specs that conditionally wire Mushi (e.g. cloud vs local targets)\n * don't have to branch.\n * 3. Flat surface. Tests want 3 verbs: \"open the widget\", \"submit a\n * report programmatically\", \"wait until the SDK confirms the POST\n * landed\". Anything beyond that belongs in the app under test.\n */\n\nimport { Mushi } from './mushi';\nimport type {\n MushiDiagnosticsResult,\n MushiReportCategory,\n MushiSDKInstance,\n} from '@mushi-mushi/core';\n\n/** Options accepted by `triggerBug`. Mirrors the core report contract but\n * keeps every field optional so a Playwright test can say\n * `triggerBug({ description: 'button dead' })` without a category. */\nexport interface TriggerBugOptions {\n /** Short free-text description of the issue. Defaults to a marker\n * string so tests that forget to pass a description still produce a\n * distinguishable report in the admin console. */\n description?: string;\n /** Severity-free category tag. */\n category?: MushiReportCategory;\n /** Arbitrary metadata the test wants to round-trip. Merged on top of\n * whatever `setMetadata` has already stored. */\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Submit a report bypassing the widget UI. Returns the server-assigned\n * `reportId` when the POST lands, or `null` if Mushi isn't initialised in\n * this test context (or the submit failed — the SDK swallows network\n * errors silently by design).\n *\n * Use this from Playwright `page.evaluate(...)` calls to round-trip a\n * report into the backend without needing to drive the widget's DOM. It's\n * the fastest way to assert \"a bug report made it from the browser into\n * reports/ in Supabase\".\n */\nexport async function triggerBug(opts: TriggerBugOptions = {}): Promise<string | null> {\n const sdk = Mushi.getInstance();\n if (!sdk) return null;\n\n const description = opts.description\n ?? `[test-utils] triggerBug marker ${new Date().toISOString()}`;\n\n if (opts.metadata) {\n for (const [k, v] of Object.entries(opts.metadata)) {\n try { sdk.setMetadata(k, v); } catch { /* ignore */ }\n }\n }\n\n // `captureEvent` is the documented programmatic-submit API since 0.3.0\n // — it bypasses the widget, resolves with the server-assigned report\n // id, and participates in the same offline queue / pre-filter pipeline\n // as a widget submission.\n return await sdk.captureEvent({\n description,\n source: 'test-utils',\n ...(opts.category ? { category: opts.category } : {}),\n ...(opts.metadata ? { metadata: opts.metadata } : {}),\n });\n}\n\n/**\n * Programmatically open the Mushi widget without submitting anything. Use\n * for interaction tests that want to assert \"the widget is mounted and\n * reachable\" or to drive a user-like flow via Playwright selectors.\n */\nexport function openReport(category?: MushiReportCategory): void {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n sdk.report(category ? { category } : undefined);\n}\n\n/** Alias with language that reads better in Playwright smoke tests. */\nexport function openMushiWidget(category?: MushiReportCategory): void {\n openReport(category);\n}\n\n/**\n * Wait until the live SDK instance exists and reports a mounted widget.\n * Throws with the diagnostics payload so CI failures point at CSP / Shadow DOM\n * / capture setup instead of a generic timeout.\n */\nexport async function expectMushiReady(options: { timeoutMs?: number } = {}): Promise<MushiDiagnosticsResult> {\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n let lastDiagnostics: MushiDiagnosticsResult | null = null;\n\n while (Date.now() - started < timeoutMs) {\n const sdk = Mushi.getInstance();\n if (sdk) {\n lastDiagnostics = await sdk.diagnose();\n if (lastDiagnostics.widgetMounted && lastDiagnostics.shadowDomAvailable) {\n return lastDiagnostics;\n }\n }\n await new Promise((r) => setTimeout(r, 100));\n }\n\n throw new Error(`[mushi:test-utils] SDK not ready: ${JSON.stringify(lastDiagnostics)}`);\n}\n\n/**\n * Run an optional action and fail if the SDK fires an api_cascade proactive\n * prompt during the observation window. This catches the exact glot.it class\n * of bug where Mushi reports on its own runtime-config/report endpoints.\n */\nexport async function expectNoMushiSelfCascade(options: {\n timeoutMs?: number;\n action?: () => void | Promise<void>;\n} = {}): Promise<void> {\n const sdk = Mushi.getInstance();\n if (!sdk) return;\n const timeoutMs = options.timeoutMs ?? 1_000;\n let cascade: unknown = null;\n const unsubscribe = sdk.on('proactive:triggered', (event) => {\n const payload = event.data as { type?: string } | undefined;\n if (payload?.type === 'api_cascade') cascade = event.data ?? true;\n });\n try {\n await options.action?.();\n await new Promise((r) => setTimeout(r, timeoutMs));\n } finally {\n unsubscribe();\n }\n if (cascade) {\n throw new Error(`[mushi:test-utils] unexpected api_cascade from SDK self-noise: ${JSON.stringify(cascade)}`);\n }\n}\n\n/**\n * Wait until the offline queue drains — useful after `triggerBug` in tests\n * that submit while offline then assert the report eventually syncs.\n * Resolves with the number of queued items remaining (0 = fully drained).\n */\nexport async function waitForQueueDrain(options: { timeoutMs?: number } = {}): Promise<number> {\n const sdk = Mushi.getInstance();\n if (!sdk) return 0;\n const timeoutMs = options.timeoutMs ?? 5_000;\n const started = Date.now();\n // The SDK instance doesn't publicly expose the queue, but `getQueueSize`\n // has been in the contract since 0.2.x. We tolerate its absence so\n // upgrading doesn't break tests that only need triggerBug/openReport.\n const getQueueSize = (sdk as MushiSDKInstance & { getQueueSize?: () => number }).getQueueSize;\n if (typeof getQueueSize !== 'function') return 0;\n\n while (Date.now() - started < timeoutMs) {\n const remaining = getQueueSize.call(sdk);\n if (remaining === 0) return 0;\n await new Promise((r) => setTimeout(r, 100));\n }\n return getQueueSize.call(sdk);\n}\n"]}
package/package.json CHANGED
@@ -1,46 +1,86 @@
1
1
  {
2
2
  "name": "@mushi-mushi/web",
3
- "version": "1.27.0",
4
- "description": "Mushi Mushi browser SDK — embeddable bug reporting widget with Shadow DOM isolation",
3
+ "version": "1.29.0",
4
+ "description": "Bug report and user feedback widget for the web. The bug mediator for AI-built apps: plain-English diagnosis + a ready fix, in your editor.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
9
9
  "types": "./dist/index.d.ts",
10
+ "unpkg": "./dist/mushi.loader.global.js",
11
+ "jsdelivr": "./dist/mushi.loader.global.js",
10
12
  "exports": {
11
13
  ".": {
12
- "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js",
14
- "require": "./dist/index.cjs"
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.cts",
20
+ "default": "./dist/index.cjs"
21
+ }
15
22
  },
16
23
  "./test-utils": {
17
- "types": "./dist/test-utils.d.ts",
18
- "import": "./dist/test-utils.js",
19
- "require": "./dist/test-utils.cjs"
24
+ "import": {
25
+ "types": "./dist/test-utils.d.ts",
26
+ "default": "./dist/test-utils.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/test-utils.d.cts",
30
+ "default": "./dist/test-utils.cjs"
31
+ }
20
32
  },
21
33
  "./i18n": {
22
- "types": "./dist/i18n/index.d.ts",
23
- "import": "./dist/i18n/index.js",
24
- "require": "./dist/i18n/index.cjs"
34
+ "import": {
35
+ "types": "./dist/i18n/index.d.ts",
36
+ "default": "./dist/i18n/index.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/i18n/index.d.cts",
40
+ "default": "./dist/i18n/index.cjs"
41
+ }
25
42
  },
26
43
  "./otel": {
27
- "types": "./dist/otel.d.ts",
28
- "import": "./dist/otel.js",
29
- "require": "./dist/otel.cjs"
44
+ "import": {
45
+ "types": "./dist/otel.d.ts",
46
+ "default": "./dist/otel.js"
47
+ },
48
+ "require": {
49
+ "types": "./dist/otel.d.cts",
50
+ "default": "./dist/otel.cjs"
51
+ }
30
52
  },
31
53
  "./headless": {
32
- "types": "./dist/headless.d.ts",
33
- "import": "./dist/headless.js",
34
- "require": "./dist/headless.cjs"
54
+ "import": {
55
+ "types": "./dist/headless.d.ts",
56
+ "default": "./dist/headless.js"
57
+ },
58
+ "require": {
59
+ "types": "./dist/headless.d.cts",
60
+ "default": "./dist/headless.cjs"
61
+ }
62
+ }
63
+ },
64
+ "typesVersions": {
65
+ "*": {
66
+ "test-utils": [
67
+ "./dist/test-utils.d.ts"
68
+ ],
69
+ "i18n": [
70
+ "./dist/i18n/index.d.ts"
71
+ ],
72
+ "otel": [
73
+ "./dist/otel.d.ts"
74
+ ],
75
+ "headless": [
76
+ "./dist/headless.d.ts"
77
+ ]
35
78
  }
36
79
  },
37
80
  "files": [
38
81
  "dist",
39
82
  "README.md",
40
- "LICENSE",
41
- "CONTRIBUTING.md",
42
- "CODE_OF_CONDUCT.md",
43
- "SECURITY.md"
83
+ "LICENSE"
44
84
  ],
45
85
  "repository": {
46
86
  "type": "git",
@@ -53,6 +93,7 @@
53
93
  },
54
94
  "keywords": [
55
95
  "mushi-mushi",
96
+ "bug-report-widget",
56
97
  "bug-translation",
57
98
  "vibe-coding",
58
99
  "ai-debugging",
@@ -72,7 +113,6 @@
72
113
  "svelte",
73
114
  "angular",
74
115
  "sentry-companion",
75
- "sentry-alternative",
76
116
  "ai-agent",
77
117
  "sdk"
78
118
  ],
@@ -85,7 +125,7 @@
85
125
  {
86
126
  "name": "Core SDK bundle (minified + gzipped)",
87
127
  "path": "dist/index.js",
88
- "limit": "88 KB",
128
+ "limit": "89.5 KB",
89
129
  "gzip": true
90
130
  },
91
131
  {
@@ -107,30 +147,32 @@
107
147
  }
108
148
  ],
109
149
  "dependencies": {
110
- "@mushi-mushi/core": "^1.27.0"
150
+ "@mushi-mushi/core": "^1.29.0"
111
151
  },
112
- "optionalDependencies": {
152
+ "peerDependencies": {
113
153
  "rrweb": "^2.0.1"
114
154
  },
155
+ "peerDependenciesMeta": {
156
+ "rrweb": {
157
+ "optional": true
158
+ }
159
+ },
115
160
  "devDependencies": {
116
161
  "@size-limit/file": "^12.1.0",
117
162
  "eslint": "^10.6.0",
118
163
  "jsdom": "^29.1.1",
164
+ "rrweb": "^2.0.1",
119
165
  "size-limit": "^12.1.0",
120
166
  "tsup": "^8.5.1",
121
167
  "typescript": "^6.0.3",
122
168
  "vitest": "^4.1.9",
123
- "@mushi-mushi/eslint-config": "0.0.0",
169
+ "eslint-plugin-mushi-mushi": "0.3.4",
124
170
  "@mushi-mushi/tsconfig": "0.0.0",
125
- "eslint-plugin-mushi-mushi": "0.3.2"
171
+ "@mushi-mushi/eslint-config": "0.0.0"
126
172
  },
127
- "author": "Kenji Sakuramoto (https://bsky.app/profile/mushimushi.dev)",
173
+ "author": "Kenji Sakuramoto <kensaurus@gmail.com> (https://github.com/kensaurus)",
128
174
  "engines": {
129
- "node": ">=20"
130
- },
131
- "funding": {
132
- "type": "github",
133
- "url": "https://github.com/sponsors/kensaurus"
175
+ "node": ">=20.19.0"
134
176
  },
135
177
  "scripts": {
136
178
  "build": "tsup",
@@ -1,51 +0,0 @@
1
- <!--
2
- AUTO-SYNCED from repo root by scripts/sync-community-files.mjs.
3
- Do not edit here — edit the canonical file at the repository root and
4
- re-run `node scripts/sync-community-files.mjs` (pre-commit hook does this
5
- automatically).
6
- -->
7
-
8
- # Contributor Covenant Code of Conduct
9
-
10
- ## Our Pledge
11
-
12
- We as members, contributors, and leaders pledge to make participation in our
13
- community a harassment-free experience for everyone, regardless of age, body
14
- size, visible or invisible disability, ethnicity, sex characteristics, gender
15
- identity and expression, level of experience, education, socio-economic status,
16
- nationality, personal appearance, race, caste, color, religion, or sexual
17
- identity and orientation.
18
-
19
- We pledge to act and interact in ways that contribute to an open, welcoming,
20
- diverse, inclusive, and healthy community.
21
-
22
- ## Our Standards
23
-
24
- Examples of behavior that contributes to a positive environment:
25
-
26
- - Using welcoming and inclusive language
27
- - Being respectful of differing viewpoints and experiences
28
- - Gracefully accepting constructive criticism
29
- - Focusing on what is best for the community
30
- - Showing empathy towards other community members
31
-
32
- Examples of unacceptable behavior:
33
-
34
- - The use of sexualized language or imagery, and sexual attention or advances of any kind
35
- - Trolling, insulting or derogatory comments, and personal or political attacks
36
- - Public or private harassment
37
- - Publishing others' private information without explicit permission
38
- - Other conduct which could reasonably be considered inappropriate in a professional setting
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
43
- reported to the project team at **kensaurus@gmail.com**.
44
-
45
- All complaints will be reviewed and investigated promptly and fairly.
46
-
47
- ## Attribution
48
-
49
- This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/),
50
- version 2.1, available at
51
- https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.