@menuia/core 1.3.0 → 1.5.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.d.mts CHANGED
@@ -14,6 +14,18 @@ interface MenuIAConfig {
14
14
  visitorPhone?: string;
15
15
  /** Visitor name */
16
16
  visitorName?: string;
17
+ /**
18
+ * Token de sessao do WIDGET PRIVADO, emitido pelo SEU servidor.
19
+ *
20
+ * ⚠️ Nao coloque aqui o segredo `wsec_...`: ele fica no seu backend. O fluxo e:
21
+ * seu servidor faz `POST /widget/<widgetId>/auth` com `Authorization: Bearer wsec_...` e a
22
+ * identidade de quem esta logado; a resposta traz `sessionToken`, e e ESSE valor (curto e
23
+ * descartavel) que vai para o navegador. Vale ~10 min e pode ser reaproveitado dentro disso.
24
+ *
25
+ * ⚠️ Em widget privado, nome/email/telefone vem do token — o que for passado aqui no front e
26
+ * ignorado pelo servidor, de proposito: quem garante a identidade e o seu backend.
27
+ */
28
+ sessionToken?: string;
17
29
  onMessage?: (message: ChatMessage) => void;
18
30
  onStatusChange?: (status: ConnectionStatus) => void;
19
31
  onTicketCreated?: (ticketId: string) => void;
@@ -27,6 +39,8 @@ interface ChatMessage {
27
39
  createdAt: string;
28
40
  mediaUrl?: string;
29
41
  mediaType?: string;
42
+ /** Nome original do arquivo anexado, quando houver. */
43
+ mediaName?: string;
30
44
  toolCalls?: string;
31
45
  toolResults?: string;
32
46
  authorName?: string;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,18 @@ interface MenuIAConfig {
14
14
  visitorPhone?: string;
15
15
  /** Visitor name */
16
16
  visitorName?: string;
17
+ /**
18
+ * Token de sessao do WIDGET PRIVADO, emitido pelo SEU servidor.
19
+ *
20
+ * ⚠️ Nao coloque aqui o segredo `wsec_...`: ele fica no seu backend. O fluxo e:
21
+ * seu servidor faz `POST /widget/<widgetId>/auth` com `Authorization: Bearer wsec_...` e a
22
+ * identidade de quem esta logado; a resposta traz `sessionToken`, e e ESSE valor (curto e
23
+ * descartavel) que vai para o navegador. Vale ~10 min e pode ser reaproveitado dentro disso.
24
+ *
25
+ * ⚠️ Em widget privado, nome/email/telefone vem do token — o que for passado aqui no front e
26
+ * ignorado pelo servidor, de proposito: quem garante a identidade e o seu backend.
27
+ */
28
+ sessionToken?: string;
17
29
  onMessage?: (message: ChatMessage) => void;
18
30
  onStatusChange?: (status: ConnectionStatus) => void;
19
31
  onTicketCreated?: (ticketId: string) => void;
@@ -27,6 +39,8 @@ interface ChatMessage {
27
39
  createdAt: string;
28
40
  mediaUrl?: string;
29
41
  mediaType?: string;
42
+ /** Nome original do arquivo anexado, quando houver. */
43
+ mediaName?: string;
30
44
  toolCalls?: string;
31
45
  toolResults?: string;
32
46
  authorName?: string;
package/dist/index.js CHANGED
@@ -66,7 +66,12 @@ var MenuIAClient = class {
66
66
  try {
67
67
  const response = await fetch(`${this.config.apiUrl}/widget/${this.config.widgetId}/session`, {
68
68
  method: "POST",
69
- headers: { "Content-Type": "application/json" },
69
+ // ⚠️ O token de sessao vai no HEADER, nao no corpo: header e o lugar de credencial e nao
70
+ // acaba em log de acesso nem no Referer. O servidor aceita os dois, com o header na frente.
71
+ headers: {
72
+ "Content-Type": "application/json",
73
+ ...this.config.sessionToken ? { "x-widget-session": this.config.sessionToken } : {}
74
+ },
70
75
  body: JSON.stringify({
71
76
  name: this.config.visitorName || this.config.metadata?.name,
72
77
  email: this.config.visitorEmail || this.config.metadata?.email,
@@ -282,6 +287,9 @@ var MenuIAClient = class {
282
287
  createdAt: m.createdAt,
283
288
  mediaUrl: m.mediaUrl,
284
289
  mediaType: m.mediaType,
290
+ // ⚠️ O endpoint devolve `mediaName` e o mapeamento o descartava: anexo recarregado do
291
+ // historico aparecia sem o nome do arquivo, mesmo com o nome gravado no banco.
292
+ mediaName: m.mediaName,
285
293
  authorName: m.authorName
286
294
  }));
287
295
  if (messages.length) {
@@ -298,9 +306,10 @@ var MenuIAClient = class {
298
306
  startPolling(intervalMs = 1e4) {
299
307
  this.stopPolling();
300
308
  this.pollInterval = setInterval(async () => {
309
+ const jaVistas = this.lastMessageCount;
301
310
  const messages = await this.loadHistory();
302
- if (messages.length > this.lastMessageCount) {
303
- const newMessages = messages.slice(this.lastMessageCount);
311
+ if (messages.length > jaVistas) {
312
+ const newMessages = messages.slice(jaVistas);
304
313
  for (const msg of newMessages) {
305
314
  if (msg.role === "assistant") {
306
315
  this.config.onMessage?.(msg);
package/dist/index.mjs CHANGED
@@ -40,7 +40,12 @@ var MenuIAClient = class {
40
40
  try {
41
41
  const response = await fetch(`${this.config.apiUrl}/widget/${this.config.widgetId}/session`, {
42
42
  method: "POST",
43
- headers: { "Content-Type": "application/json" },
43
+ // ⚠️ O token de sessao vai no HEADER, nao no corpo: header e o lugar de credencial e nao
44
+ // acaba em log de acesso nem no Referer. O servidor aceita os dois, com o header na frente.
45
+ headers: {
46
+ "Content-Type": "application/json",
47
+ ...this.config.sessionToken ? { "x-widget-session": this.config.sessionToken } : {}
48
+ },
44
49
  body: JSON.stringify({
45
50
  name: this.config.visitorName || this.config.metadata?.name,
46
51
  email: this.config.visitorEmail || this.config.metadata?.email,
@@ -256,6 +261,9 @@ var MenuIAClient = class {
256
261
  createdAt: m.createdAt,
257
262
  mediaUrl: m.mediaUrl,
258
263
  mediaType: m.mediaType,
264
+ // ⚠️ O endpoint devolve `mediaName` e o mapeamento o descartava: anexo recarregado do
265
+ // historico aparecia sem o nome do arquivo, mesmo com o nome gravado no banco.
266
+ mediaName: m.mediaName,
259
267
  authorName: m.authorName
260
268
  }));
261
269
  if (messages.length) {
@@ -272,9 +280,10 @@ var MenuIAClient = class {
272
280
  startPolling(intervalMs = 1e4) {
273
281
  this.stopPolling();
274
282
  this.pollInterval = setInterval(async () => {
283
+ const jaVistas = this.lastMessageCount;
275
284
  const messages = await this.loadHistory();
276
- if (messages.length > this.lastMessageCount) {
277
- const newMessages = messages.slice(this.lastMessageCount);
285
+ if (messages.length > jaVistas) {
286
+ const newMessages = messages.slice(jaVistas);
278
287
  for (const msg of newMessages) {
279
288
  if (msg.role === "assistant") {
280
289
  this.config.onMessage?.(msg);
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@menuia/core",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "MenuIA Chat SDK - Core",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
- "files": ["dist"],
8
+ "files": [
9
+ "dist"
10
+ ],
9
11
  "scripts": {
10
12
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
11
13
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch"