@velaro/cli 1.4.231 → 1.4.232

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.
@@ -25,3 +25,29 @@ export function buildMultiTabUpdateFields(current, mode) {
25
25
  languageConfig: JSON.stringify(current.languageConfig ?? {}),
26
26
  };
27
27
  }
28
+
29
+ // Per-chat-window "visitors can email themselves a transcript" (MessengerStyleConfig.EnableEmailTranscriptButton).
30
+ // Global default is ON; an absent key (null) follows it. A transcript requested while a chat is still open is
31
+ // emailed in full once when the chat ends.
32
+ /** Returns true | false | null (follow the global default, on). Throws on anything else. */
33
+ export function normalizeEmailTranscript(raw) {
34
+ if (raw === null || raw === undefined) return null;
35
+ if (typeof raw === 'boolean') return raw;
36
+ const v = String(raw).trim().toLowerCase();
37
+ if (['default', 'follow-default', 'null', ''].includes(v)) return null;
38
+ if (['on', 'true', 'yes', '1'].includes(v)) return true;
39
+ if (['off', 'false', 'no', '0'].includes(v)) return false;
40
+ throw new Error('enableEmailTranscriptButton must be on, off or default (follows the global default, on).');
41
+ }
42
+
43
+ /** Fields of the update form for a chat window with only enableEmailTranscriptButton changed. */
44
+ export function buildEmailTranscriptUpdateFields(current, value) {
45
+ if (!current || typeof current !== 'object') throw new Error('chat window not found');
46
+ const styleConfig = { ...(current.styleConfig ?? {}) };
47
+ if (value === null) delete styleConfig.enableEmailTranscriptButton; else styleConfig.enableEmailTranscriptButton = value;
48
+ return {
49
+ name: current.name ?? '',
50
+ styleConfig: JSON.stringify(styleConfig),
51
+ languageConfig: JSON.stringify(current.languageConfig ?? {}),
52
+ };
53
+ }
@@ -1,6 +1,21 @@
1
1
  import { test } from 'node:test';
2
2
  import assert from 'node:assert/strict';
3
- import { normalizeMultiTabMode, buildMultiTabUpdateFields } from './chat-window-style.js';
3
+ import { normalizeMultiTabMode, buildMultiTabUpdateFields, normalizeEmailTranscript, buildEmailTranscriptUpdateFields } from './chat-window-style.js';
4
+
5
+ test('email transcript: on/off/default normalize, junk rejected', () => {
6
+ assert.equal(normalizeEmailTranscript('on'), true);
7
+ assert.equal(normalizeEmailTranscript('OFF'), false);
8
+ assert.equal(normalizeEmailTranscript('default'), null);
9
+ assert.equal(normalizeEmailTranscript(false), false);
10
+ assert.throws(() => normalizeEmailTranscript('maybe'), /must be on, off or default/);
11
+ });
12
+
13
+ test('email transcript: update changes only that field; default drops the override', () => {
14
+ const cw = { name: 'Main', styleConfig: { launcherText: 'Help', enableEmailTranscriptButton: true }, languageConfig: {} };
15
+ assert.deepEqual(JSON.parse(buildEmailTranscriptUpdateFields(cw, false).styleConfig), { launcherText: 'Help', enableEmailTranscriptButton: false });
16
+ assert.deepEqual(JSON.parse(buildEmailTranscriptUpdateFields(cw, null).styleConfig), { launcherText: 'Help' });
17
+ assert.equal(cw.styleConfig.enableEmailTranscriptButton, true);
18
+ });
4
19
 
5
20
  test('normalize accepts the two modes and maps default to null', () => {
6
21
  assert.equal(normalizeMultiTabMode('Active-Only'), 'active-only');
@@ -3,7 +3,7 @@
3
3
  // To show different copy on different pages: create one chat window per page type, set its
4
4
  // label/greeting here, then pick it with a Select Chat Window workflow node.
5
5
  import { messagingGet, messagingPut, messagingPostForm } from '../api.js';
6
- import { normalizeMultiTabMode, buildMultiTabUpdateFields } from '../chat-window-style.js';
6
+ import { normalizeMultiTabMode, buildMultiTabUpdateFields, normalizeEmailTranscript, buildEmailTranscriptUpdateFields } from '../chat-window-style.js';
7
7
  import { runCommand } from '../run.js';
8
8
 
9
9
  export const chatWindowCommand = {
@@ -51,6 +51,7 @@ export const chatWindowCommand = {
51
51
  const w = await messagingGet(`/ChatWindow/get/${argv.id}`);
52
52
  console.log(`${w.id} ${w.name ?? '(unnamed)'}`);
53
53
  console.log(` multiTabMode: ${w.styleConfig?.multiTabMode ?? '(follow site/platform default)'}`);
54
+ console.log(` enableEmailTranscriptButton: ${w.styleConfig?.enableEmailTranscriptButton ?? '(follow global default: on)'}`);
54
55
  }),
55
56
  })
56
57
  .command({
@@ -68,6 +69,21 @@ export const chatWindowCommand = {
68
69
  console.log(`Updated chat window ${r.id}. multiTabMode: ${r.styleConfig?.multiTabMode ?? '(follow default)'}`);
69
70
  }),
70
71
  })
71
- .demandCommand(1, 'Specify a subcommand: list, set-copy, get-style, set-multi-tab-mode'),
72
+ .command({
73
+ command: 'set-email-transcript <id> <value>',
74
+ describe: 'Let visitors email themselves a transcript: on | off | default (default = on globally). A mid-chat request is emailed in full when the chat ends.',
75
+ builder: (y) => y
76
+ .positional('id', { type: 'number', describe: 'Chat window ID' })
77
+ .positional('value', { type: 'string', choices: ['on', 'off', 'default'], describe: '"default" follows the global default (on)' }),
78
+ handler: runCommand(async (argv) => {
79
+ const value = normalizeEmailTranscript(argv.value);
80
+ const current = await messagingGet(`/ChatWindow/get/${argv.id}`);
81
+ const form = new FormData();
82
+ for (const [k, v] of Object.entries(buildEmailTranscriptUpdateFields(current, value))) form.append(k, v);
83
+ const r = await messagingPostForm(`/ChatWindow/Update/${argv.id}`, form);
84
+ console.log(`Updated chat window ${r.id}. enableEmailTranscriptButton: ${r.styleConfig?.enableEmailTranscriptButton ?? '(follow default: on)'}`);
85
+ }),
86
+ })
87
+ .demandCommand(1, 'Specify a subcommand: list, set-copy, get-style, set-multi-tab-mode, set-email-transcript'),
72
88
  handler: () => {},
73
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velaro/cli",
3
- "version": "1.4.231",
3
+ "version": "1.4.232",
4
4
  "description": "Velaro Workspace v20 — command-line interface for managing bots, knowledge base ingestion, MCP API keys, search indexes, and ops health.",
5
5
  "type": "module",
6
6
  "bin": {