@mushi-mushi/svelte 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kenji Sakuramoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @mushi-mushi/svelte
2
+
3
+ Svelte SDK for Mushi Mushi bug reporting.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import { initMushi, getMushi } from '@mushi-mushi/svelte'
9
+
10
+ initMushi({ projectId: 'proj_xxx', apiKey: 'mushi_xxx' })
11
+
12
+ // Later
13
+ const mushi = getMushi()
14
+ mushi.submitReport({ title: 'broken', description: '...' })
15
+ ```
16
+
17
+ ### SvelteKit error handler
18
+
19
+ ```ts
20
+ import { createMushiErrorHandler } from '@mushi-mushi/svelte'
21
+
22
+ export const handleError = createMushiErrorHandler()
23
+ ```
24
+
25
+ ## Peer Dependencies
26
+
27
+ - `svelte` >= 4
28
+
29
+ ## License
30
+
31
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createMushiErrorHandler: () => createMushiErrorHandler,
24
+ getMushi: () => getMushi,
25
+ initMushi: () => initMushi
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var import_core = require("@mushi-mushi/core");
29
+ var log = (0, import_core.createLogger)({ scope: "mushi:svelte" });
30
+ var _instance = null;
31
+ var _client = null;
32
+ var _projectId = "";
33
+ function buildReport(data) {
34
+ return {
35
+ id: crypto.randomUUID?.() ?? `mushi_${Date.now()}_${Math.random().toString(36).slice(2)}`,
36
+ projectId: _projectId,
37
+ description: data.description,
38
+ category: data.category,
39
+ environment: (0, import_core.captureEnvironment)(),
40
+ metadata: data.metadata,
41
+ sessionId: (0, import_core.getSessionId)(),
42
+ reporterToken: (0, import_core.getReporterToken)(),
43
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
44
+ };
45
+ }
46
+ function initMushi(config) {
47
+ _projectId = config.projectId;
48
+ _client = (0, import_core.createApiClient)({
49
+ projectId: config.projectId,
50
+ apiKey: config.apiKey,
51
+ apiEndpoint: config.endpoint ?? "https://api.mushimushi.dev"
52
+ });
53
+ _instance = {
54
+ async submitReport(data) {
55
+ if (!_client) throw new Error("Call initMushi() first");
56
+ await _client.submitReport(buildReport(data));
57
+ },
58
+ captureError(err, context) {
59
+ const description = err instanceof Error ? err.message : String(err);
60
+ _instance?.submitReport({
61
+ description,
62
+ category: "bug",
63
+ metadata: { stack: err instanceof Error ? err.stack : void 0, ...context }
64
+ }).catch((e) => log.error("Failed to capture error", { err: String(e) }));
65
+ }
66
+ };
67
+ return _instance;
68
+ }
69
+ function getMushi() {
70
+ if (!_instance) throw new Error("Call initMushi() first");
71
+ return _instance;
72
+ }
73
+ function createMushiErrorHandler() {
74
+ return ({ error, event }) => {
75
+ if (_instance) {
76
+ _instance.captureError(error, { route: event?.url?.pathname });
77
+ }
78
+ };
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ createMushiErrorHandler,
83
+ getMushi,
84
+ initMushi
85
+ });
@@ -0,0 +1,33 @@
1
+ import { MushiReportCategory } from '@mushi-mushi/core';
2
+
3
+ /**
4
+ * FILE: packages/svelte/src/index.ts
5
+ * PURPOSE: Svelte SDK for Mushi Mushi — init, report submission,
6
+ * and SvelteKit error handler via @mushi-mushi/core.
7
+ */
8
+
9
+ interface MushiConfig {
10
+ projectId: string;
11
+ apiKey: string;
12
+ endpoint?: string;
13
+ }
14
+ interface MushiInstance {
15
+ submitReport(data: {
16
+ description: string;
17
+ category: MushiReportCategory;
18
+ metadata?: Record<string, unknown>;
19
+ }): Promise<void>;
20
+ captureError(err: unknown, context?: Record<string, unknown>): void;
21
+ }
22
+ declare function initMushi(config: MushiConfig): MushiInstance;
23
+ declare function getMushi(): MushiInstance;
24
+ declare function createMushiErrorHandler(): ({ error, event }: {
25
+ error: unknown;
26
+ event?: {
27
+ url?: {
28
+ pathname?: string;
29
+ };
30
+ };
31
+ }) => void;
32
+
33
+ export { type MushiConfig, createMushiErrorHandler, getMushi, initMushi };
@@ -0,0 +1,33 @@
1
+ import { MushiReportCategory } from '@mushi-mushi/core';
2
+
3
+ /**
4
+ * FILE: packages/svelte/src/index.ts
5
+ * PURPOSE: Svelte SDK for Mushi Mushi — init, report submission,
6
+ * and SvelteKit error handler via @mushi-mushi/core.
7
+ */
8
+
9
+ interface MushiConfig {
10
+ projectId: string;
11
+ apiKey: string;
12
+ endpoint?: string;
13
+ }
14
+ interface MushiInstance {
15
+ submitReport(data: {
16
+ description: string;
17
+ category: MushiReportCategory;
18
+ metadata?: Record<string, unknown>;
19
+ }): Promise<void>;
20
+ captureError(err: unknown, context?: Record<string, unknown>): void;
21
+ }
22
+ declare function initMushi(config: MushiConfig): MushiInstance;
23
+ declare function getMushi(): MushiInstance;
24
+ declare function createMushiErrorHandler(): ({ error, event }: {
25
+ error: unknown;
26
+ event?: {
27
+ url?: {
28
+ pathname?: string;
29
+ };
30
+ };
31
+ }) => void;
32
+
33
+ export { type MushiConfig, createMushiErrorHandler, getMushi, initMushi };
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ // src/index.ts
2
+ import { createApiClient, captureEnvironment, getSessionId, getReporterToken, createLogger } from "@mushi-mushi/core";
3
+ var log = createLogger({ scope: "mushi:svelte" });
4
+ var _instance = null;
5
+ var _client = null;
6
+ var _projectId = "";
7
+ function buildReport(data) {
8
+ return {
9
+ id: crypto.randomUUID?.() ?? `mushi_${Date.now()}_${Math.random().toString(36).slice(2)}`,
10
+ projectId: _projectId,
11
+ description: data.description,
12
+ category: data.category,
13
+ environment: captureEnvironment(),
14
+ metadata: data.metadata,
15
+ sessionId: getSessionId(),
16
+ reporterToken: getReporterToken(),
17
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
18
+ };
19
+ }
20
+ function initMushi(config) {
21
+ _projectId = config.projectId;
22
+ _client = createApiClient({
23
+ projectId: config.projectId,
24
+ apiKey: config.apiKey,
25
+ apiEndpoint: config.endpoint ?? "https://api.mushimushi.dev"
26
+ });
27
+ _instance = {
28
+ async submitReport(data) {
29
+ if (!_client) throw new Error("Call initMushi() first");
30
+ await _client.submitReport(buildReport(data));
31
+ },
32
+ captureError(err, context) {
33
+ const description = err instanceof Error ? err.message : String(err);
34
+ _instance?.submitReport({
35
+ description,
36
+ category: "bug",
37
+ metadata: { stack: err instanceof Error ? err.stack : void 0, ...context }
38
+ }).catch((e) => log.error("Failed to capture error", { err: String(e) }));
39
+ }
40
+ };
41
+ return _instance;
42
+ }
43
+ function getMushi() {
44
+ if (!_instance) throw new Error("Call initMushi() first");
45
+ return _instance;
46
+ }
47
+ function createMushiErrorHandler() {
48
+ return ({ error, event }) => {
49
+ if (_instance) {
50
+ _instance.captureError(error, { route: event?.url?.pathname });
51
+ }
52
+ };
53
+ }
54
+ export {
55
+ createMushiErrorHandler,
56
+ getMushi,
57
+ initMushi
58
+ };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@mushi-mushi/svelte",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Svelte SDK for Mushi Mushi — context-based init, SvelteKit error hook integration",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "scripts": {
10
+ "build": "tsup",
11
+ "lint": "eslint src/",
12
+ "test": "echo 'no tests yet'",
13
+ "typecheck": "tsc --noEmit"
14
+ },
15
+ "peerDependencies": {
16
+ "svelte": ">=4"
17
+ },
18
+ "dependencies": {
19
+ "@mushi-mushi/core": "workspace:*"
20
+ },
21
+ "devDependencies": {
22
+ "@mushi-mushi/eslint-config": "workspace:*",
23
+ "eslint": "^9.39.4",
24
+ "svelte": "^5.0.0",
25
+ "tsup": "^8.5.1",
26
+ "typescript": "^5.9.3"
27
+ },
28
+ "author": "Kenji Sakuramoto",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/kensaurus/mushi-mushi.git",
32
+ "directory": "packages/svelte"
33
+ },
34
+ "homepage": "https://github.com/kensaurus/mushi-mushi/tree/main/packages/svelte#readme",
35
+ "bugs": {
36
+ "url": "https://github.com/kensaurus/mushi-mushi/issues"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md",
44
+ "LICENSE"
45
+ ],
46
+ "sideEffects": false,
47
+ "keywords": [
48
+ "mushi-mushi",
49
+ "bug-reporting",
50
+ "sdk"
51
+ ],
52
+ "exports": {
53
+ ".": {
54
+ "import": {
55
+ "types": "./dist/index.d.ts",
56
+ "default": "./dist/index.js"
57
+ },
58
+ "require": {
59
+ "types": "./dist/index.d.cts",
60
+ "default": "./dist/index.cjs"
61
+ }
62
+ }
63
+ },
64
+ "type": "module"
65
+ }