@startanaicompany/crm 2.4.0 → 2.5.1
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/README.md +130 -49
- package/index.js +210 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,43 +10,56 @@ npm install -g @startanaicompany/crm
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 🏢 Multi-Tenant Architecture
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
This CRM is **multi-tenant**: each company gets its own isolated workspace. All data (leads, contacts, calls, contracts, etc.) is completely separated between workspaces.
|
|
16
|
+
|
|
17
|
+
- One workspace slug per company (e.g. `mygardeningcompany`, `johnscarshop`)
|
|
18
|
+
- All agents of a company share the same workspace — one key per "fleet" or one key per agent, your choice
|
|
19
|
+
- Cross-workspace data access is impossible: a key from workspace `mygardeningcompany` can never see data from `johnscarshop`
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🤖 AI Agent Quick Start (zero-auth)
|
|
24
|
+
|
|
25
|
+
Agents bootstrap themselves in two steps:
|
|
16
26
|
|
|
17
27
|
```bash
|
|
18
|
-
# Step 1:
|
|
19
|
-
saac_crm config set --url https://
|
|
20
|
-
|
|
21
|
-
#
|
|
28
|
+
# Step 1: Point at the CRM deployment
|
|
29
|
+
saac_crm config set --url https://crm.startanaicompany.com
|
|
30
|
+
|
|
31
|
+
# Step 2: Bootstrap your workspace + get an API key (no auth needed, no human required)
|
|
32
|
+
saac_crm workspace init --workspace mygardeningcompany --name my-agent
|
|
33
|
+
# → Returns crm_xxxx API key + saves key + workspace to ~/.saac_crm/config.json
|
|
22
34
|
|
|
23
|
-
# Step
|
|
24
|
-
export SAAC_CRM_API_KEY=crm_xxxxxxxxxxxx
|
|
35
|
+
# Step 3: Start working (workspace is automatically used from config)
|
|
25
36
|
saac_crm leads create --name "Jane Smith" --email "jane@example.com"
|
|
26
37
|
saac_crm leads list
|
|
38
|
+
|
|
39
|
+
# Optional: attribute actions to a named agent for audit trail
|
|
40
|
+
saac_crm leads create --name "Bob Jones" --email "bob@example.com" --from-agent-name "discovery-agent-v2"
|
|
27
41
|
```
|
|
28
42
|
|
|
29
43
|
> **Auth priority**: `--api-key` flag > `SAAC_CRM_API_KEY` env var > config file (`~/.saac_crm/config.json`)
|
|
44
|
+
> **Workspace priority**: `--workspace` flag > `SAAC_CRM_WORKSPACE` env var > config file `workspace` field
|
|
30
45
|
|
|
31
|
-
> ⚠️ **Agents:
|
|
46
|
+
> ⚠️ **Agents: `workspace init` is idempotent** — if the workspace already exists, it just creates a new key for it. Safe to call from any agent on first run.
|
|
32
47
|
|
|
33
48
|
---
|
|
34
49
|
|
|
35
50
|
## 👤 Operator Setup (one-time, human)
|
|
36
51
|
|
|
37
|
-
|
|
52
|
+
For the initial admin setup or to create admin-scope keys:
|
|
38
53
|
|
|
39
54
|
```bash
|
|
40
55
|
# 1. Point at your deployment
|
|
41
|
-
saac_crm config set --url https://
|
|
56
|
+
saac_crm config set --url https://crm.startanaicompany.com
|
|
42
57
|
|
|
43
|
-
# 2.
|
|
44
|
-
saac_crm
|
|
45
|
-
# →
|
|
46
|
-
# → prompts: Deployment admin password:
|
|
47
|
-
# → returns crm_xxx admin key — store securely
|
|
58
|
+
# 2. Create admin-scope key for your workspace (requires deployment admin password)
|
|
59
|
+
saac_crm keys create --name "admin-key" --workspace mycompany --scope admin
|
|
60
|
+
# → Prompts for admin password
|
|
48
61
|
|
|
49
|
-
# 3. Save admin key and create first human user account
|
|
62
|
+
# 3. Save admin key to config and create the first human user account
|
|
50
63
|
saac_crm config set --api-key crm_xxx_admin_key
|
|
51
64
|
saac_crm users create --email admin@example.com --name "Admin" --role admin
|
|
52
65
|
```
|
|
@@ -55,17 +68,27 @@ saac_crm users create --email admin@example.com --name "Admin" --role admin
|
|
|
55
68
|
|
|
56
69
|
## Commands
|
|
57
70
|
|
|
71
|
+
### Workspace
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Bootstrap workspace + create API key in one step (recommended for agent auto-init)
|
|
75
|
+
saac_crm workspace init --workspace mycompany --name "my-agent"
|
|
76
|
+
saac_crm workspace init --workspace mycompany --name "admin-key" --scope admin
|
|
77
|
+
|
|
78
|
+
# Via REST: POST /api/v1/workspaces/register
|
|
79
|
+
# Body: { workspace, key_name, scope?, admin_password? }
|
|
80
|
+
```
|
|
81
|
+
|
|
58
82
|
### API Keys
|
|
59
83
|
|
|
60
84
|
```bash
|
|
61
|
-
# Create agent key —
|
|
62
|
-
saac_crm keys create --name "my-agent"
|
|
85
|
+
# Create agent key — workspace required (auto-creates workspace if it doesn't exist yet)
|
|
86
|
+
saac_crm keys create --name "my-agent" --workspace mycompany
|
|
63
87
|
|
|
64
|
-
# Create admin scope key (
|
|
65
|
-
saac_crm keys create --name "admin-key" --scope admin
|
|
66
|
-
--workspace mycompany --admin-password <deployment-password>
|
|
88
|
+
# Create admin scope key (requires deployment password)
|
|
89
|
+
saac_crm keys create --name "admin-key" --workspace mycompany --scope admin
|
|
67
90
|
|
|
68
|
-
# List all keys
|
|
91
|
+
# List all keys in current workspace
|
|
69
92
|
saac_crm keys list
|
|
70
93
|
|
|
71
94
|
# Show current key info
|
|
@@ -78,11 +101,11 @@ saac_crm keys revoke <id>
|
|
|
78
101
|
### Leads
|
|
79
102
|
|
|
80
103
|
```bash
|
|
81
|
-
# Create a lead
|
|
82
|
-
saac_crm leads create --name "Jane Smith" --email "jane@example.com" --company "Acme"
|
|
104
|
+
# Create a lead (optional: --from-agent-name for audit trail)
|
|
105
|
+
saac_crm leads create --name "Jane Smith" --email "jane@example.com" --company "Acme" --from-agent-name "lead-gen-agent"
|
|
83
106
|
|
|
84
107
|
# List leads (with filters)
|
|
85
|
-
saac_crm leads list --status new --tag vip
|
|
108
|
+
saac_crm leads list --status new --tag vip
|
|
86
109
|
|
|
87
110
|
# Get single lead
|
|
88
111
|
saac_crm leads get <id>
|
|
@@ -95,22 +118,76 @@ saac_crm leads delete <id>
|
|
|
95
118
|
|
|
96
119
|
# Status change history
|
|
97
120
|
saac_crm leads history <id>
|
|
121
|
+
|
|
122
|
+
# Move lead to pipeline stage
|
|
123
|
+
saac_crm leads stage <id> --stage discovery
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Contacts
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
saac_crm contacts create --email contact@example.com --first-name "Jane" --from-agent-name "enrichment-agent"
|
|
130
|
+
saac_crm contacts list
|
|
131
|
+
saac_crm contacts get <id>
|
|
132
|
+
saac_crm contacts update <id> --company "Acme"
|
|
133
|
+
saac_crm contacts delete <id>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Calls
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
saac_crm calls create --lead-id <id> --direction outbound --outcome connected --from-agent-name "call-agent"
|
|
140
|
+
saac_crm calls list [--lead-id <id>]
|
|
141
|
+
saac_crm calls get <id>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Meetings
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
saac_crm meetings create --lead-id <id> --title "Demo call" --from-agent-name "scheduler-agent"
|
|
148
|
+
saac_crm meetings list
|
|
149
|
+
saac_crm meetings get <id>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Emails
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
saac_crm emails create --lead-id <id> --subject "Follow-up" --direction sent --from-agent-name "outreach-agent"
|
|
156
|
+
saac_crm emails list [--lead-id <id>]
|
|
157
|
+
saac_crm emails get <id>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Quotes
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
saac_crm quotes create --lead-id <id> --title "Q-2026-001" --value 5000 --from-agent-name "quote-agent"
|
|
164
|
+
saac_crm quotes list
|
|
165
|
+
saac_crm quotes get <id>
|
|
166
|
+
saac_crm quotes status <id> --status accepted
|
|
167
|
+
saac_crm quotes add-line <id> --description "License" --quantity 1 --unit-price 5000
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Contracts
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
saac_crm contracts create --lead-id <id> --title "Service Agreement" --from-agent-name "contract-agent"
|
|
174
|
+
saac_crm contracts list
|
|
175
|
+
saac_crm contracts get <id>
|
|
176
|
+
saac_crm contracts status <id> --status sent
|
|
177
|
+
saac_crm contracts signatories <id>
|
|
178
|
+
saac_crm contracts add-signatory <id> --contact-id <cid> --party customer --role signer
|
|
179
|
+
saac_crm contracts sign <id> --contact-id <cid>
|
|
180
|
+
saac_crm contracts decline-signature <id> --contact-id <cid>
|
|
181
|
+
saac_crm contracts remind-signatory <id> --contact-id <cid>
|
|
182
|
+
saac_crm contracts remind-all-pending <id>
|
|
98
183
|
```
|
|
99
184
|
|
|
100
185
|
### Users (requires admin scope key)
|
|
101
186
|
|
|
102
187
|
```bash
|
|
103
|
-
# Create a human user account (both commands are equivalent)
|
|
104
188
|
saac_crm users create --email admin@example.com --name "Admin User" --role admin
|
|
105
|
-
saac_crm users register --email admin@example.com --name "Admin User" --role admin
|
|
106
|
-
|
|
107
|
-
# List users
|
|
108
189
|
saac_crm users list
|
|
109
|
-
|
|
110
|
-
# Update user
|
|
111
190
|
saac_crm users update <id> --role viewer
|
|
112
|
-
|
|
113
|
-
# Deactivate user
|
|
114
191
|
saac_crm users deactivate <id>
|
|
115
192
|
```
|
|
116
193
|
|
|
@@ -119,23 +196,16 @@ saac_crm users deactivate <id>
|
|
|
119
196
|
```bash
|
|
120
197
|
# Log in as admin/viewer — saves JWT to config for dashboard access
|
|
121
198
|
saac_crm login --workspace mycompany --email admin@example.com
|
|
122
|
-
# →
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### Workspace Registration (operator only)
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
# First-time setup — registers workspace slug + creates admin key
|
|
129
|
-
# Prompts for --workspace and --admin-password if not provided
|
|
130
|
-
saac_crm register --name "main-admin-key"
|
|
131
|
-
saac_crm register --name "main-admin-key" --workspace mycompany --admin-password <pw>
|
|
199
|
+
# → Prompts for password, saves JWT to ~/.saac_crm/config.json
|
|
132
200
|
```
|
|
133
201
|
|
|
134
202
|
### Configuration
|
|
135
203
|
|
|
136
204
|
```bash
|
|
137
|
-
saac_crm config set --url https://
|
|
205
|
+
saac_crm config set --url https://crm.startanaicompany.com
|
|
138
206
|
saac_crm config set --api-key crm_xxxxxxxxxxxx
|
|
207
|
+
saac_crm config set --workspace mycompany
|
|
208
|
+
saac_crm config set --agent-name "my-agent-v2" # default --from-agent-name for all commands
|
|
139
209
|
saac_crm config get
|
|
140
210
|
```
|
|
141
211
|
|
|
@@ -146,10 +216,21 @@ saac_crm config get
|
|
|
146
216
|
--url <url> Override API base URL for this command
|
|
147
217
|
```
|
|
148
218
|
|
|
219
|
+
## `--from-agent-name` Attribution
|
|
220
|
+
|
|
221
|
+
Pass `--from-agent-name <name>` (or set `SAAC_CRM_AGENT_NAME` env / `config.defaultAgentName`) on any create command to attribute the action to a named agent. This is for **audit trail only** — it does NOT affect authentication or authorization. The same workspace key is shared across all agents of that workspace.
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
export SAAC_CRM_AGENT_NAME=discovery-agent-v2
|
|
225
|
+
saac_crm leads create --name "Alice" --email "alice@example.com"
|
|
226
|
+
# → lead.from_agent_name = "discovery-agent-v2"
|
|
227
|
+
```
|
|
228
|
+
|
|
149
229
|
## Architecture
|
|
150
230
|
|
|
151
|
-
This is a **
|
|
231
|
+
This is a **multi-tenant** system: multiple workspace slugs per deployment, each fully isolated.
|
|
152
232
|
|
|
153
|
-
- **Agents** →
|
|
154
|
-
- **Operators** → `
|
|
155
|
-
- **Humans** → `login` → web dashboard
|
|
233
|
+
- **Agents** → `workspace init` once → `leads create` → manage leads with workspace isolation
|
|
234
|
+
- **Operators** → `keys create --scope admin` → `users create` → human accounts
|
|
235
|
+
- **Humans** → `login` → web dashboard (only shows their workspace's data)
|
|
236
|
+
- **Audit** → `--from-agent-name` for per-agent attribution within a workspace
|
package/index.js
CHANGED
|
@@ -43,7 +43,21 @@ function resolveApiUrl(cliUrl) {
|
|
|
43
43
|
return cfg.apiUrl || null;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function
|
|
46
|
+
function resolveWorkspace(cliWorkspace) {
|
|
47
|
+
if (cliWorkspace) return cliWorkspace;
|
|
48
|
+
if (process.env.SAAC_CRM_WORKSPACE) return process.env.SAAC_CRM_WORKSPACE;
|
|
49
|
+
const cfg = loadConfig();
|
|
50
|
+
return cfg.workspace || null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function resolveAgentName(cliAgentName) {
|
|
54
|
+
if (cliAgentName) return cliAgentName;
|
|
55
|
+
if (process.env.SAAC_CRM_AGENT_NAME) return process.env.SAAC_CRM_AGENT_NAME;
|
|
56
|
+
const cfg = loadConfig();
|
|
57
|
+
return cfg.defaultAgentName || null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getClient(options = {}, agentName = null) {
|
|
47
61
|
const apiKey = resolveApiKey(options.apiKey);
|
|
48
62
|
const apiUrl = resolveApiUrl(options.url);
|
|
49
63
|
|
|
@@ -56,12 +70,15 @@ function getClient(options = {}) {
|
|
|
56
70
|
process.exit(1);
|
|
57
71
|
}
|
|
58
72
|
|
|
73
|
+
const headers = {
|
|
74
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
75
|
+
'Content-Type': 'application/json'
|
|
76
|
+
};
|
|
77
|
+
if (agentName) headers['X-Agent-Name'] = agentName;
|
|
78
|
+
|
|
59
79
|
return axios.create({
|
|
60
80
|
baseURL: `${apiUrl.replace(/\/$/, '')}/api/v1`,
|
|
61
|
-
headers
|
|
62
|
-
'Authorization': `Bearer ${apiKey}`,
|
|
63
|
-
'Content-Type': 'application/json'
|
|
64
|
-
}
|
|
81
|
+
headers
|
|
65
82
|
});
|
|
66
83
|
}
|
|
67
84
|
|
|
@@ -116,6 +133,8 @@ configCmd
|
|
|
116
133
|
.description('Set configuration values')
|
|
117
134
|
.option('--url <url>', 'CRM API base URL (e.g. https://yourapp.example.com)')
|
|
118
135
|
.option('--api-key <key>', 'Default API key to use')
|
|
136
|
+
.option('--workspace <slug>', 'Default workspace slug')
|
|
137
|
+
.option('--agent-name <name>', 'Default agent name for attribution (stored as defaultAgentName)')
|
|
119
138
|
.action((opts) => {
|
|
120
139
|
// NOTE: commander.js may consume --url and --api-key at the parent program level
|
|
121
140
|
// if they share the same option names. Always fall back to program.opts().
|
|
@@ -125,6 +144,8 @@ configCmd
|
|
|
125
144
|
const apiKeyValue = opts.apiKey || globalOpts.apiKey;
|
|
126
145
|
if (urlValue) cfg.apiUrl = urlValue;
|
|
127
146
|
if (apiKeyValue) cfg.apiKey = apiKeyValue;
|
|
147
|
+
if (opts.workspace) cfg.workspace = opts.workspace;
|
|
148
|
+
if (opts.agentName) cfg.defaultAgentName = opts.agentName;
|
|
128
149
|
saveConfig(cfg);
|
|
129
150
|
console.log('Configuration saved to', CONFIG_FILE);
|
|
130
151
|
printJSON(cfg);
|
|
@@ -151,7 +172,7 @@ keysCmd
|
|
|
151
172
|
.description('Create a new API key')
|
|
152
173
|
.requiredOption('--name <name>', 'Name/label for the key')
|
|
153
174
|
.option('--scope <scope>', 'Key scope: agent (default) or admin', 'agent')
|
|
154
|
-
.option('--workspace <slug>', 'Workspace slug (
|
|
175
|
+
.option('--workspace <slug>', 'Workspace slug (falls back to config workspace)')
|
|
155
176
|
.option('--admin-password <password>', 'Admin password (required for scope=admin)')
|
|
156
177
|
.action(async (opts) => {
|
|
157
178
|
const globalOpts = program.opts();
|
|
@@ -161,15 +182,15 @@ keysCmd
|
|
|
161
182
|
process.exit(1);
|
|
162
183
|
}
|
|
163
184
|
|
|
164
|
-
const
|
|
185
|
+
const workspace = resolveWorkspace(opts.workspace);
|
|
186
|
+
if (!workspace) {
|
|
187
|
+
console.error('Error: --workspace <slug> is required (or set in config via: saac_crm config set --workspace <slug>)');
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const body = { name: opts.name, scope: opts.scope, workspace };
|
|
165
192
|
|
|
166
193
|
if (opts.scope === 'admin') {
|
|
167
|
-
if (!opts.workspace) {
|
|
168
|
-
console.error('Error: --workspace <slug> is required for scope=admin');
|
|
169
|
-
process.exit(1);
|
|
170
|
-
}
|
|
171
|
-
body.workspace = opts.workspace;
|
|
172
|
-
|
|
173
194
|
let adminPw = opts.adminPassword;
|
|
174
195
|
if (!adminPw) {
|
|
175
196
|
adminPw = await promptSecret('Admin password: ');
|
|
@@ -242,6 +263,81 @@ program
|
|
|
242
263
|
}
|
|
243
264
|
});
|
|
244
265
|
|
|
266
|
+
// ============================================================
|
|
267
|
+
// WORKSPACE COMMANDS
|
|
268
|
+
// ============================================================
|
|
269
|
+
|
|
270
|
+
const workspaceCmd = program.command('workspace').description('Manage CRM workspaces');
|
|
271
|
+
|
|
272
|
+
workspaceCmd
|
|
273
|
+
.command('init')
|
|
274
|
+
.description('Bootstrap a new workspace: register slug + create API key, save to config')
|
|
275
|
+
.requiredOption('--workspace <slug>', 'Workspace slug (3-50 chars, a-z0-9/dash/underscore)')
|
|
276
|
+
.requiredOption('--name <keyname>', 'Name/label for the initial API key')
|
|
277
|
+
.option('--scope <scope>', 'Key scope: agent (default) or admin', 'agent')
|
|
278
|
+
.option('--admin-password <password>', 'Admin password (required for scope=admin; will prompt if not provided)')
|
|
279
|
+
.option('--owner-email <email>', 'Owner email — creates a human login account for /workspaces/login')
|
|
280
|
+
.option('--owner-password <password>', 'Owner password (min 8 chars) — required if --owner-email is provided')
|
|
281
|
+
.option('--owner-name <name>', 'Owner display name (default: Owner)')
|
|
282
|
+
.option('--save-key', 'Save the returned key to CLI config (default: true)', true)
|
|
283
|
+
.action(async (opts) => {
|
|
284
|
+
const globalOpts = program.opts();
|
|
285
|
+
const apiUrl = resolveApiUrl(globalOpts.url);
|
|
286
|
+
if (!apiUrl) {
|
|
287
|
+
console.error('Error: API URL not configured. Run: saac_crm config set --url <api-url>');
|
|
288
|
+
process.exit(1);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const body = {
|
|
292
|
+
workspace: opts.workspace.trim().toLowerCase(),
|
|
293
|
+
key_name: opts.name,
|
|
294
|
+
scope: opts.scope
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
if (opts.scope === 'admin') {
|
|
298
|
+
let adminPw = opts.adminPassword;
|
|
299
|
+
if (!adminPw) {
|
|
300
|
+
adminPw = await promptSecret('Admin password: ');
|
|
301
|
+
}
|
|
302
|
+
body.admin_password = adminPw;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// BUG-S9-B fix: pass owner credentials so /workspaces/login works immediately
|
|
306
|
+
if (opts.ownerEmail) {
|
|
307
|
+
if (!opts.ownerPassword) {
|
|
308
|
+
console.error('Error: --owner-password is required when --owner-email is provided');
|
|
309
|
+
process.exit(1);
|
|
310
|
+
}
|
|
311
|
+
body.owner_email = opts.ownerEmail.trim().toLowerCase();
|
|
312
|
+
body.owner_password = opts.ownerPassword;
|
|
313
|
+
if (opts.ownerName) body.owner_name = opts.ownerName.trim();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
const res = await axios.post(
|
|
318
|
+
`${apiUrl.replace(/\/$/, '')}/api/v1/workspaces/register`,
|
|
319
|
+
body,
|
|
320
|
+
{ headers: { 'Content-Type': 'application/json' } }
|
|
321
|
+
);
|
|
322
|
+
const data = res.data.data;
|
|
323
|
+
console.log(`Workspace '${data.workspace}' initialized. API key created.`);
|
|
324
|
+
console.log('Store the key — it will not be shown again.');
|
|
325
|
+
if (data.owner_user) {
|
|
326
|
+
console.log(`Owner user created: ${data.owner_user.email} — use POST /api/v1/workspaces/login to get a JWT.`);
|
|
327
|
+
}
|
|
328
|
+
printJSON(data);
|
|
329
|
+
|
|
330
|
+
// Auto-save to config
|
|
331
|
+
const cfg = loadConfig();
|
|
332
|
+
cfg.apiKey = data.key;
|
|
333
|
+
cfg.workspace = data.workspace;
|
|
334
|
+
saveConfig(cfg);
|
|
335
|
+
console.log(`\nKey and workspace saved to config: ${CONFIG_FILE}`);
|
|
336
|
+
} catch (err) {
|
|
337
|
+
handleError(err);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
245
341
|
keysCmd
|
|
246
342
|
.command('list')
|
|
247
343
|
.description('List all API keys (metadata only)')
|
|
@@ -307,9 +403,11 @@ leadsCmd
|
|
|
307
403
|
.option('--tag <tag>', 'Tag (repeatable)', (v, prev) => prev.concat([v]), [])
|
|
308
404
|
.option('--external-id <externalId>', 'External ID')
|
|
309
405
|
.option('--idempotency-key <key>', 'Idempotency key for deduplication')
|
|
406
|
+
.option('--from-agent-name <name>', 'Agent name for attribution (falls back to config defaultAgentName)')
|
|
310
407
|
.action(async (opts) => {
|
|
311
408
|
const globalOpts = program.opts();
|
|
312
|
-
const
|
|
409
|
+
const agentName = resolveAgentName(opts.fromAgentName);
|
|
410
|
+
const client = getClient(globalOpts, agentName);
|
|
313
411
|
const headers = {};
|
|
314
412
|
if (opts.idempotencyKey) headers['Idempotency-Key'] = opts.idempotencyKey;
|
|
315
413
|
const body = {
|
|
@@ -624,9 +722,11 @@ contactsCmd
|
|
|
624
722
|
.option('--tags <tags>', 'Comma-separated tags')
|
|
625
723
|
.option('--do-not-contact', 'Mark as do not contact')
|
|
626
724
|
.option('--notes <notes>', 'Notes')
|
|
725
|
+
.option('--from-agent-name <name>', 'Agent name for attribution (falls back to config defaultAgentName)')
|
|
627
726
|
.action(async (opts) => {
|
|
628
727
|
const globalOpts = program.opts();
|
|
629
|
-
const
|
|
728
|
+
const agentName = resolveAgentName(opts.fromAgentName);
|
|
729
|
+
const client = getClient(globalOpts, agentName);
|
|
630
730
|
try {
|
|
631
731
|
const body = {
|
|
632
732
|
first_name: opts.firstName,
|
|
@@ -780,9 +880,11 @@ callsCmd
|
|
|
780
880
|
.option('--duration <seconds>', 'Duration in seconds')
|
|
781
881
|
.option('--notes <notes>', 'Call notes')
|
|
782
882
|
.option('--call-time <iso>', 'Call time (ISO8601, defaults to now)')
|
|
883
|
+
.option('--from-agent-name <name>', 'Agent name for attribution (falls back to config defaultAgentName)')
|
|
783
884
|
.action(async (opts) => {
|
|
784
885
|
const globalOpts = program.opts();
|
|
785
|
-
const
|
|
886
|
+
const agentName = resolveAgentName(opts.fromAgentName);
|
|
887
|
+
const client = getClient(globalOpts, agentName);
|
|
786
888
|
try {
|
|
787
889
|
const body = { direction: opts.direction };
|
|
788
890
|
if (opts.leadId) body.lead_id = opts.leadId;
|
|
@@ -948,9 +1050,11 @@ meetingsCmd
|
|
|
948
1050
|
.option('--notes <notes>', 'Meeting notes or agenda')
|
|
949
1051
|
.option('--outcome <outcome>', 'scheduled | completed | cancelled | no_show')
|
|
950
1052
|
.option('--sentiment <sentiment>', 'positive | neutral | negative | unknown')
|
|
1053
|
+
.option('--from-agent-name <name>', 'Agent name for attribution (falls back to config defaultAgentName)')
|
|
951
1054
|
.action(async (opts) => {
|
|
952
1055
|
const globalOpts = program.opts();
|
|
953
|
-
const
|
|
1056
|
+
const agentName = resolveAgentName(opts.fromAgentName);
|
|
1057
|
+
const client = getClient(globalOpts, agentName);
|
|
954
1058
|
try {
|
|
955
1059
|
const body = {
|
|
956
1060
|
title: opts.title,
|
|
@@ -1078,9 +1182,11 @@ emailsCmd
|
|
|
1078
1182
|
.option('--body-summary <summary>', 'Body summary (max 1000 chars)')
|
|
1079
1183
|
.option('--thread-id <id>', 'Thread ID for grouping related emails')
|
|
1080
1184
|
.option('--email-timestamp <iso>', 'When the email was sent/received (ISO8601, defaults to now)')
|
|
1185
|
+
.option('--from-agent-name <name>', 'Agent name for attribution (falls back to config defaultAgentName)')
|
|
1081
1186
|
.action(async (opts) => {
|
|
1082
1187
|
const globalOpts = program.opts();
|
|
1083
|
-
const
|
|
1188
|
+
const agentName = resolveAgentName(opts.fromAgentName);
|
|
1189
|
+
const client = getClient(globalOpts, agentName);
|
|
1084
1190
|
try {
|
|
1085
1191
|
const body = {
|
|
1086
1192
|
direction: opts.direction,
|
|
@@ -1171,9 +1277,11 @@ quotesCmd
|
|
|
1171
1277
|
.option('--currency <code>', 'Currency code (default: USD)')
|
|
1172
1278
|
.option('--validity-date <date>', 'Validity date (YYYY-MM-DD)')
|
|
1173
1279
|
.option('--notes <notes>', 'Notes')
|
|
1280
|
+
.option('--from-agent-name <name>', 'Agent name for attribution (falls back to config defaultAgentName)')
|
|
1174
1281
|
.action(async (opts) => {
|
|
1175
1282
|
const globalOpts = program.opts();
|
|
1176
|
-
const
|
|
1283
|
+
const agentName = resolveAgentName(opts.fromAgentName);
|
|
1284
|
+
const client = getClient(globalOpts, agentName);
|
|
1177
1285
|
try {
|
|
1178
1286
|
|
|
1179
1287
|
const res = await client.post('/quotes', {
|
|
@@ -1185,7 +1293,7 @@ quotesCmd
|
|
|
1185
1293
|
notes: opts.notes
|
|
1186
1294
|
});
|
|
1187
1295
|
printJSON(res.data);
|
|
1188
|
-
|
|
1296
|
+
|
|
1189
1297
|
} catch (err) {
|
|
1190
1298
|
handleError(err);
|
|
1191
1299
|
}
|
|
@@ -1396,9 +1504,11 @@ contractsCmd
|
|
|
1396
1504
|
.option('--end-date <date>', 'End date (YYYY-MM-DD)')
|
|
1397
1505
|
.option('--document-url <url>', 'Document URL reference')
|
|
1398
1506
|
.option('--notes <notes>', 'Notes')
|
|
1507
|
+
.option('--from-agent-name <name>', 'Agent name for attribution (falls back to config defaultAgentName)')
|
|
1399
1508
|
.action(async (opts) => {
|
|
1400
1509
|
const globalOpts = program.opts();
|
|
1401
|
-
const
|
|
1510
|
+
const agentName = resolveAgentName(opts.fromAgentName);
|
|
1511
|
+
const client = getClient(globalOpts, agentName);
|
|
1402
1512
|
try {
|
|
1403
1513
|
|
|
1404
1514
|
const res = await client.post('/contracts', {
|
|
@@ -1414,7 +1524,7 @@ contractsCmd
|
|
|
1414
1524
|
notes: opts.notes
|
|
1415
1525
|
});
|
|
1416
1526
|
printJSON(res.data);
|
|
1417
|
-
|
|
1527
|
+
|
|
1418
1528
|
} catch (err) {
|
|
1419
1529
|
handleError(err);
|
|
1420
1530
|
}
|
|
@@ -2038,4 +2148,82 @@ program
|
|
|
2038
2148
|
}
|
|
2039
2149
|
});
|
|
2040
2150
|
|
|
2151
|
+
// ============================================================
|
|
2152
|
+
// SUPPORT commands — Sprint 10 (saac_crm support bugs|features ...)
|
|
2153
|
+
// ============================================================
|
|
2154
|
+
const supportCmd = program.command('support').description('Submit and manage bug reports and feature requests');
|
|
2155
|
+
|
|
2156
|
+
['bugs', 'features'].forEach((type) => {
|
|
2157
|
+
const typeCmd = supportCmd.command(type).description(`Manage ${type} support tickets`);
|
|
2158
|
+
const singular = type === 'bugs' ? 'bug' : 'feature';
|
|
2159
|
+
|
|
2160
|
+
typeCmd
|
|
2161
|
+
.command('add')
|
|
2162
|
+
.description(`Submit a new ${singular} report`)
|
|
2163
|
+
.requiredOption('--title <title>', `${singular} title (max 200 chars)`)
|
|
2164
|
+
.requiredOption('--description <desc>', 'Full description (max 2000 chars)')
|
|
2165
|
+
.action(async (opts) => {
|
|
2166
|
+
const globalOpts = program.opts();
|
|
2167
|
+
const client = getClient(globalOpts);
|
|
2168
|
+
try {
|
|
2169
|
+
const res = await client.post(`/support/${type}`, {
|
|
2170
|
+
title: opts.title,
|
|
2171
|
+
description: opts.description
|
|
2172
|
+
});
|
|
2173
|
+
console.log(`${singular.charAt(0).toUpperCase() + singular.slice(1)} submitted. ID: ${res.data.data.id}`);
|
|
2174
|
+
printJSON(res.data);
|
|
2175
|
+
} catch (err) {
|
|
2176
|
+
handleError(err);
|
|
2177
|
+
}
|
|
2178
|
+
});
|
|
2179
|
+
|
|
2180
|
+
typeCmd
|
|
2181
|
+
.command('list')
|
|
2182
|
+
.description(`List your workspace's ${type}`)
|
|
2183
|
+
.action(async () => {
|
|
2184
|
+
const globalOpts = program.opts();
|
|
2185
|
+
const client = getClient(globalOpts);
|
|
2186
|
+
try {
|
|
2187
|
+
const res = await client.get(`/support/${type}`);
|
|
2188
|
+
printJSON(res.data);
|
|
2189
|
+
} catch (err) {
|
|
2190
|
+
handleError(err);
|
|
2191
|
+
}
|
|
2192
|
+
});
|
|
2193
|
+
|
|
2194
|
+
typeCmd
|
|
2195
|
+
.command('get')
|
|
2196
|
+
.description(`Get a ${singular} ticket by ID`)
|
|
2197
|
+
.requiredOption('--id <id>', 'Ticket ID')
|
|
2198
|
+
.action(async (opts) => {
|
|
2199
|
+
const globalOpts = program.opts();
|
|
2200
|
+
const client = getClient(globalOpts);
|
|
2201
|
+
try {
|
|
2202
|
+
const res = await client.get(`/support/${type}/${opts.id}`);
|
|
2203
|
+
printJSON(res.data);
|
|
2204
|
+
} catch (err) {
|
|
2205
|
+
handleError(err);
|
|
2206
|
+
}
|
|
2207
|
+
});
|
|
2208
|
+
|
|
2209
|
+
typeCmd
|
|
2210
|
+
.command('comment')
|
|
2211
|
+
.description(`Add a comment to your own ${singular} ticket`)
|
|
2212
|
+
.requiredOption('--id <id>', 'Ticket ID')
|
|
2213
|
+
.requiredOption('--message <msg>', 'Comment message (max 2000 chars)')
|
|
2214
|
+
.action(async (opts) => {
|
|
2215
|
+
const globalOpts = program.opts();
|
|
2216
|
+
const client = getClient(globalOpts);
|
|
2217
|
+
try {
|
|
2218
|
+
const res = await client.post(`/support/${type}/${opts.id}/comments`, {
|
|
2219
|
+
message: opts.message
|
|
2220
|
+
});
|
|
2221
|
+
console.log('Comment added.');
|
|
2222
|
+
printJSON(res.data);
|
|
2223
|
+
} catch (err) {
|
|
2224
|
+
handleError(err);
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2227
|
+
});
|
|
2228
|
+
|
|
2041
2229
|
program.parse(process.argv);
|