@mushi-mushi/web 0.2.1 → 0.3.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/index.cjs CHANGED
@@ -1642,6 +1642,58 @@ function createInstance(config) {
1642
1642
  listeners.clear();
1643
1643
  instance = null;
1644
1644
  log.debug("Destroyed");
1645
+ },
1646
+ // Wave G4 — unified `captureEvent` API for programmatic/adapter-driven
1647
+ // reports. Skips the widget, runs the same PII scrub + rate limit +
1648
+ // offline-queue path as `submit()`, and returns the server report id.
1649
+ async captureEvent(input) {
1650
+ if (!rateLimiter.tryConsume()) {
1651
+ log.warn("captureEvent throttled \u2014 rate limit exceeded");
1652
+ return null;
1653
+ }
1654
+ const description = piiScrubber.scrub(preFilter.truncate(input.description));
1655
+ const category = input.category ?? "bug";
1656
+ const report = {
1657
+ id: crypto.randomUUID?.() ?? `mushi_${Date.now()}_${Math.random().toString(36).slice(2)}`,
1658
+ projectId: config.projectId,
1659
+ category,
1660
+ description,
1661
+ environment: core.captureEnvironment(),
1662
+ metadata: {
1663
+ ...input.metadata ?? {},
1664
+ ...userInfo ? { user: userInfo } : {},
1665
+ ...input.tags ? { tags: input.tags } : {},
1666
+ ...input.error ? { error: input.error } : {},
1667
+ ...input.severity ? { severity: input.severity } : {},
1668
+ ...input.component ? { component: input.component } : {},
1669
+ ...input.source ? { source: input.source } : { source: "captureEvent" }
1670
+ },
1671
+ sessionId: core.getSessionId(),
1672
+ reporterToken: core.getReporterToken(),
1673
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
1674
+ };
1675
+ emit("report:submitted", { reportId: report.id });
1676
+ if (typeof navigator !== "undefined" && !navigator.onLine) {
1677
+ await offlineQueue.enqueue(report);
1678
+ emit("report:queued", { reportId: report.id });
1679
+ return null;
1680
+ }
1681
+ const res = await apiClient.submitReport(report);
1682
+ if (res.ok) {
1683
+ emit("report:sent", { reportId: res.data?.reportId });
1684
+ return res.data?.reportId ?? null;
1685
+ }
1686
+ await offlineQueue.enqueue(report);
1687
+ emit("report:failed", { reportId: report.id, error: res.error });
1688
+ return null;
1689
+ },
1690
+ identify(userId, traits) {
1691
+ userInfo = { id: userId, ...traits?.email ? { email: traits.email } : {}, ...traits?.name ? { name: traits.name } : {} };
1692
+ if (traits) {
1693
+ for (const [k, v] of Object.entries(traits)) {
1694
+ if (k !== "email" && k !== "name") customMetadata[`user.${k}`] = v;
1695
+ }
1696
+ }
1645
1697
  }
1646
1698
  };
1647
1699
  return sdk;
@@ -1663,6 +1715,9 @@ function createNoopInstance() {
1663
1715
  },
1664
1716
  destroy: () => {
1665
1717
  instance = null;
1718
+ },
1719
+ captureEvent: async () => null,
1720
+ identify: () => {
1666
1721
  }
1667
1722
  };
1668
1723
  }