@monkfeed-sdk/web 0.0.0-stage → 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,50 @@
1
+ MonkFeed SDK License
2
+
3
+ Copyright (c) 2026 MonkFeed. All rights reserved.
4
+
5
+ 1. Definitions
6
+
7
+ "Software" means this package: its source code, compiled code and documentation.
8
+ "Service" means the MonkFeed feedback, support and announcements service that MonkFeed makes available at monkfeed.com.
9
+ "You" means the person or organisation that uses the Software.
10
+
11
+ 2. Licence grant
12
+
13
+ Subject to these terms, MonkFeed grants You a limited, non-exclusive, non-transferable, non-sublicensable and revocable licence to install and use the unmodified Software, only to connect Your own websites and applications to the Service, and only while You are entitled to use the Service.
14
+
15
+ You may include the unmodified Software, as produced by Your package manager and build tools, in Your own applications and distribute those applications to Your end users, for the sole purpose of running the Service inside them.
16
+
17
+ 3. Restrictions
18
+
19
+ Without MonkFeed's prior written permission, You must not:
20
+
21
+ (a) copy, modify, adapt, translate or create derivative works of the Software, except for the copies Your package manager and build tools make when installing and bundling it;
22
+ (b) distribute, publish, sell, rent, lease or sublicense the Software, or make it available to anyone else, except as allowed in section 2;
23
+ (c) use the Software with any service other than the Service, or use it to build, train or support a product or service that competes with the Service;
24
+ (d) remove or change any copyright, licence or ownership notice in the Software;
25
+ (e) reverse engineer, decompile or disassemble the Software, except to the extent the law allows despite this restriction;
26
+ (f) bypass or interfere with any account, access control or usage limit of the Service.
27
+
28
+ 4. Ownership
29
+
30
+ MonkFeed and its licensors own the Software and all rights in it. This licence gives You no rights other than those stated in it. No other right is granted by implication.
31
+
32
+ 5. The Service
33
+
34
+ This licence covers the Software only. It does not give You access to the Service. Your use of the Service is governed by Your separate agreement with MonkFeed.
35
+
36
+ 6. Termination
37
+
38
+ This licence ends automatically if You breach it, or when Your right to use the Service ends. MonkFeed may also end it by written notice. When it ends, You must stop using the Software and delete all copies of it.
39
+
40
+ 7. No warranty
41
+
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
43
+
44
+ 8. Limitation of liability
45
+
46
+ TO THE MAXIMUM EXTENT THE LAW ALLOWS, MONKFEED IS NOT LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES, OR FOR LOST PROFITS OR DATA, ARISING FROM THE USE OF OR INABILITY TO USE THE SOFTWARE.
47
+
48
+ 9. Permission
49
+
50
+ To ask for permission to do anything this licence does not allow, contact MonkFeed through https://www.monkfeed.com/contact.
package/README.md CHANGED
@@ -1,3 +1,68 @@
1
- # Temporary Holding Version
1
+ # @monkfeed-sdk/web
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Load the MonkFeed widget on any website and control it from code.
4
+
5
+ ```
6
+ npm install @monkfeed-sdk/web
7
+ ```
8
+
9
+ ```ts
10
+ import { init } from "@monkfeed-sdk/web";
11
+
12
+ const monkfeed = init({
13
+ projectId: "YOUR_PROJECT_ID",
14
+ user: { id: "42", email: "ada@example.com", name: "Ada" }, // optional
15
+ });
16
+
17
+ monkfeed.open(); // from your own button
18
+ monkfeed.close();
19
+ monkfeed.toggle();
20
+ monkfeed.isOpen();
21
+ ```
22
+
23
+ ## Options
24
+
25
+ | Option | Meaning |
26
+ |---|---|
27
+ | `projectId` | Required. Dashboard > Connect > Setup. |
28
+ | `baseUrl` | Where MonkFeed is served from. Default `https://www.monkfeed.com`. |
29
+ | `user` | `{ id, email, name?, createdAt?, jwt? }`. Leave out for anonymous visitors. With `jwt` (signed by your server) the person is verified; without it the identity is only claimed. |
30
+ | `launcher` | `"hidden"` removes the floating button so you open it from your own. Default `"default"`. |
31
+ | `source`, `appId`, `appVersion` | Labels shown in the dashboard for where feedback came from. |
32
+
33
+ ## Methods
34
+
35
+ | Method | What it does |
36
+ |---|---|
37
+ | `open()`, `close()`, `toggle()`, `isOpen()` | Control the panel. `open()` waits for the widget to finish loading. |
38
+ | `identify(user)` | Call after login (or when the user changes). |
39
+ | `reset()` | Call on logout. |
40
+ | `destroy()` | Remove the widget from the page. It does not log the visitor out. |
41
+ | `ready` | A promise that resolves when the widget can be opened (rejects if the script cannot load). |
42
+
43
+ `init()` is safe to call more than once and on the server (it does nothing there).
44
+
45
+ ## Vue, Angular, Svelte
46
+
47
+ Call `init` once when the app starts and `reset()` on logout.
48
+
49
+ ```ts
50
+ // Vue 3: main.ts
51
+ import { init } from "@monkfeed-sdk/web";
52
+ init({ projectId: "YOUR_PROJECT_ID" });
53
+
54
+ // Angular: app.component.ts
55
+ ngOnInit() { this.monkfeed = init({ projectId: "YOUR_PROJECT_ID" }); }
56
+ ngOnDestroy() { this.monkfeed.destroy(); }
57
+
58
+ // Svelte: +layout.svelte
59
+ onMount(() => { const m = init({ projectId: "YOUR_PROJECT_ID" }); return () => m.destroy(); });
60
+ ```
61
+
62
+ ## Without a build step
63
+
64
+ The package is plain ESM. Or use the documented script tag from the dashboard; this package adds the typed handle on top of it.
65
+
66
+ ## Licence
67
+
68
+ Proprietary. Use is limited to connecting your own apps to the MonkFeed service. See [LICENSE](LICENSE).
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @monkfeed-sdk/web: load the MonkFeed widget on any website and control it from code.
3
+ *
4
+ * It does exactly what the documented embed snippet does (stylesheet, #feedback-widget-root, the 6 KB loader script with
5
+ * data-tenant-id) and adds a typed handle: open, close, identify, reset. Every framework package (React, ...) is a thin
6
+ * wrapper around this one.
7
+ */
8
+ export declare const DEFAULT_BASE_URL = "https://www.monkfeed.com";
9
+ export interface MonkfeedUser {
10
+ /** Your own id for the person. */
11
+ id: string;
12
+ email: string;
13
+ name?: string;
14
+ /** When the account was created (ISO string, Date, or unix seconds/milliseconds). */
15
+ createdAt?: string | number | Date;
16
+ /**
17
+ * A short-lived token signed by YOUR server (see the Connect > Setup guides). When present it proves who the person is,
18
+ * and id/email are then only a fallback. Never put your signing secret in browser code.
19
+ */
20
+ jwt?: string;
21
+ }
22
+ export interface MonkfeedOptions {
23
+ /** The project id from the dashboard (Connect > Setup). */
24
+ projectId: string;
25
+ /** Where MonkFeed is served from. Default https://www.monkfeed.com. No trailing slash needed. */
26
+ baseUrl?: string;
27
+ /** The signed-in person, if any. Leave out for anonymous visitors (feedback and votes still work). */
28
+ user?: MonkfeedUser;
29
+ /** "hidden" removes the floating button so you open the widget from your own button with open(). Default "default". */
30
+ launcher?: "default" | "hidden";
31
+ /** Label for where this runs, shown in the dashboard (for example "web", "shopify"). */
32
+ source?: string;
33
+ appId?: string;
34
+ appVersion?: string;
35
+ }
36
+ export interface MonkfeedClient {
37
+ /** Resolves once the launcher is on the page and the widget can be opened. */
38
+ readonly ready: Promise<void>;
39
+ open(): void;
40
+ close(): void;
41
+ toggle(): void;
42
+ isOpen(): boolean;
43
+ /** Tell MonkFeed who is signed in (call again after login, or with another user). */
44
+ identify(user: MonkfeedUser): void;
45
+ /** Forget the person (call on logout). The visitor goes back to anonymous. */
46
+ reset(): void;
47
+ /** Remove the widget from the page. Does not log the visitor out. */
48
+ destroy(): void;
49
+ }
50
+ /**
51
+ * Loads the widget (once per page). Calling it again with the same project and URL returns the same handle; with
52
+ * different ones it replaces the old widget. Safe to call on the server: it returns an inert handle.
53
+ */
54
+ export declare function init(options: MonkfeedOptions): MonkfeedClient;
55
+ /** The handle from the last init(), if any. */
56
+ export declare function getClient(): MonkfeedClient | undefined;
package/dist/index.js ADDED
@@ -0,0 +1,170 @@
1
+ /**
2
+ * @monkfeed-sdk/web: load the MonkFeed widget on any website and control it from code.
3
+ *
4
+ * It does exactly what the documented embed snippet does (stylesheet, #feedback-widget-root, the 6 KB loader script with
5
+ * data-tenant-id) and adds a typed handle: open, close, identify, reset. Every framework package (React, ...) is a thin
6
+ * wrapper around this one.
7
+ */
8
+ export const DEFAULT_BASE_URL = "https://www.monkfeed.com";
9
+ const ROOT_ID = "feedback-widget-root";
10
+ const STYLE_ID = "monkfeed-sdk-style";
11
+ const SCRIPT_ATTR = "data-monkfeed-sdk";
12
+ let current;
13
+ function noop() {
14
+ return {
15
+ ready: Promise.resolve(),
16
+ open() { },
17
+ close() { },
18
+ toggle() { },
19
+ isOpen: () => false,
20
+ identify() { },
21
+ reset() { },
22
+ destroy() { }
23
+ };
24
+ }
25
+ function toSettings(user) {
26
+ if (user.jwt)
27
+ return { user_jwt: user.jwt, user_id: user.id, email: user.email, ...(user.name ? { name: user.name } : {}) };
28
+ const created = user.createdAt instanceof Date ? user.createdAt.toISOString() : user.createdAt;
29
+ return {
30
+ user_id: user.id,
31
+ email: user.email,
32
+ ...(user.name ? { name: user.name } : {}),
33
+ ...(created !== undefined ? { created_at: created } : {})
34
+ };
35
+ }
36
+ function launcherEl() {
37
+ return document.querySelector(`#${ROOT_ID} .fw-launcher`) ?? document.querySelector(`#${ROOT_ID} button`);
38
+ }
39
+ const panelOpen = () => document.querySelector(".fw-panel") !== null;
40
+ function normalize(baseUrl) {
41
+ return (baseUrl?.trim() || DEFAULT_BASE_URL).replace(/\/+$/, "");
42
+ }
43
+ /**
44
+ * Loads the widget (once per page). Calling it again with the same project and URL returns the same handle; with
45
+ * different ones it replaces the old widget. Safe to call on the server: it returns an inert handle.
46
+ */
47
+ export function init(options) {
48
+ if (typeof window === "undefined" || typeof document === "undefined")
49
+ return noop();
50
+ if (!options.projectId?.trim())
51
+ throw new Error("[monkfeed] projectId is required.");
52
+ const baseUrl = normalize(options.baseUrl);
53
+ const key = `${baseUrl}|${options.projectId}|${options.launcher ?? "default"}`;
54
+ if (current?.key === key) {
55
+ if (options.user)
56
+ current.client.identify(options.user);
57
+ return current.client;
58
+ }
59
+ current?.client.destroy();
60
+ const win = window;
61
+ const added = [];
62
+ const append = (parent, node) => {
63
+ parent.appendChild(node);
64
+ added.push(node);
65
+ };
66
+ // Commands sent before the loader finishes are queued by this stub and replayed by the loader.
67
+ if (!win.Monkfeed) {
68
+ const stub = ((...args) => {
69
+ (stub.q || (stub.q = [])).push(args);
70
+ });
71
+ stub.q = [];
72
+ win.Monkfeed = stub;
73
+ }
74
+ if (options.launcher === "hidden") {
75
+ const style = document.createElement("style");
76
+ style.id = STYLE_ID;
77
+ style.textContent = `#${ROOT_ID} .fw-launcher{display:none!important}`;
78
+ append(document.head, style);
79
+ }
80
+ const link = document.createElement("link");
81
+ link.rel = "stylesheet";
82
+ link.href = `${baseUrl}/widget.css`;
83
+ append(document.head, link);
84
+ const root = document.createElement("div");
85
+ root.id = ROOT_ID;
86
+ append(document.body, root);
87
+ let booted = false;
88
+ const send = (user) => {
89
+ win.Monkfeed?.(booted ? "update" : "boot", toSettings(user));
90
+ booted = true;
91
+ };
92
+ if (options.user)
93
+ send(options.user);
94
+ const script = document.createElement("script");
95
+ script.src = `${baseUrl}/feedback-widget.js`;
96
+ script.async = true;
97
+ script.setAttribute("data-tenant-id", options.projectId);
98
+ script.setAttribute("data-api-base-url", `${baseUrl}/api`);
99
+ script.setAttribute(SCRIPT_ATTR, "true");
100
+ if (options.source)
101
+ script.setAttribute("data-source", options.source);
102
+ if (options.appId)
103
+ script.setAttribute("data-app-id", options.appId);
104
+ if (options.appVersion)
105
+ script.setAttribute("data-app-version", options.appVersion);
106
+ append(document.body, script);
107
+ let observer;
108
+ let destroyed = false;
109
+ const ready = new Promise((resolve, reject) => {
110
+ if (launcherEl())
111
+ return resolve();
112
+ observer = new MutationObserver(() => {
113
+ if (launcherEl()) {
114
+ observer?.disconnect();
115
+ resolve();
116
+ }
117
+ });
118
+ observer.observe(root, { childList: true, subtree: true });
119
+ script.addEventListener("error", () => {
120
+ observer?.disconnect();
121
+ reject(new Error(`[monkfeed] could not load ${script.src}`));
122
+ });
123
+ });
124
+ ready.catch((error) => console.warn(String(error))); // reported once here so it never becomes an unhandled rejection
125
+ const client = {
126
+ ready,
127
+ open() {
128
+ if (destroyed)
129
+ return;
130
+ void ready.then(() => {
131
+ if (!panelOpen())
132
+ launcherEl()?.click();
133
+ }, () => { });
134
+ },
135
+ close() {
136
+ if (destroyed || !panelOpen())
137
+ return;
138
+ launcherEl()?.click();
139
+ },
140
+ toggle() {
141
+ if (panelOpen())
142
+ this.close();
143
+ else
144
+ this.open();
145
+ },
146
+ isOpen: panelOpen,
147
+ identify: send,
148
+ reset() {
149
+ booted = false;
150
+ win.Monkfeed?.("reset");
151
+ },
152
+ destroy() {
153
+ if (destroyed)
154
+ return;
155
+ destroyed = true;
156
+ observer?.disconnect();
157
+ for (const node of added)
158
+ node.parentNode?.removeChild(node);
159
+ document.querySelectorAll(".fw-panel").forEach((n) => n.parentNode?.removeChild(n));
160
+ if (current?.client === client)
161
+ current = undefined;
162
+ }
163
+ };
164
+ current = { key, client };
165
+ return client;
166
+ }
167
+ /** The handle from the last init(), if any. */
168
+ export function getClient() {
169
+ return current?.client;
170
+ }
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@monkfeed-sdk/web",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Load the MonkFeed widget on any website and open, close and identify from code.",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc -p tsconfig.build.json",
24
+ "typecheck": "tsc -p tsconfig.json --noEmit",
25
+ "test": "vitest run",
26
+ "prepublishOnly": "npm run typecheck && npm test && npm run build"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^22.10.0",
30
+ "jsdom": "^26.1.0",
31
+ "typescript": "^5.6.0",
32
+ "vitest": "^3.2.4"
33
+ },
34
+ "homepage": "https://www.monkfeed.com",
35
+ "keywords": [
36
+ "monkfeed",
37
+ "feedback",
38
+ "widget",
39
+ "javascript"
40
+ ],
41
+ "publishConfig": {
42
+ "access": "public"
43
+ }
44
+ }