@quadient/skillshare 1.11.1 → 1.13.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/README.md +20 -0
- package/dist/agents-detect.js +9 -3
- package/dist/agents-service-path.js +52 -0
- package/dist/agents-service.js +81 -6
- package/dist/agents.js +3 -2
- package/dist/help.js +22 -5
- package/dist/index.js +14 -1
- package/dist/output.js +1 -0
- package/dist/pages-comments.js +143 -0
- package/dist/salesforce.js +181 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -341,6 +341,26 @@ printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN
|
|
|
341
341
|
skillshare pages secrets delete my-app API_TOKEN
|
|
342
342
|
```
|
|
343
343
|
|
|
344
|
+
## Page comments (1.13.0+)
|
|
345
|
+
|
|
346
|
+
Every Page is also served at `/pa/<slug>/` with an **Annotations** button. Signed-in
|
|
347
|
+
users highlight text, place pins or add page notes there; comments are stored in
|
|
348
|
+
SkillShare with their author and time. The owner can show the button on the regular
|
|
349
|
+
`/p/<slug>/` address too. The CLI reads and answers comments:
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
skillshare pages comments enable my-app # also on /p/my-app/ (owner or admin)
|
|
353
|
+
skillshare pages comments list my-app --author mine
|
|
354
|
+
skillshare pages comments list my-app --path docs/ --resolved
|
|
355
|
+
skillshare pages comments add my-app "Please add a changelog section" --path index.html
|
|
356
|
+
skillshare pages comments reply my-app 12 "Fixed in revision 4"
|
|
357
|
+
skillshare pages comments resolve my-app 12
|
|
358
|
+
skillshare pages comments delete my-app 12
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
`--author` accepts `mine` or a user id and keeps threads that person started or
|
|
362
|
+
replied to. Text without an argument, or `-`, is read from stdin.
|
|
363
|
+
|
|
344
364
|
## Local Pages development (1.6.0+)
|
|
345
365
|
|
|
346
366
|
Run a celld application without a SkillShare server, repository checkout, Docker,
|
package/dist/agents-detect.js
CHANGED
|
@@ -15,10 +15,10 @@ export function profilesPath(home = homedir()) {
|
|
|
15
15
|
export async function detectAgents(options = {}) {
|
|
16
16
|
const home = options.home ?? homedir();
|
|
17
17
|
const env = options.env ?? process.env;
|
|
18
|
-
const version = options.version ?? commandVersion;
|
|
19
18
|
const read = options.read ?? readOptional;
|
|
20
19
|
const agents = [];
|
|
21
20
|
const problems = [];
|
|
21
|
+
const version = options.version ?? (command => commandVersion(command, env, problem => problems.push(problem)));
|
|
22
22
|
const claudeVersion = await version('claude');
|
|
23
23
|
if (claudeVersion !== null) {
|
|
24
24
|
const settings = parseJson(await read(join(env.CLAUDE_CONFIG_DIR ?? join(home, '.claude'), 'settings.json')));
|
|
@@ -45,6 +45,8 @@ export async function detectAgents(options = {}) {
|
|
|
45
45
|
for (const profile of profiles)
|
|
46
46
|
if (!agents.some(agent => agent.kind === profile.agent))
|
|
47
47
|
problems.push(`Profile "${profile.name}" uses ${profile.agent}, which is not installed.`);
|
|
48
|
+
if (agents.length === 0)
|
|
49
|
+
problems.push(`Could not run claude --version or codex --version. Check that an agent is installed and runnable on PATH: ${env.PATH ?? env.Path ?? ''}. For a service, check skillshare agents service status and reinstall from a fresh terminal if needed.`);
|
|
48
50
|
return {
|
|
49
51
|
capabilities: { agents, profiles: profiles.map(p => ({ name: p.name, agent: p.agent, model: p.model, reasoning: p.reasoning,
|
|
50
52
|
workdir: p.workdir ? basename(p.workdir) : undefined, ...(p.sandbox ? { sandbox: true } : {}) })) },
|
|
@@ -202,8 +204,12 @@ async function readOptional(path) {
|
|
|
202
204
|
return null;
|
|
203
205
|
}
|
|
204
206
|
}
|
|
205
|
-
function commandVersion(command) {
|
|
207
|
+
function commandVersion(command, env, report) {
|
|
206
208
|
return new Promise(resolvePromise => {
|
|
207
|
-
execFile(command, ['--version'], { timeout: 15_000, windowsHide: true, shell: process.platform === 'win32' }, (error, stdout) =>
|
|
209
|
+
execFile(command, ['--version'], { env, timeout: 15_000, windowsHide: true, shell: process.platform === 'win32' }, (error, stdout) => {
|
|
210
|
+
if (error)
|
|
211
|
+
report(`${command} --version failed (${error.killed ? 'timeout or terminated' : error.code ?? 'unknown error'}). Check the executable and PATH.`);
|
|
212
|
+
resolvePromise(error ? null : stdout.toString());
|
|
213
|
+
});
|
|
208
214
|
});
|
|
209
215
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const readRegistry = (command, args) => new Promise((resolve, reject) => {
|
|
4
|
+
execFile(command, args, { timeout: 10_000, windowsHide: true }, (error, stdout, stderr) => {
|
|
5
|
+
if (error)
|
|
6
|
+
reject(error);
|
|
7
|
+
else
|
|
8
|
+
resolve({ code: 0, stdout, stderr });
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
export function mergeWindowsPath(...paths) {
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
return paths.flatMap(path => path.split(';')).map(part => part.trim()).filter(part => {
|
|
14
|
+
const key = part.replace(/[\\/]+$/, '').toLowerCase();
|
|
15
|
+
if (!part || /(?:^|[\\/])node_modules[\\/]\.bin(?:[\\/]|$)/i.test(part) || seen.has(key))
|
|
16
|
+
return false;
|
|
17
|
+
seen.add(key);
|
|
18
|
+
return true;
|
|
19
|
+
}).join(';');
|
|
20
|
+
}
|
|
21
|
+
/** Refresh before every service detection, including in services installed by older CLIs. */
|
|
22
|
+
export async function refreshServicePath(env = process.env, platform = process.platform, run = readRegistry) {
|
|
23
|
+
if (platform !== 'win32')
|
|
24
|
+
return [];
|
|
25
|
+
const script = `$ErrorActionPreference = 'Stop'
|
|
26
|
+
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
|
27
|
+
foreach ($scope in @('Machine', 'User')) {
|
|
28
|
+
$vars = [Environment]::GetEnvironmentVariables($scope)
|
|
29
|
+
foreach ($key in $vars.Keys) { if ($key -ne 'Path') { [Environment]::SetEnvironmentVariable($key, [Environment]::ExpandEnvironmentVariables($vars[$key]), 'Process') } }
|
|
30
|
+
}
|
|
31
|
+
$machine = [Environment]::GetEnvironmentVariable('Path', 'Machine')
|
|
32
|
+
[Environment]::SetEnvironmentVariable('Path', [Environment]::ExpandEnvironmentVariables($machine), 'Process')
|
|
33
|
+
$user = [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
34
|
+
[Environment]::ExpandEnvironmentVariables($machine + ';' + $user)`;
|
|
35
|
+
const pathKeys = Object.keys(env).filter(key => key.toLowerCase() === 'path');
|
|
36
|
+
const snapshot = pathKeys.map(key => env[key] ?? '').join(';');
|
|
37
|
+
let current = '';
|
|
38
|
+
const warnings = [];
|
|
39
|
+
try {
|
|
40
|
+
const result = await run(join(env.SystemRoot ?? env.SYSTEMROOT ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'), ['-NoProfile', '-NonInteractive', '-Command', script]);
|
|
41
|
+
if (result.code !== 0)
|
|
42
|
+
throw new Error('registry read failed');
|
|
43
|
+
current = result.stdout.trim();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
warnings.push('Could not read current Windows PATH from the registry; using the saved service PATH. Reinstall from a fresh terminal if agents are missing.');
|
|
47
|
+
}
|
|
48
|
+
for (const key of pathKeys)
|
|
49
|
+
delete env[key];
|
|
50
|
+
env.PATH = mergeWindowsPath(current, snapshot);
|
|
51
|
+
return warnings;
|
|
52
|
+
}
|
package/dist/agents-service.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { detectAgents } from './agents-detect.js';
|
|
2
|
+
import { refreshServicePath } from './agents-service-path.js';
|
|
1
3
|
import { existsSync } from 'node:fs';
|
|
2
4
|
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
5
|
import { homedir } from 'node:os';
|
|
@@ -18,6 +20,7 @@ export function defaultServiceEnvironment(appDir) {
|
|
|
18
20
|
export function servicePaths(appDir) {
|
|
19
21
|
return {
|
|
20
22
|
config: join(appDir, 'agents-service.json'),
|
|
23
|
+
detection: join(appDir, 'agents-service-detection.json'),
|
|
21
24
|
launcher: join(appDir, 'agents-service.mjs'),
|
|
22
25
|
log: join(appDir, 'logs', 'agents.log'),
|
|
23
26
|
// What the service manager catches before the listener's own log opens, such as a launcher that cannot start.
|
|
@@ -221,9 +224,40 @@ export async function installService(environment, settings, options = {}) {
|
|
|
221
224
|
}
|
|
222
225
|
return config;
|
|
223
226
|
}
|
|
227
|
+
/** Match the launcher argument, not a substring belonging to another installation. */
|
|
228
|
+
export function windowsStopServiceScript(appDir) {
|
|
229
|
+
const launcher = servicePaths(appDir).launcher.replace(/'/g, "''");
|
|
230
|
+
return `
|
|
231
|
+
$ErrorActionPreference = 'Stop'
|
|
232
|
+
$launcher = '${launcher}'
|
|
233
|
+
$pattern = '^\\s*(?:"[^"\\r\\n]+"|[^\\s"]+)\\s+(?:"' + [regex]::Escape($launcher) + '"|' + [regex]::Escape($launcher) + ')(?:\\s|$)'
|
|
234
|
+
$all = @(Get-CimInstance Win32_Process)
|
|
235
|
+
$tree = [System.Collections.Generic.List[object]]::new()
|
|
236
|
+
foreach ($p in $all) {
|
|
237
|
+
if ($p.Name -ieq 'node.exe' -and $p.CommandLine -match $pattern) { $tree.Add($p) }
|
|
238
|
+
}
|
|
239
|
+
# Snapshot descendants before stopping their parents, which otherwise loses the tree.
|
|
240
|
+
for ($i = 0; $i -lt $tree.Count; $i++) {
|
|
241
|
+
foreach ($p in $all) {
|
|
242
|
+
if ($p.ParentProcessId -eq $tree[$i].ProcessId -and $p.ProcessId -notin $tree.ProcessId) { $tree.Add($p) }
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
# Parent first prevents the supervisor from restarting a listener during teardown.
|
|
246
|
+
foreach ($p in $tree) {
|
|
247
|
+
$live = Get-CimInstance Win32_Process -Filter ("ProcessId = " + $p.ProcessId)
|
|
248
|
+
if ($null -ne $live -and $live.CreationDate -eq $p.CreationDate) {
|
|
249
|
+
Stop-Process -Id $p.ProcessId -Force -ErrorAction Stop
|
|
250
|
+
if (Get-Process -Id $p.ProcessId -ErrorAction SilentlyContinue) {
|
|
251
|
+
Wait-Process -Id $p.ProcessId -Timeout 10 -ErrorAction Stop
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
`;
|
|
256
|
+
}
|
|
224
257
|
/** Stops the service and removes it; downloaded CLI versions and logs stay. */
|
|
225
258
|
export async function uninstallService(environment) {
|
|
226
259
|
const definition = definitionPath(environment);
|
|
260
|
+
const wasRunning = (await readListenerLock(environment.appDir))?.service === true;
|
|
227
261
|
switch (environment.platform) {
|
|
228
262
|
case 'darwin':
|
|
229
263
|
await environment.run('launchctl', ['bootout', `gui/${environment.uid}/${LAUNCHD_LABEL}`]);
|
|
@@ -231,10 +265,21 @@ export async function uninstallService(environment) {
|
|
|
231
265
|
case 'linux':
|
|
232
266
|
await environment.run('systemctl', ['--user', 'disable', '--now', SYSTEMD_UNIT]);
|
|
233
267
|
break;
|
|
234
|
-
case 'win32':
|
|
235
|
-
await environment.run('schtasks', ['/
|
|
236
|
-
|
|
268
|
+
case 'win32': {
|
|
269
|
+
const task = await environment.run('schtasks', ['/Query', '/TN', WINDOWS_TASK]);
|
|
270
|
+
if (task.code === 0) {
|
|
271
|
+
await must(environment, 'schtasks', ['/Change', '/TN', WINDOWS_TASK, '/DISABLE'], 'Disable agents task');
|
|
272
|
+
}
|
|
273
|
+
// /End only stops conhost on some Windows versions, leaving Node and its worker alive.
|
|
274
|
+
// Discover by launcher path even after a previous uninstall removed the config and task.
|
|
275
|
+
await must(environment, 'powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand',
|
|
276
|
+
Buffer.from(windowsStopServiceScript(environment.appDir), 'utf16le').toString('base64')], 'Stop agents service processes');
|
|
277
|
+
if (task.code === 0) {
|
|
278
|
+
await environment.run('schtasks', ['/End', '/TN', WINDOWS_TASK]);
|
|
279
|
+
await must(environment, 'schtasks', ['/Delete', '/TN', WINDOWS_TASK, '/F'], 'Delete agents task');
|
|
280
|
+
}
|
|
237
281
|
break;
|
|
282
|
+
}
|
|
238
283
|
}
|
|
239
284
|
const existed = existsSync(definition) || existsSync(servicePaths(environment.appDir).config);
|
|
240
285
|
const paths = servicePaths(environment.appDir);
|
|
@@ -242,7 +287,21 @@ export async function uninstallService(environment) {
|
|
|
242
287
|
await rm(path, { force: true });
|
|
243
288
|
if (environment.platform === 'linux')
|
|
244
289
|
await environment.run('systemctl', ['--user', 'daemon-reload']);
|
|
245
|
-
return existed;
|
|
290
|
+
return existed || wasRunning;
|
|
291
|
+
}
|
|
292
|
+
export async function detectServiceAgents(appDir) {
|
|
293
|
+
const warnings = await refreshServicePath();
|
|
294
|
+
const detected = await detectAgents();
|
|
295
|
+
detected.problems.unshift(...warnings);
|
|
296
|
+
const report = {
|
|
297
|
+
checkedAt: new Date().toISOString(), path: process.env.PATH ?? '',
|
|
298
|
+
agents: detected.capabilities.agents.map(agent => `${agent.kind} ${agent.version ?? ''}`.trim()),
|
|
299
|
+
problems: detected.problems,
|
|
300
|
+
};
|
|
301
|
+
await writeFile(servicePaths(appDir).detection, JSON.stringify(report, null, 2));
|
|
302
|
+
for (const problem of report.problems)
|
|
303
|
+
console.warn(problem);
|
|
304
|
+
return detected;
|
|
246
305
|
}
|
|
247
306
|
export async function serviceStatus(environment) {
|
|
248
307
|
let config;
|
|
@@ -252,14 +311,23 @@ export async function serviceStatus(environment) {
|
|
|
252
311
|
catch { }
|
|
253
312
|
const lock = await readListenerLock(environment.appDir);
|
|
254
313
|
const running = lock?.service === true;
|
|
314
|
+
let detection;
|
|
315
|
+
try {
|
|
316
|
+
const report = JSON.parse(await readFile(servicePaths(environment.appDir).detection, 'utf8'));
|
|
317
|
+
if (running && report.checkedAt >= lock.startedAt)
|
|
318
|
+
detection = report;
|
|
319
|
+
}
|
|
320
|
+
catch { }
|
|
255
321
|
return {
|
|
256
|
-
installed: config !== undefined && existsSync(definitionPath(environment)), config, running,
|
|
322
|
+
installed: config !== undefined && existsSync(definitionPath(environment)), config, running, detection,
|
|
257
323
|
pid: running ? lock.pid : undefined, version: running ? lock.version : undefined, since: running ? lock.startedAt : undefined,
|
|
258
324
|
};
|
|
259
325
|
}
|
|
260
326
|
export function renderServiceStatus(status, appDir) {
|
|
261
327
|
if (!status.installed)
|
|
262
|
-
return
|
|
328
|
+
return status.running
|
|
329
|
+
? `The agents service is not installed, but process ${status.pid} is still running. Stop it with skillshare agents service uninstall.`
|
|
330
|
+
: 'The agents service is not installed. Install it with skillshare agents service install.';
|
|
263
331
|
const lines = [
|
|
264
332
|
status.running
|
|
265
333
|
? `The agents service is running (process ${status.pid}, Skillshare CLI ${status.version}, since ${status.since}).`
|
|
@@ -269,6 +337,13 @@ export function renderServiceStatus(status, appDir) {
|
|
|
269
337
|
];
|
|
270
338
|
if (status.config.args.length)
|
|
271
339
|
lines.push(`Options: ${status.config.args.join(' ')}`);
|
|
340
|
+
if (status.detection) {
|
|
341
|
+
lines.push(`Service agent detection (${status.detection.checkedAt}): ${status.detection.agents.join(', ') || 'No supported agent found.'}`);
|
|
342
|
+
lines.push(`Service PATH: ${status.detection.path}`);
|
|
343
|
+
lines.push(...status.detection.problems);
|
|
344
|
+
}
|
|
345
|
+
else
|
|
346
|
+
lines.push('Service agent detection is not available yet. Check service logs; reinstall with the updated CLI if needed.');
|
|
272
347
|
lines.push(`Log: ${servicePaths(appDir).log}`);
|
|
273
348
|
return lines.join('\n');
|
|
274
349
|
}
|
package/dist/agents.js
CHANGED
|
@@ -4,7 +4,7 @@ import { hostname, platform, tmpdir } from 'node:os';
|
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
6
|
import { createClaudeDriver } from './agents-claude.js';
|
|
7
|
-
import { defaultServiceEnvironment, installService, renderServiceStatus, serviceLogs, serviceStatus, uninstallService, } from './agents-service.js';
|
|
7
|
+
import { defaultServiceEnvironment, detectServiceAgents, installService, renderServiceStatus, serviceLogs, serviceStatus, uninstallService, } from './agents-service.js';
|
|
8
8
|
import { createCodexDriver } from './agents-codex.js';
|
|
9
9
|
import { detectAgents, expandHome, profilesPath } from './agents-detect.js';
|
|
10
10
|
import { SessionRunner, errorMessage, } from './agents-session.js';
|
|
@@ -135,6 +135,7 @@ export async function runAgentsCommand(client, args, flags, appDirectory, teamsW
|
|
|
135
135
|
try {
|
|
136
136
|
result = await listen({
|
|
137
137
|
client, listenerId, name: flags.name, workdir, maxConcurrency: max, sandbox, signal: abort.signal, onProgress: console.log, service,
|
|
138
|
+
detect: service ? () => detectServiceAgents(appDirectory) : undefined,
|
|
138
139
|
updater: worker ? { currentVersion: readCliVersion(), prepare: version => installVersion(appDirectory, version) } : undefined,
|
|
139
140
|
});
|
|
140
141
|
}
|
|
@@ -183,7 +184,7 @@ export async function runServiceCommand(action, flags, appDirectory, server) {
|
|
|
183
184
|
await installService(environment, { server, workdir, args: serviceListenArgs(flags), version });
|
|
184
185
|
// The service manager starts it right away; it takes a moment to sign in and report.
|
|
185
186
|
let status = await serviceStatus(environment);
|
|
186
|
-
for (let attempt = 0; attempt <
|
|
187
|
+
for (let attempt = 0; attempt < 60 && (!status.running || !status.detection); attempt++) {
|
|
187
188
|
await delay(500);
|
|
188
189
|
status = await serviceStatus(environment);
|
|
189
190
|
}
|
package/dist/help.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
export const GLOBAL_FLAGS = ['token', 'server', 'help'];
|
|
3
|
-
export const BOOLEAN_FLAGS = new Set(['dry-run', 'force', 'headless', 'help', 'json', 'no-teams-watch', 'no-update', 'sandbox']);
|
|
3
|
+
export const BOOLEAN_FLAGS = new Set(['dry-run', 'force', 'headless', 'help', 'json', 'no-teams-watch', 'no-update', 'resolved', 'sandbox']);
|
|
4
4
|
export const COMMANDS = [
|
|
5
5
|
{
|
|
6
6
|
name: 'login',
|
|
@@ -90,12 +90,17 @@ export const COMMANDS = [
|
|
|
90
90
|
'pages secrets list <slug> [--json]',
|
|
91
91
|
'pages secrets set <slug> <name> [--json]',
|
|
92
92
|
'pages secrets delete <slug> <name> [--json]',
|
|
93
|
+
'pages comments list <slug> [--path <path>] [--author mine|<user id>] [--resolved] [--json]',
|
|
94
|
+
'pages comments add <slug> [text] [--path <path>] [--json]',
|
|
95
|
+
'pages comments reply|edit <slug> <id> [text] [--json]',
|
|
96
|
+
'pages comments resolve|reopen|delete <slug> <id> [--json]',
|
|
97
|
+
'pages comments enable|disable <slug> [--json]',
|
|
93
98
|
'pages dev [directory] [--slug <slug>] [--port <port>] [--build <command> --watch-dir <sources>]',
|
|
94
99
|
' [--celld <executable>] [--user-id <id>] [--user-name <name>] [--user-email <email>]',
|
|
95
100
|
],
|
|
96
|
-
description: 'An upload replaces all content of the page. Without --slug the directory name is used; build output folders such as dist need an explicit --slug. Pages owned by someone else are refused unless you are an admin. pages secrets manages the write-only secrets an app reads through SKILLSHARE_SECRETS (owner or admin only, at most 32 per page, 16 KiB each); set reads the value from piped stdin or a masked prompt, never from the command line.',
|
|
97
|
-
examples: ['skillshare pages upload ./site --slug release-notes', 'skillshare pages dev . --slug my-app', 'skillshare pages secrets set my-app API_TOKEN', 'printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN'],
|
|
98
|
-
flags: ['slug', 'json'],
|
|
101
|
+
description: 'An upload replaces all content of the page. Without --slug the directory name is used; build output folders such as dist need an explicit --slug. Pages owned by someone else are refused unless you are an admin. pages secrets manages the write-only secrets an app reads through SKILLSHARE_SECRETS (owner or admin only, at most 32 per page, 16 KiB each); set reads the value from piped stdin or a masked prompt, never from the command line. pages comments reads and writes the annotations reviewers leave on a Page at /pa/<slug>/ (enable and disable decide whether the regular /p/<slug>/ address shows them too); add creates a page note, text without an argument (or -) is read from stdin, and list hides resolved threads unless --resolved is given.',
|
|
102
|
+
examples: ['skillshare pages upload ./site --slug release-notes', 'skillshare pages dev . --slug my-app', 'skillshare pages secrets set my-app API_TOKEN', 'printf %s "$TOKEN" | skillshare pages secrets set my-app API_TOKEN', 'skillshare pages comments list my-app --author mine', 'skillshare pages comments reply my-app 12 "Fixed in revision 4"'],
|
|
103
|
+
flags: ['slug', 'path', 'author', 'resolved', 'json'],
|
|
99
104
|
},
|
|
100
105
|
{
|
|
101
106
|
name: 'teams',
|
|
@@ -111,6 +116,18 @@ export const COMMANDS = [
|
|
|
111
116
|
],
|
|
112
117
|
flags: ['browser', 'headless', 'browser-profile', 'output', 'json'],
|
|
113
118
|
},
|
|
119
|
+
{
|
|
120
|
+
name: 'salesforce',
|
|
121
|
+
summary: 'Connect Salesforce to the read-only Skillshare Salesforce MCP',
|
|
122
|
+
usage: [
|
|
123
|
+
'salesforce login [local] [--instance <url>]',
|
|
124
|
+
'salesforce status | test [--json]',
|
|
125
|
+
'salesforce logout',
|
|
126
|
+
],
|
|
127
|
+
description: 'login opens Salesforce sign-in in the browser through the Salesforce CLI connected app (callback on localhost:1717), so no administrator has to create an app; your org must allow that app for you. --instance is the Lightning or My Domain URL of the org (or test.salesforce.com for a sandbox); later logins reuse the connected org. Skillshare keeps the Salesforce sign-in, renews it and offers agents only read tools: search, SOQL queries, records and object metadata, with your own Salesforce permissions. logout also revokes the sign-in in Salesforce.',
|
|
128
|
+
examples: ['skillshare salesforce login --instance https://acme--uat.sandbox.lightning.force.com', 'skillshare salesforce test'],
|
|
129
|
+
flags: ['instance', 'json'],
|
|
130
|
+
},
|
|
114
131
|
{
|
|
115
132
|
name: 'agents',
|
|
116
133
|
summary: 'Run Claude Code or Codex sessions from Skillshare on this computer',
|
|
@@ -151,7 +168,7 @@ export function renderUsage(defaultUrl) {
|
|
|
151
168
|
'Options:',
|
|
152
169
|
' --token <token> Bearer token for API requests (overrides SKILLSHARE_TOKEN)',
|
|
153
170
|
' --server <url> Skillshare origin for login and Teams commands',
|
|
154
|
-
' --json Print machine-readable JSON (whoami, list, show, upload, pages, teams, agents)',
|
|
171
|
+
' --json Print machine-readable JSON (whoami, list, show, upload, pages, teams, salesforce, agents)',
|
|
155
172
|
' -h, --help Show help for a command',
|
|
156
173
|
' -v, --version Show the CLI version',
|
|
157
174
|
'',
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runSalesforceCommand } from './salesforce.js';
|
|
1
2
|
import { assertCredentialDestination, resolveTeamsObjectId, runTeamsCommand, watchTeamsInBackground } from './teams.js';
|
|
2
3
|
import { runAgentsCommand, runServiceCommand } from './agents.js';
|
|
3
4
|
import { SERVICE_ENV } from './agents-update.js';
|
|
@@ -7,6 +8,7 @@ import { inspectInstallTarget, installFilesAtomically } from './install-files.js
|
|
|
7
8
|
import { preparePageFiles, resolvePageSlug } from './pages.js';
|
|
8
9
|
import { formatByteSize, formatDateTime, pageUrl, plural, renderPageDetail, renderPageList, renderPageRuntime, renderSkillDetail, renderSkillList, renderSkillVersion, renderUser, } from './output.js';
|
|
9
10
|
import { runPageDev } from './pages-dev.js';
|
|
11
|
+
import { runPageCommentsCommand } from './pages-comments.js';
|
|
10
12
|
import { runPageSecretsCommand } from './pages-secrets.js';
|
|
11
13
|
import { createServer } from 'node:http';
|
|
12
14
|
import { createHash, randomBytes } from 'node:crypto';
|
|
@@ -146,6 +148,13 @@ async function main() {
|
|
|
146
148
|
await runTeamsCommand(teamsClient, options.positionals, options.flags, APP_DIR);
|
|
147
149
|
return;
|
|
148
150
|
}
|
|
151
|
+
case 'salesforce': {
|
|
152
|
+
const baseUrl = options.flags.server ?? (options.positionals[1] === 'local' ? LOCAL_URL : await resolveActiveBaseUrl());
|
|
153
|
+
if (!options.token && !await loadSession(baseUrl))
|
|
154
|
+
await login(baseUrl);
|
|
155
|
+
await runSalesforceCommand(await createClient(baseUrl, options.token), options.positionals, options.flags, openBrowser);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
149
158
|
case 'agents': {
|
|
150
159
|
// Managing the background service needs no server, except to install it.
|
|
151
160
|
if (options.positionals[0] === 'service' && options.positionals[1] !== 'install') {
|
|
@@ -383,7 +392,11 @@ async function main() {
|
|
|
383
392
|
await runPageSecretsCommand(client, options.positionals.slice(1), print);
|
|
384
393
|
return;
|
|
385
394
|
}
|
|
386
|
-
|
|
395
|
+
if (action === 'comments') {
|
|
396
|
+
await runPageCommentsCommand(client, options.positionals.slice(1), options.flags, print);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
throw new Error(`Unknown pages command '${action}'. Use list, show, runtime, upload, secrets, or comments.`);
|
|
387
400
|
}
|
|
388
401
|
}
|
|
389
402
|
return;
|
package/dist/output.js
CHANGED
|
@@ -122,6 +122,7 @@ export function renderPageDetail(page, baseUrl, now = new Date()) {
|
|
|
122
122
|
`${page.slug} (${page.kind === 'celld' ? 'application' : 'static site'})`,
|
|
123
123
|
...fields([
|
|
124
124
|
['URL', pageUrl(baseUrl, page.slug)],
|
|
125
|
+
['Annotate', `${baseUrl.replace(/\/+$/, '')}/pa/${encodeURIComponent(page.slug)}/`],
|
|
125
126
|
['Owner', page.ownerDisplayName],
|
|
126
127
|
['Revision', `${page.contentRevision}, updated ${formatDateTime(page.updated)}`],
|
|
127
128
|
['Users this month', page.monthlyUsage.find((usage) => usage.month === month)?.uniqueUsers ?? 0],
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { formatDateTime } from './output.js';
|
|
2
|
+
const ACTIONS = ['list', 'add', 'reply', 'edit', 'resolve', 'reopen', 'delete', 'enable', 'disable'];
|
|
3
|
+
/** Keeps threads where the author (`mine` or a user id) wrote the first comment or any reply. */
|
|
4
|
+
export function filterPageComments(list, filter) {
|
|
5
|
+
const authorId = filter.author === 'mine' ? list.currentUserId : filter.author ? Number(filter.author) : undefined;
|
|
6
|
+
if (filter.author && filter.author !== 'mine' && !Number.isInteger(authorId)) {
|
|
7
|
+
throw new Error('--author must be "mine" or a user id.');
|
|
8
|
+
}
|
|
9
|
+
const threads = list.annotations.filter((comment) => comment.threadId === comment.id);
|
|
10
|
+
return threads.filter((thread) => {
|
|
11
|
+
if (!filter.resolved && thread.resolved)
|
|
12
|
+
return false;
|
|
13
|
+
if (authorId === undefined)
|
|
14
|
+
return true;
|
|
15
|
+
return list.annotations.some((comment) => comment.threadId === thread.id && comment.authorUserId === authorId);
|
|
16
|
+
}).flatMap((thread) => list.annotations.filter((comment) => comment.threadId === thread.id));
|
|
17
|
+
}
|
|
18
|
+
function quote(comment) {
|
|
19
|
+
if (comment.kind !== 'text')
|
|
20
|
+
return null;
|
|
21
|
+
try {
|
|
22
|
+
const anchor = JSON.parse(comment.anchor);
|
|
23
|
+
return anchor.quote ? anchor.quote.replace(/\s+/g, ' ').slice(0, 120) : null;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function renderPageComments(slug, list, comments) {
|
|
30
|
+
const header = list.enabled ? [] : [`/p/${slug}/ hides annotations; comment on /pa/${slug}/.`, ''];
|
|
31
|
+
if (comments.length === 0)
|
|
32
|
+
return [...header, `/p/${slug}/ has no matching comments.`].join('\n');
|
|
33
|
+
const lines = [...header];
|
|
34
|
+
let path = null;
|
|
35
|
+
for (const comment of comments) {
|
|
36
|
+
const isThread = comment.threadId === comment.id;
|
|
37
|
+
if (isThread && comment.path !== path) {
|
|
38
|
+
path = comment.path;
|
|
39
|
+
if (lines.length > header.length)
|
|
40
|
+
lines.push('');
|
|
41
|
+
lines.push(`/p/${slug}/${path}`);
|
|
42
|
+
}
|
|
43
|
+
const indent = isThread ? ' ' : ' ';
|
|
44
|
+
const status = isThread ? ` [${comment.kind}${comment.resolved ? `, resolved by ${comment.resolvedByDisplayName}` : ''}]` : '';
|
|
45
|
+
lines.push(`${indent}#${comment.id}${status} ${comment.authorDisplayName} · ${formatDateTime(comment.created)}`);
|
|
46
|
+
const quoted = quote(comment);
|
|
47
|
+
if (quoted)
|
|
48
|
+
lines.push(`${indent} > ${quoted}`);
|
|
49
|
+
for (const line of comment.body.split('\n'))
|
|
50
|
+
lines.push(`${indent} ${line}`);
|
|
51
|
+
}
|
|
52
|
+
return lines.join('\n');
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Reads and writes a Page's annotation comments. /pa/<slug>/ always shows them; enable and disable
|
|
56
|
+
* only decide whether the regular /p/<slug>/ address shows them too. The CLI adds page notes and replies;
|
|
57
|
+
* text highlights and pins are placed in the browser where their position is known.
|
|
58
|
+
*/
|
|
59
|
+
export async function runPageCommentsCommand(client, positionals, flags, print, readText = readStdin) {
|
|
60
|
+
const [action = 'list', slug, ...rest] = positionals;
|
|
61
|
+
if (!ACTIONS.includes(action)) {
|
|
62
|
+
throw new Error(`Unknown pages comments command '${action}'. Use ${ACTIONS.join(', ')}.`);
|
|
63
|
+
}
|
|
64
|
+
if (!slug)
|
|
65
|
+
throw new Error(`pages comments ${action} requires <slug>`);
|
|
66
|
+
const base = `/api/pages/${encodeURIComponent(slug)}/annotations`;
|
|
67
|
+
if (action === 'list') {
|
|
68
|
+
const query = flags.path !== undefined ? `?path=${encodeURIComponent(flags.path)}` : '';
|
|
69
|
+
const list = await expectJson(slug, await client.request(base + query, { method: 'GET' }));
|
|
70
|
+
const comments = filterPageComments(list, { path: flags.path, author: flags.author, resolved: flags.resolved === 'true' });
|
|
71
|
+
print(comments, () => renderPageComments(slug, list, comments));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (action === 'enable' || action === 'disable') {
|
|
75
|
+
await expectJson(slug, await client.request(`${base}/settings`, json('PUT', { enabled: action === 'enable' })));
|
|
76
|
+
print({ enabled: action === 'enable' }, () => action === 'enable'
|
|
77
|
+
? `/p/${slug}/ now shows the Annotations button too. Reload the Page to see it.`
|
|
78
|
+
: `/p/${slug}/ no longer shows annotations. They stay available on /pa/${slug}/.`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (action === 'add') {
|
|
82
|
+
const body = await commentText(rest, readText);
|
|
83
|
+
const created = await expectJson(slug, await client.request(base, json('POST', { path: normalizePath(flags.path), kind: 'note', anchor: '', body })));
|
|
84
|
+
print(created, () => `Added page note #${created.id} to /p/${slug}/${created.path}.`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const [idText, ...text] = rest;
|
|
88
|
+
const id = Number(idText);
|
|
89
|
+
if (!idText || !Number.isInteger(id) || id <= 0)
|
|
90
|
+
throw new Error(`pages comments ${action} requires <slug> <comment id>`);
|
|
91
|
+
if (action === 'delete') {
|
|
92
|
+
await expectJson(slug, await client.request(`${base}/${id}`, { method: 'DELETE' }), id);
|
|
93
|
+
print({ deleted: id }, () => `Deleted comment #${id} and its replies.`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (action === 'reply') {
|
|
97
|
+
const created = await expectJson(slug, await client.request(base, json('POST', { threadId: id, body: await commentText(text, readText) })), id);
|
|
98
|
+
print(created, () => `Added reply #${created.id} to #${id}.`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const change = action === 'edit' ? { body: await commentText(text, readText) } : { resolved: action === 'resolve' };
|
|
102
|
+
const updated = await expectJson(slug, await client.request(`${base}/${id}`, json('PATCH', change)), id);
|
|
103
|
+
print(updated, () => action === 'edit' ? `Updated comment #${id}.` : `${action === 'resolve' ? 'Resolved' : 'Reopened'} #${id}.`);
|
|
104
|
+
}
|
|
105
|
+
function json(method, body) {
|
|
106
|
+
return { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) };
|
|
107
|
+
}
|
|
108
|
+
function normalizePath(path) {
|
|
109
|
+
return (path ?? '').replace(/^\/+/, '');
|
|
110
|
+
}
|
|
111
|
+
async function commentText(words, readText) {
|
|
112
|
+
const text = (words.length > 0 && words.join(' ') !== '-' ? words.join(' ') : await readText()).trim();
|
|
113
|
+
if (!text)
|
|
114
|
+
throw new Error('The comment is empty. Pass it as an argument or pipe it to stdin.');
|
|
115
|
+
return text;
|
|
116
|
+
}
|
|
117
|
+
async function expectJson(slug, response, id) {
|
|
118
|
+
if (response.status === 204)
|
|
119
|
+
return undefined;
|
|
120
|
+
if (response.ok)
|
|
121
|
+
return await response.json();
|
|
122
|
+
if (response.status === 403) {
|
|
123
|
+
throw new Error(id
|
|
124
|
+
? `Only the comment's author, the owner of /p/${slug}/ or an administrator can change #${id}.`
|
|
125
|
+
: `Only the owner of /p/${slug}/ or an administrator can change its annotation settings.`);
|
|
126
|
+
}
|
|
127
|
+
if (response.status === 404)
|
|
128
|
+
throw new Error(id ? `Comment #${id} on /p/${slug}/ was not found.` : `Page /p/${slug}/ was not found.`);
|
|
129
|
+
let error = {};
|
|
130
|
+
try {
|
|
131
|
+
error = await response.json();
|
|
132
|
+
}
|
|
133
|
+
catch { }
|
|
134
|
+
throw new Error(error.error ?? `Skillshare returned HTTP ${response.status} for the Page comments.`);
|
|
135
|
+
}
|
|
136
|
+
async function readStdin() {
|
|
137
|
+
if (process.stdin.isTTY)
|
|
138
|
+
return '';
|
|
139
|
+
const chunks = [];
|
|
140
|
+
for await (const chunk of process.stdin)
|
|
141
|
+
chunks.push(Buffer.from(chunk));
|
|
142
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
143
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { assertCredentialDestination } from './teams.js';
|
|
4
|
+
const root = '/api/mcps/providers/salesforce';
|
|
5
|
+
// The Salesforce CLI connected app exists in every org and accepts only this loopback redirect,
|
|
6
|
+
// so users can connect without an administrator creating an app for Skillshare.
|
|
7
|
+
export const SALESFORCE_CLIENT_ID = 'PlatformCLI';
|
|
8
|
+
export const SALESFORCE_CALLBACK_PORT = 1717;
|
|
9
|
+
const callbackPath = '/OauthRedirect';
|
|
10
|
+
const domainLabel = '[a-z0-9](?:[a-z0-9-]{0,78}[a-z0-9])?(?:\\.(?:sandbox|develop|scratch|demo|patch|trailblaze))?';
|
|
11
|
+
const myDomainHost = new RegExp(`^${domainLabel}\\.my\\.salesforce\\.com$`);
|
|
12
|
+
const lightningHost = new RegExp(`^${domainLabel}\\.lightning\\.force\\.com$`);
|
|
13
|
+
/**
|
|
14
|
+
* Accepts login.salesforce.com, test.salesforce.com, a My Domain URL or the Lightning URL from the browser
|
|
15
|
+
* (mapped to its My Domain), with or without https://. Returns the https origin, or null.
|
|
16
|
+
*/
|
|
17
|
+
export function normalizeSalesforceLoginUrl(value) {
|
|
18
|
+
let input = value?.trim() ?? '';
|
|
19
|
+
if (!input)
|
|
20
|
+
return null;
|
|
21
|
+
if (!input.includes('://'))
|
|
22
|
+
input = `https://${input}`;
|
|
23
|
+
let url;
|
|
24
|
+
try {
|
|
25
|
+
url = new URL(input);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (url.protocol !== 'https:' || url.port || url.username || url.password)
|
|
31
|
+
return null;
|
|
32
|
+
let host = url.hostname.toLowerCase();
|
|
33
|
+
if (lightningHost.test(host))
|
|
34
|
+
host = host.slice(0, -'.lightning.force.com'.length) + '.my.salesforce.com';
|
|
35
|
+
return host === 'login.salesforce.com' || host === 'test.salesforce.com' || myDomainHost.test(host) ? `https://${host}` : null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Runs the OAuth authorization code flow with PKCE in the browser and returns the code. The code is handed to
|
|
39
|
+
* Skillshare, which redeems it; no Salesforce token is ever stored on this computer.
|
|
40
|
+
*/
|
|
41
|
+
export async function captureSalesforceAuthorization(options) {
|
|
42
|
+
const port = options.port ?? SALESFORCE_CALLBACK_PORT;
|
|
43
|
+
const redirectUri = `http://localhost:${port}${callbackPath}`;
|
|
44
|
+
const codeVerifier = randomBytes(32).toString('base64url');
|
|
45
|
+
const state = randomBytes(16).toString('hex');
|
|
46
|
+
const authorize = new URL('/services/oauth2/authorize', options.loginUrl);
|
|
47
|
+
authorize.search = new URLSearchParams({
|
|
48
|
+
response_type: 'code',
|
|
49
|
+
client_id: SALESFORCE_CLIENT_ID,
|
|
50
|
+
redirect_uri: redirectUri,
|
|
51
|
+
scope: 'refresh_token api web',
|
|
52
|
+
code_challenge: createHash('sha256').update(codeVerifier).digest('base64url'),
|
|
53
|
+
code_challenge_method: 'S256',
|
|
54
|
+
state,
|
|
55
|
+
}).toString();
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
let timer;
|
|
58
|
+
const finish = (error, code) => {
|
|
59
|
+
clearTimeout(timer);
|
|
60
|
+
server.close();
|
|
61
|
+
server.closeAllConnections?.();
|
|
62
|
+
if (error)
|
|
63
|
+
reject(error);
|
|
64
|
+
else
|
|
65
|
+
resolve({ code: code, codeVerifier });
|
|
66
|
+
};
|
|
67
|
+
const server = createServer((request, response) => {
|
|
68
|
+
const url = new URL(request.url ?? '/', redirectUri);
|
|
69
|
+
if (url.pathname !== callbackPath) {
|
|
70
|
+
response.writeHead(404).end();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const reply = (message) => response.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8', Connection: 'close' }).end(message);
|
|
74
|
+
if (url.searchParams.get('state') !== state) {
|
|
75
|
+
reply('This sign-in does not belong to the running skillshare salesforce login.');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const error = url.searchParams.get('error');
|
|
79
|
+
if (error) {
|
|
80
|
+
const description = url.searchParams.get('error_description') ?? error;
|
|
81
|
+
reply(`Salesforce sign-in failed: ${description}`);
|
|
82
|
+
finish(new Error(error === 'OAUTH_APPROVAL_ERROR_GENERIC' || /installed/i.test(description)
|
|
83
|
+
? `Salesforce refused the Salesforce CLI app for your user (${description}). Your org must allow it: an administrator installs the Salesforce CLI connected app or grants you "Approve Uninstalled Connected Apps".`
|
|
84
|
+
: `Salesforce sign-in failed: ${description}`));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const code = url.searchParams.get('code');
|
|
88
|
+
if (!code) {
|
|
89
|
+
reply('Salesforce did not return an authorization code.');
|
|
90
|
+
finish(new Error('Salesforce did not return an authorization code.'));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
reply('Salesforce sign-in received. You can close this tab and return to the terminal.');
|
|
94
|
+
finish(null, code);
|
|
95
|
+
});
|
|
96
|
+
server.once('error', (error) => finish(error.code === 'EADDRINUSE'
|
|
97
|
+
? new Error(`Port ${port} is in use (Salesforce CLI may be signing in). Close it and retry.`)
|
|
98
|
+
: error));
|
|
99
|
+
server.listen(port, '127.0.0.1', () => {
|
|
100
|
+
timer = setTimeout(() => finish(new Error('Salesforce sign-in timed out.')), options.timeoutMs ?? 5 * 60_000);
|
|
101
|
+
options.log?.(`Sign in to Salesforce in the browser. If it does not open, visit:\n${authorize}`);
|
|
102
|
+
options.openBrowser(authorize.toString()).catch(() => { });
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async function expectOk(response) {
|
|
107
|
+
if (response.ok)
|
|
108
|
+
return;
|
|
109
|
+
let error = {};
|
|
110
|
+
try {
|
|
111
|
+
error = await response.json();
|
|
112
|
+
}
|
|
113
|
+
catch { }
|
|
114
|
+
throw new Error(error.error ?? `Skillshare Salesforce API returned HTTP ${response.status}.`);
|
|
115
|
+
}
|
|
116
|
+
export function renderSalesforceStatus(status) {
|
|
117
|
+
const state = status.requiresReconnect
|
|
118
|
+
? 'reconnect required — run skillshare salesforce login'
|
|
119
|
+
: status.configured
|
|
120
|
+
? `connected${status.identity ? ` as ${status.identity}` : ''}`
|
|
121
|
+
: 'not connected — run skillshare salesforce login --instance <url>';
|
|
122
|
+
return [
|
|
123
|
+
`Salesforce: ${state}`,
|
|
124
|
+
...(status.organization ? [` Instance: ${status.organization}`] : []),
|
|
125
|
+
...(status.updatedAt ? [` Updated: ${new Date(status.updatedAt).toLocaleString()}`] : []),
|
|
126
|
+
` MCP endpoint: ${status.endpoint}`,
|
|
127
|
+
].join('\n');
|
|
128
|
+
}
|
|
129
|
+
export async function runSalesforceCommand(client, args, flags, openBrowser) {
|
|
130
|
+
const action = args[0];
|
|
131
|
+
const json = flags.json === 'true';
|
|
132
|
+
if (action === 'login') {
|
|
133
|
+
// The authorization code is a credential: send it only over HTTPS, or HTTP on loopback.
|
|
134
|
+
assertCredentialDestination(client.baseUrl);
|
|
135
|
+
let instance = flags.instance;
|
|
136
|
+
if (!instance) {
|
|
137
|
+
const status = await client.get(`${root}/settings`);
|
|
138
|
+
instance = status.organization ?? undefined;
|
|
139
|
+
}
|
|
140
|
+
if (!instance) {
|
|
141
|
+
throw new Error('Pass the org to sign in to: skillshare salesforce login --instance <url>, for example the Lightning URL from your browser (https://acme.lightning.force.com), its My Domain, or test.salesforce.com for a sandbox.');
|
|
142
|
+
}
|
|
143
|
+
const loginUrl = normalizeSalesforceLoginUrl(instance);
|
|
144
|
+
if (!loginUrl)
|
|
145
|
+
throw new Error(`${instance} is not a Salesforce login URL. Use your My Domain or Lightning URL, login.salesforce.com or test.salesforce.com.`);
|
|
146
|
+
const authorization = await captureSalesforceAuthorization({ loginUrl, openBrowser, log: console.log });
|
|
147
|
+
const response = await client.request(`${root}/connection`, {
|
|
148
|
+
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
|
149
|
+
body: JSON.stringify({ loginUrl, code: authorization.code, codeVerifier: authorization.codeVerifier }),
|
|
150
|
+
});
|
|
151
|
+
await expectOk(response);
|
|
152
|
+
const result = await response.json();
|
|
153
|
+
console.log(`Salesforce connected as ${result.identity} (${result.instanceUrl}).`);
|
|
154
|
+
console.log(`MCP endpoint: ${client.baseUrl}/salesforce/mcp`);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (action === 'status') {
|
|
158
|
+
const status = await client.get(`${root}/settings`);
|
|
159
|
+
console.log(json ? JSON.stringify(status, null, 2) : renderSalesforceStatus(status));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (action === 'test') {
|
|
163
|
+
const response = await client.request(`${root}/test`, { method: 'POST' });
|
|
164
|
+
const result = await response.json().catch(() => ({}));
|
|
165
|
+
if (json)
|
|
166
|
+
console.log(JSON.stringify(result, null, 2));
|
|
167
|
+
if (!response.ok || !result.success)
|
|
168
|
+
throw new Error(result.error ?? `Skillshare Salesforce API returned HTTP ${response.status}.`);
|
|
169
|
+
if (!json)
|
|
170
|
+
console.log(`Salesforce connection works${result.identity ? ` for ${result.identity}` : ''}.`);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (action === 'logout') {
|
|
174
|
+
const response = await client.request(`${root}/connection`, { method: 'DELETE' });
|
|
175
|
+
if (response.status !== 404)
|
|
176
|
+
await expectOk(response);
|
|
177
|
+
console.log('Salesforce disconnected from Skillshare and the sign-in revoked in Salesforce.');
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
throw new Error('salesforce requires login, status, test or logout.');
|
|
181
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadient/skillshare",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Skillshare CLI for installing and publishing Quadient skills",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
17
17
|
"start": "node ./dist/index.js",
|
|
18
18
|
"prepublishOnly": "npm run build",
|
|
19
|
-
"test": "tsx --test cli-args.test.ts install-files.test.ts output.test.ts pages.test.ts pages-secrets.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-browser.test.ts agents.test.ts agents-update.test.ts"
|
|
19
|
+
"test": "tsx --test cli-args.test.ts install-files.test.ts output.test.ts pages.test.ts pages-secrets.test.ts pages-comments.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-update.test.ts"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|