@resenty/widget 0.1.0 → 0.1.2

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.
@@ -1,5 +1,5 @@
1
1
  import { i as __toESM, n as require_react, r as __commonJSMin, t as require_react_dom } from "./react-dom-B4CdVWWC.js";
2
- import { A as Subscribable, C as resolveStaleTime, D as timeUntilStale, M as client, O as timeoutManager, S as resolveQueryBoolean, T as shouldThrowError, c as fetchState, d as pendingThenable, f as environmentManager, g as isValidTimeout, j as Client, k as focusManager, m as hashKey, n as object, o as getDefaultState, t as _enum, u as notifyManager, w as shallowEqualObjects, x as replaceData, y as noop$1 } from "./schemas-B2StEWw-.js";
2
+ import { A as Subscribable, C as resolveStaleTime, D as timeUntilStale, M as client, O as timeoutManager, S as resolveQueryBoolean, T as shouldThrowError, c as fetchState, d as pendingThenable, f as environmentManager, g as isValidTimeout, j as Client, k as focusManager, m as hashKey, n as object, o as getDefaultState, t as _enum, u as notifyManager, w as shallowEqualObjects, x as replaceData, y as noop$1 } from "./schemas-wISp5pUG.js";
3
3
  import { i as createContextAndHook, n as useCore, o as useQueryClient, r as assertContextExists, s as require_jsx_runtime } from "./core-Cpyk9a29.js";
4
4
  var QueryObserver = class extends Subscribable {
5
5
  constructor(n, s) {
@@ -1,7 +1,7 @@
1
1
  import { n as __toESM } from "./rolldown-runtime-B_fQOXul.js";
2
- import { A as _enum, C as e$2, D as r$2, E as r$3, O as r$1, S as o$1, T as e$1, _ as e$5, a as useEditorState, b as e$4, c as index_default, d as Markdown, f as MarkdownManager, g as o$3, h as r, i as useEditor, j as object, l as index_default$2, m as e$3, n as EditorContext, o as renderToReactElement, p as index_default$1, r as useCurrentEditor, s as index_default$3, t as EditorContent, u as Placeholder, v as o$2, w as e, x as o, y as t } from "./vendor-CAJw9nfJ.js";
3
- import { _ as useMutation, a as createHotkeyHandler, b as require_jsx_runtime, c as createRouter, d as createRoute, f as useNavigate, h as createMemoryHistory, i as widgetThreadsGetThreadsOptions, l as Outlet, n as widgetMessagesGetMessagesQueryKey, o as formatForDisplay, r as widgetMessagesSendMessageMutation, s as RouterProvider, t as widgetMessagesGetMessagesOptions, u as createRootRoute, v as useQuery, x as require_react } from "./query-common-D_G8O-M_.js";
4
- import { a as Toggle, c as cn, d as useLauncher, f as useFrame, i as Kbd, l as LogoIcon, m as useCore, n as TooltipPopup, o as ToggleGroup, r as TooltipProvider, s as Button, t as Tooltip, u as BaseLayout } from "./ui-common-DfZ7eP4u.js";
2
+ import { A as _enum, C as e$2, D as r$2, E as r$3, O as r$1, S as o$1, T as e$1, _ as e$5, a as useEditorState, b as e$4, c as index_default, d as Markdown, f as MarkdownManager, g as o$3, h as r, i as useEditor, j as object, l as index_default$2, m as e$3, n as EditorContext, o as renderToReactElement, p as index_default$1, r as useCurrentEditor, s as index_default$3, t as EditorContent, u as Placeholder, v as o$2, w as e, x as o, y as t } from "./vendor-B8HTpnXx.js";
3
+ import { _ as useMutation, a as createHotkeyHandler, b as require_jsx_runtime, c as createRouter, d as createRoute, f as useNavigate, h as createMemoryHistory, i as widgetThreadsGetThreadsOptions, l as Outlet, n as widgetMessagesGetMessagesQueryKey, o as formatForDisplay, r as widgetMessagesSendMessageMutation, s as RouterProvider, t as widgetMessagesGetMessagesOptions, u as createRootRoute, v as useQuery, x as require_react } from "./query-common-Cdb6fuPq.js";
4
+ import { a as Toggle, c as cn, d as useLauncher, f as useFrame, i as Kbd, l as LogoIcon, m as useCore, n as TooltipPopup, o as ToggleGroup, r as TooltipProvider, s as Button, t as Tooltip, u as BaseLayout } from "./ui-common-C6BZgnhP.js";
5
5
  var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
6
6
  const ChatPanelContext = (0, import_react.createContext)({
7
7
  isOpen: !1,
@@ -1,7 +1,7 @@
1
1
  import { n as __toESM } from "./rolldown-runtime-B_fQOXul.js";
2
- import { F as merge, M as record, N as string, P as toMerged, j as object } from "./vendor-CAJw9nfJ.js";
3
- import { C as Client, S as QueryClient, b as require_jsx_runtime, g as require_react_dom, w as client, x as require_react, y as QueryClientProvider } from "./query-common-D_G8O-M_.js";
4
- import { p as CoreContext } from "./ui-common-DfZ7eP4u.js";
2
+ import { F as merge, M as record, N as string, P as toMerged, j as object } from "./vendor-B8HTpnXx.js";
3
+ import { C as Client, S as QueryClient, b as require_jsx_runtime, g as require_react_dom, w as client, x as require_react, y as QueryClientProvider } from "./query-common-Cdb6fuPq.js";
4
+ import { p as CoreContext } from "./ui-common-C6BZgnhP.js";
5
5
  var DefaultMessages = Object.freeze({
6
6
  MissingWidgetIdErrorMessage: "Missing widgetId. You can get your key at https://app.resenty.com/widget.",
7
7
  NotInBrowserErrorMessage: "Widget can only be used in a browser for the time being."
@@ -132,7 +132,9 @@ var SESSION_RETRY_ATTEMPTS = 3, SESSION_RETRY_BASE_MS = 500, SESSION_CREATE_PATH
132
132
  if (b.headers.set("x-resenty-widget-id", this.appId), isSessionCreationRequest(b)) return b;
133
133
  let Y = await this.ensureSession();
134
134
  return Y && b.headers.set("x-resenty-widget-client-session-id", Y), b;
135
- }), this.ensureSession(), this.#n = createResentyUI?.(this) ?? null;
135
+ }), this.ensureSession();
136
+ let X = this.resolvedOptions.userJwt;
137
+ this.#e && X && this.applyJwtToSession(X), this.#n = createResentyUI?.(this) ?? null;
136
138
  }
137
139
  async ensureSession(b) {
138
140
  if (this.session && !b) return this.session;
@@ -172,7 +174,15 @@ var SESSION_RETRY_ATTEMPTS = 3, SESSION_RETRY_BASE_MS = 500, SESSION_CREATE_PATH
172
174
  }
173
175
  update(b) {
174
176
  let Y = this.resolvedOptions.userJwt;
175
- this.options = this.buildOptions(b), this.setAccessors(this.options), b.userJwt && b.userJwt !== Y && this.ensureSession(!0);
177
+ this.options = this.buildOptions(b), this.setAccessors(this.options), b.userJwt && b.userJwt !== Y && this.applyJwtToSession(b.userJwt);
178
+ }
179
+ async applyJwtToSession(b) {
180
+ if (await this.ensureSession()) try {
181
+ let Y = await this.client?.widget.sessions.identifySession({ body: { user_jwt: b } });
182
+ if (!Y || Y.error) throw Error(Y?.error?.message ?? "Identify failed");
183
+ } catch (b) {
184
+ console.warn("[Resenty] Failed to identify session", b);
185
+ }
176
186
  }
177
187
  buildOptions(b) {
178
188
  return normalizeOptions(toMerged(this.options, b));
@@ -223,7 +233,7 @@ const noop = (...b) => {}, createDeferredPromise = () => {
223
233
  reject: Y
224
234
  };
225
235
  };
226
- var componentImportPaths = { chat: () => import("./chat-CJ6R7eoG.js") };
236
+ var componentImportPaths = { chat: () => import("./chat-DuwCwr2S.js") };
227
237
  const Components = { chat: (0, import_react.lazy)(() => componentImportPaths.chat().then((b) => ({ default: b.Chat }))) }, preloadComponent = async (b) => componentImportPaths[b]?.();
228
238
  var import_react_dom$1 = /* @__PURE__ */ __toESM(require_react_dom(), 1);
229
239
  const Portal = (b) => {
@@ -239,7 +249,7 @@ const mountComponentRenderer = (b) => {
239
249
  let { preloadHint: Q } = Z || {};
240
250
  if (!X) {
241
251
  let Z = createDeferredPromise();
242
- Q && preloadComponent(Q), X = import("./react-root-BBU2MuNT.js").then(({ createRoot: X }) => (X(Y, {
252
+ Q && preloadComponent(Q), X = import("./react-root-VqqgED2E.js").then(({ createRoot: X }) => (X(Y, {
243
253
  onCaughtError(b, Y) {
244
254
  console.error(b, Y);
245
255
  },
@@ -522,6 +522,16 @@ var HeyApiClient = class {
522
522
  }
523
523
  });
524
524
  }
525
+ identifySession(e) {
526
+ return (e.client ?? this.client).post({
527
+ url: "/widget/sessions/identify",
528
+ ...e,
529
+ headers: {
530
+ "Content-Type": "application/json",
531
+ ...e.headers
532
+ }
533
+ });
534
+ }
525
535
  }, Messages = class extends HeyApiClient {
526
536
  sendMessage(e) {
527
537
  return (e.client ?? this.client).post({
@@ -1,5 +1,5 @@
1
1
  import { n as __toESM } from "./rolldown-runtime-B_fQOXul.js";
2
- import { k as require_client } from "./vendor-CAJw9nfJ.js";
3
- import "./query-common-D_G8O-M_.js";
2
+ import { k as require_client } from "./vendor-B8HTpnXx.js";
3
+ import "./query-common-Cdb6fuPq.js";
4
4
  var createRoot = (/* @__PURE__ */ __toESM(require_client(), 1)).createRoot;
5
5
  export { createRoot };
@@ -521,6 +521,16 @@ var HeyApiClient = class {
521
521
  }
522
522
  });
523
523
  }
524
+ identifySession(u) {
525
+ return (u.client ?? this.client).post({
526
+ url: "/widget/sessions/identify",
527
+ ...u,
528
+ headers: {
529
+ "Content-Type": "application/json",
530
+ ...u.headers
531
+ }
532
+ });
533
+ }
524
534
  }, Messages = class extends HeyApiClient {
525
535
  sendMessage(u) {
526
536
  return (u.client ?? this.client).post({
@@ -11,7 +11,7 @@ const noop = (...e) => {}, createDeferredPromise = () => {
11
11
  reject: y
12
12
  };
13
13
  };
14
- var componentImportPaths = { chat: () => import("./chat-CZS20945.js") };
14
+ var componentImportPaths = { chat: () => import("./chat-DZnScfT1.js") };
15
15
  const Components = { chat: (0, import_react.lazy)(() => componentImportPaths.chat().then((e) => ({ default: e.Chat }))) }, preloadComponent = async (e) => componentImportPaths[e]?.();
16
16
  var import_react_dom$1 = /* @__PURE__ */ __toESM(require_react_dom(), 1);
17
17
  const Portal = (e) => {
@@ -1,5 +1,5 @@
1
1
  import { n as __toESM } from "./rolldown-runtime-B_fQOXul.js";
2
- import { b as require_jsx_runtime, g as require_react_dom, x as require_react } from "./query-common-D_G8O-M_.js";
2
+ import { b as require_jsx_runtime, g as require_react_dom, x as require_react } from "./query-common-Cdb6fuPq.js";
3
3
  var import_react = /* @__PURE__ */ __toESM(require_react());
4
4
  function assertContextExists(e, w) {
5
5
  if (!e) throw typeof w == "string" ? Error(w) : /* @__PURE__ */ Error(`${w.displayName} not found`);
@@ -1,5 +1,5 @@
1
1
  import { n as __toESM, t as __commonJSMin } from "./rolldown-runtime-B_fQOXul.js";
2
- import { b as require_jsx_runtime, g as require_react_dom, m as require_shim, p as require_with_selector, x as require_react } from "./query-common-D_G8O-M_.js";
2
+ import { b as require_jsx_runtime, g as require_react_dom, m as require_shim, p as require_with_selector, x as require_react } from "./query-common-Cdb6fuPq.js";
3
3
  function isPrimitive(n) {
4
4
  return n == null || typeof n != "object" && typeof n != "function";
5
5
  }
package/dist/resenty.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as Subscribable, C as resolveStaleTime, E as skipToken, M as client, _ as matchMutation, a as Mutation, b as partialMatchKey, h as hashQueryKeyByOptions, i as string, j as Client, k as focusManager, l as onlineManager, m as hashKey, n as object, p as functionalUpdate, r as record, s as Query, u as notifyManager, v as matchQuery, y as noop } from "./chunks/schemas-B2StEWw-.js";
1
+ import { A as Subscribable, C as resolveStaleTime, E as skipToken, M as client, _ as matchMutation, a as Mutation, b as partialMatchKey, h as hashQueryKeyByOptions, i as string, j as Client, k as focusManager, l as onlineManager, m as hashKey, n as object, p as functionalUpdate, r as record, s as Query, u as notifyManager, v as matchQuery, y as noop } from "./chunks/schemas-wISp5pUG.js";
2
2
  var DefaultMessages = Object.freeze({
3
3
  MissingWidgetIdErrorMessage: "Missing widgetId. You can get your key at https://app.resenty.com/widget.",
4
4
  NotInBrowserErrorMessage: "Widget can only be used in a browser for the time being."
@@ -545,7 +545,9 @@ var SESSION_RETRY_ATTEMPTS = 3, SESSION_RETRY_BASE_MS = 500, SESSION_CREATE_PATH
545
545
  if (_.headers.set("x-resenty-widget-id", this.appId), isSessionCreationRequest(_)) return _;
546
546
  let K = await this.ensureSession();
547
547
  return K && _.headers.set("x-resenty-widget-client-session-id", K), _;
548
- }), this.ensureSession(), this.#n = createResentyUI?.(this) ?? null;
548
+ }), this.ensureSession();
549
+ let q = this.resolvedOptions.userJwt;
550
+ this.#e && q && this.applyJwtToSession(q), this.#n = createResentyUI?.(this) ?? null;
549
551
  }
550
552
  async ensureSession(_) {
551
553
  if (this.session && !_) return this.session;
@@ -585,7 +587,15 @@ var SESSION_RETRY_ATTEMPTS = 3, SESSION_RETRY_BASE_MS = 500, SESSION_CREATE_PATH
585
587
  }
586
588
  update(_) {
587
589
  let K = this.resolvedOptions.userJwt;
588
- this.options = this.buildOptions(_), this.setAccessors(this.options), _.userJwt && _.userJwt !== K && this.ensureSession(!0);
590
+ this.options = this.buildOptions(_), this.setAccessors(this.options), _.userJwt && _.userJwt !== K && this.applyJwtToSession(_.userJwt);
591
+ }
592
+ async applyJwtToSession(_) {
593
+ if (await this.ensureSession()) try {
594
+ let K = await this.client?.widget.sessions.identifySession({ body: { user_jwt: _ } });
595
+ if (!K || K.error) throw Error(K?.error?.message ?? "Identify failed");
596
+ } catch (_) {
597
+ console.warn("[Resenty] Failed to identify session", _);
598
+ }
589
599
  }
590
600
  buildOptions(_) {
591
601
  return normalizeOptions(toMerged(this.options, _));
@@ -650,7 +660,7 @@ var errorThrower = buildErrorThrower({ packageName: "💬 Resenty" }), loaderWin
650
660
  async function bootstrap() {
651
661
  let _ = loaderWindow.resentyOptions ?? {};
652
662
  _.appId || errorThrower.throwMissingWidgetIdError();
653
- let { ResentyUI: K } = await import("./chunks/ui-f9sPMhJV.js");
663
+ let { ResentyUI: K } = await import("./chunks/ui-DDeDAQlF.js");
654
664
  configureResentyUI((_) => new K(_));
655
665
  let q = new Resenty();
656
666
  q.load(_.appId, _);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resenty/widget",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Resenty chat widget — embedded via <script> tag.",
5
5
  "homepage": "https://resenty.com",
6
6
  "license": "MIT",
@@ -23,71 +23,5 @@
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
- "dependencies": {
27
- "@phosphor-icons/react": "^2.1.10",
28
- "@tailwindcss/typography": "^0.5.19",
29
- "@tailwindcss/vite": "^4.3.0",
30
- "@tanstack/react-form": "^1.32.0",
31
- "@tanstack/react-hotkeys": "^0.10.0",
32
- "@tanstack/react-query": "^5.100.11",
33
- "@tanstack/react-router": "~1.168.8",
34
- "@tiptap/react": "^3.23.5",
35
- "class-variance-authority": "^0.7.1",
36
- "clsx": "^2.1.1",
37
- "es-toolkit": "^1.46.1",
38
- "frimousse": "^0.3.0",
39
- "html2canvas-pro": "^2.0.2",
40
- "lucide-react": "^0.577.0",
41
- "react": "~19.2.4",
42
- "react-aria-components": "^1.17.0",
43
- "react-dom": "~19.2.4",
44
- "tailwindcss": "^4.3.0",
45
- "tailwindcss-react-aria-components": "^2.1.0",
46
- "zod": "^4.3.6"
47
- },
48
- "devDependencies": {
49
- "@hey-api/openapi-ts": "^0.90.9",
50
- "@playwright/test": "^1.58.2",
51
- "@testing-library/jest-dom": "^6.9.1",
52
- "@testing-library/react": "^16.3.2",
53
- "@testing-library/user-event": "^14.6.1",
54
- "@types/node": "^24.10.13",
55
- "@types/react": "^19.2.14",
56
- "@types/react-dom": "^19.2.3",
57
- "@vitejs/plugin-react": "^5.1.4",
58
- "@vitest/browser": "^4.1.6",
59
- "@vitest/browser-playwright": "^4.1.0",
60
- "@vitest/coverage-v8": "^4.1.0",
61
- "jsdom": "^28.1.0",
62
- "knip": "^5.86.0",
63
- "playwright": "^1.58.2",
64
- "tw-animate-css": "^1.4.0",
65
- "typescript": "~5.9.3",
66
- "vite": "npm:rolldown-vite@7.2.2",
67
- "vite-tsconfig-paths": "^5.1.4",
68
- "vitest": "^4.1.0",
69
- "@resenty/editor": "0.0.0",
70
- "@resenty/tsconfig": "0.0.0"
71
- },
72
- "scripts": {
73
- "analyze": "vite-bundle-analyzer -e=rolldown-vite",
74
- "api:generate": "openapi-ts && pnpm fmt",
75
- "build": "pnpm clean && pnpm build:sdk && pnpm build:loader",
76
- "build:sdk": "vite build",
77
- "build:loader": "vite build --config vite.loader.config.ts",
78
- "build:cdn:canary": "RESENTY_CDN_VERSION_DIR=\"canary/$RESENTY_CDN_SHA\" pnpm build:sdk && RESENTY_CDN_VERSION_DIR=\"canary/$RESENTY_CDN_SHA\" pnpm build:loader",
79
- "clean": "rm -rf ./dist ./tmp",
80
- "dev": "vite",
81
- "fmt": "oxfmt",
82
- "fmt:check": "oxfmt --check",
83
- "knip": "knip",
84
- "lint": "oxlint",
85
- "lint:fix": "oxlint --fix",
86
- "test": "vitest",
87
- "test:browser": "vitest run --project browser",
88
- "test:core": "vitest run --project core",
89
- "test:coverage": "vitest run --coverage",
90
- "test:ui": "vitest run --project ui",
91
- "typecheck": "tsc --noEmit"
92
- }
26
+ "scripts": {}
93
27
  }