@monkfeed-sdk/react 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 +50 -0
- package/README.md +37 -2
- package/dist/index.d.ts +34 -0
- package/dist/index.js +90 -0
- package/package.json +53 -4
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,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @monkfeed-sdk/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The MonkFeed widget for React and Next.js. A thin wrapper over [`@monkfeed-sdk/web`](../web).
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @monkfeed-sdk/react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { MonkfeedProvider, MonkfeedButton, useMonkfeed } from "@monkfeed-sdk/react";
|
|
11
|
+
|
|
12
|
+
export function Root({ user, children }) {
|
|
13
|
+
return (
|
|
14
|
+
<MonkfeedProvider
|
|
15
|
+
projectId="YOUR_PROJECT_ID"
|
|
16
|
+
user={user ? { id: user.id, email: user.email, name: user.name } : undefined}
|
|
17
|
+
>
|
|
18
|
+
{children}
|
|
19
|
+
</MonkfeedProvider>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function HelpMenu() {
|
|
24
|
+
const { open, isOpen } = useMonkfeed();
|
|
25
|
+
return <button onClick={open}>{isOpen ? "Close feedback" : "Feedback"}</button>;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- **Login and logout** follow the `user` prop: it identifies when a user appears and resets when it goes away. The widget is not reloaded.
|
|
30
|
+
- **Your own button:** add `launcher="hidden"` to the provider and use `<MonkfeedButton />` or `useMonkfeed().open()`.
|
|
31
|
+
- **Next.js App Router:** the package is a client component; put the provider in a client layout. **Pages Router:** put it in `_app`.
|
|
32
|
+
- It takes the same props as `init()` in `@monkfeed-sdk/web` (`baseUrl`, `launcher`, `source`, `appId`, `appVersion`, `user`, and `user.jwt` for a verified identity).
|
|
33
|
+
|
|
34
|
+
`useMonkfeed()` returns `{ ready, isOpen, open, close, toggle, identify, reset }`. Outside a provider every call does nothing.
|
|
35
|
+
|
|
36
|
+
## Licence
|
|
37
|
+
|
|
38
|
+
Proprietary. Use is limited to connecting your own apps to the MonkFeed service. See [LICENSE](LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import { type MonkfeedOptions, type MonkfeedUser } from "@monkfeed-sdk/web";
|
|
3
|
+
export type { MonkfeedClient, MonkfeedOptions, MonkfeedUser } from "@monkfeed-sdk/web";
|
|
4
|
+
export interface MonkfeedProviderProps extends MonkfeedOptions {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export interface MonkfeedApi {
|
|
8
|
+
/** True once the widget is loaded and can be opened. */
|
|
9
|
+
ready: boolean;
|
|
10
|
+
/** True while the panel is open. */
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
open(): void;
|
|
13
|
+
close(): void;
|
|
14
|
+
toggle(): void;
|
|
15
|
+
identify(user: MonkfeedUser): void;
|
|
16
|
+
/** Call on logout. */
|
|
17
|
+
reset(): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Puts the MonkFeed widget on the page and gives the components below it open/close/identify.
|
|
21
|
+
* Works with Next.js (App Router: it is a client component; Pages Router: put it in _app).
|
|
22
|
+
*
|
|
23
|
+
* <MonkfeedProvider projectId="..." user={user ? { id: user.id, email: user.email, name: user.name } : undefined}>
|
|
24
|
+
* <App />
|
|
25
|
+
* </MonkfeedProvider>
|
|
26
|
+
*/
|
|
27
|
+
export declare function MonkfeedProvider({ children, user, projectId, baseUrl, launcher, source, appId, appVersion }: MonkfeedProviderProps): import("react").JSX.Element;
|
|
28
|
+
/** Open, close and identify from any component under <MonkfeedProvider>. Outside a provider every call does nothing. */
|
|
29
|
+
export declare function useMonkfeed(): MonkfeedApi;
|
|
30
|
+
/**
|
|
31
|
+
* A ready-made "Feedback" button that opens the widget. Pair it with launcher="hidden" on the provider to replace the
|
|
32
|
+
* floating button, or use it next to it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function MonkfeedButton({ children, onClick, ...rest }: ButtonHTMLAttributes<HTMLButtonElement>): import("react").JSX.Element;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { init } from "@monkfeed-sdk/web";
|
|
5
|
+
const inert = { ready: false, isOpen: false, open() { }, close() { }, toggle() { }, identify() { }, reset() { } };
|
|
6
|
+
const Context = createContext(inert);
|
|
7
|
+
/**
|
|
8
|
+
* Puts the MonkFeed widget on the page and gives the components below it open/close/identify.
|
|
9
|
+
* Works with Next.js (App Router: it is a client component; Pages Router: put it in _app).
|
|
10
|
+
*
|
|
11
|
+
* <MonkfeedProvider projectId="..." user={user ? { id: user.id, email: user.email, name: user.name } : undefined}>
|
|
12
|
+
* <App />
|
|
13
|
+
* </MonkfeedProvider>
|
|
14
|
+
*/
|
|
15
|
+
export function MonkfeedProvider({ children, user, projectId, baseUrl, launcher, source, appId, appVersion }) {
|
|
16
|
+
const clientRef = useRef(undefined);
|
|
17
|
+
const [ready, setReady] = useState(false);
|
|
18
|
+
const [isOpen, setOpen] = useState(false);
|
|
19
|
+
const userRef = useRef(user);
|
|
20
|
+
userRef.current = user;
|
|
21
|
+
const userKey = user ? `${user.id}|${user.email}|${user.name ?? ""}|${user.jwt ?? ""}` : "";
|
|
22
|
+
// What the widget was last told about the user ("" = nobody), so the same person is never sent twice.
|
|
23
|
+
const sentKey = useRef("");
|
|
24
|
+
// Load the widget; reload only when where it comes from changes. The user is handled separately below.
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const client = init({
|
|
27
|
+
projectId,
|
|
28
|
+
...(baseUrl !== undefined ? { baseUrl } : {}),
|
|
29
|
+
...(launcher !== undefined ? { launcher } : {}),
|
|
30
|
+
source: source ?? "react",
|
|
31
|
+
...(appId !== undefined ? { appId } : {}),
|
|
32
|
+
...(appVersion !== undefined ? { appVersion } : {}),
|
|
33
|
+
...(userRef.current ? { user: userRef.current } : {})
|
|
34
|
+
});
|
|
35
|
+
clientRef.current = client;
|
|
36
|
+
sentKey.current = userRef.current ? userKey : "";
|
|
37
|
+
let alive = true;
|
|
38
|
+
client.ready.then(() => alive && setReady(true), () => { });
|
|
39
|
+
// The panel opens and closes inside the widget (its own X, the launcher, Escape), so watch the page for it.
|
|
40
|
+
const watch = () => alive && setOpen(client.isOpen());
|
|
41
|
+
const observer = new MutationObserver(watch);
|
|
42
|
+
observer.observe(document.body, { childList: true });
|
|
43
|
+
return () => {
|
|
44
|
+
alive = false;
|
|
45
|
+
observer.disconnect();
|
|
46
|
+
client.destroy();
|
|
47
|
+
clientRef.current = undefined;
|
|
48
|
+
setReady(false);
|
|
49
|
+
setOpen(false);
|
|
50
|
+
};
|
|
51
|
+
}, [projectId, baseUrl, launcher, source, appId, appVersion]);
|
|
52
|
+
// Follow login and logout.
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const client = clientRef.current;
|
|
55
|
+
if (!client || userKey === sentKey.current)
|
|
56
|
+
return;
|
|
57
|
+
if (user)
|
|
58
|
+
client.identify(user);
|
|
59
|
+
else
|
|
60
|
+
client.reset();
|
|
61
|
+
sentKey.current = userKey;
|
|
62
|
+
// userKey is the stable form of `user`, so it is the only dependency
|
|
63
|
+
}, [userKey]);
|
|
64
|
+
const api = useMemo(() => ({
|
|
65
|
+
ready,
|
|
66
|
+
isOpen,
|
|
67
|
+
open: () => clientRef.current?.open(),
|
|
68
|
+
close: () => clientRef.current?.close(),
|
|
69
|
+
toggle: () => clientRef.current?.toggle(),
|
|
70
|
+
identify: (u) => clientRef.current?.identify(u),
|
|
71
|
+
reset: () => clientRef.current?.reset()
|
|
72
|
+
}), [ready, isOpen]);
|
|
73
|
+
return _jsx(Context.Provider, { value: api, children: children });
|
|
74
|
+
}
|
|
75
|
+
/** Open, close and identify from any component under <MonkfeedProvider>. Outside a provider every call does nothing. */
|
|
76
|
+
export function useMonkfeed() {
|
|
77
|
+
return useContext(Context);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A ready-made "Feedback" button that opens the widget. Pair it with launcher="hidden" on the provider to replace the
|
|
81
|
+
* floating button, or use it next to it.
|
|
82
|
+
*/
|
|
83
|
+
export function MonkfeedButton({ children = "Feedback", onClick, ...rest }) {
|
|
84
|
+
const { toggle } = useMonkfeed();
|
|
85
|
+
return (_jsx("button", { type: "button", ...rest, onClick: (event) => {
|
|
86
|
+
onClick?.(event);
|
|
87
|
+
if (!event.defaultPrevented)
|
|
88
|
+
toggle();
|
|
89
|
+
}, children: children }));
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkfeed-sdk/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MonkFeed widget for React and Next.js: a provider, a hook and a button.",
|
|
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
|
+
"dependencies": {
|
|
29
|
+
"@monkfeed-sdk/web": "^0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=17"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@testing-library/dom": "^10.4.0",
|
|
36
|
+
"@testing-library/react": "^16.3.0",
|
|
37
|
+
"@types/react": "^18.3.0",
|
|
38
|
+
"jsdom": "^26.1.0",
|
|
39
|
+
"react": "^18.3.1",
|
|
40
|
+
"react-dom": "^18.3.1",
|
|
41
|
+
"typescript": "^5.6.0",
|
|
42
|
+
"vitest": "^3.2.4"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://www.monkfeed.com",
|
|
45
|
+
"keywords": [
|
|
46
|
+
"monkfeed",
|
|
47
|
+
"feedback",
|
|
48
|
+
"widget",
|
|
49
|
+
"react",
|
|
50
|
+
"nextjs"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|