@opsrev/acculynx-cli 1.1.0 → 1.2.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 +26 -1
- package/dist/index.js +161 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ API keys are created by your AccuLynx account administrator under Account Settin
|
|
|
30
30
|
|
|
31
31
|
### Unofficial Web API
|
|
32
32
|
|
|
33
|
-
The `unofficial` commands use cookie-based authentication against AccuLynx's internal web APIs. These provide access to features not available in the official API (job documents,
|
|
33
|
+
The `unofficial` commands use cookie-based authentication against AccuLynx's internal web APIs. These provide access to features not available in the official API (job documents, messages, etc.).
|
|
34
34
|
|
|
35
35
|
| Env Var | Flag | Description |
|
|
36
36
|
|---------|------|-------------|
|
|
@@ -79,8 +79,33 @@ acculynx unofficial logout # Remove cached session
|
|
|
79
79
|
acculynx unofficial sessions # List cached sessions
|
|
80
80
|
acculynx unofficial documents list <jobId> # List all document folders/files for a job
|
|
81
81
|
acculynx unofficial documents download <jobId> <fileId> [--output ./file.pdf] # Download a document
|
|
82
|
+
acculynx unofficial messages list <jobId> # List all messages/comments for a job
|
|
83
|
+
acculynx unofficial messages list <jobId> --type Email # Filter by type: Comment, Email, or Signatures
|
|
84
|
+
acculynx unofficial messages list <jobId> --count-only # Get message count only
|
|
85
|
+
acculynx unofficial messages post <jobId> <message> # Post a comment to a job
|
|
86
|
+
acculynx unofficial messages post <jobId> <message> --notify <userId,...> # Post and notify users
|
|
82
87
|
```
|
|
83
88
|
|
|
89
|
+
#### Messages
|
|
90
|
+
|
|
91
|
+
List all messages, comments, and emails on a job. HTML email content is automatically converted to lightweight markdown (headers, links, lists preserved; images and styles stripped) for clean AI agent consumption.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
acculynx unofficial messages list <jobId> # all messages, newest first
|
|
95
|
+
acculynx unofficial messages list <jobId> --sort "createdDate|asc" # oldest first
|
|
96
|
+
acculynx unofficial messages list <jobId> --type Email # only emails
|
|
97
|
+
acculynx unofficial messages list <jobId> --count-only # just the count
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Post a comment to a job, optionally notifying (tagging) users:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
acculynx unofficial messages post <jobId> "Your message here"
|
|
104
|
+
acculynx unofficial messages post <jobId> "Check this out" --notify "userId1,userId2"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
User IDs for `--notify` come from the official users API (`/api/v2/users`).
|
|
108
|
+
|
|
84
109
|
**Getting started:** If you don't know your company ID, run `companies` first -- it logs in and returns all companies available to your account:
|
|
85
110
|
|
|
86
111
|
```bash
|
package/dist/index.js
CHANGED
|
@@ -260,6 +260,16 @@ var CookieJar = class _CookieJar {
|
|
|
260
260
|
}
|
|
261
261
|
this.cookies.set(domain, jar);
|
|
262
262
|
}
|
|
263
|
+
/** Get a specific cookie value by name for a given URL. */
|
|
264
|
+
getCookie(url, name) {
|
|
265
|
+
const domain = new URL(url).hostname;
|
|
266
|
+
for (const [d, jar] of this.cookies) {
|
|
267
|
+
if (domain === d || domain.endsWith("." + d)) {
|
|
268
|
+
if (jar.has(name)) return jar.get(name);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return void 0;
|
|
272
|
+
}
|
|
263
273
|
/** Build a Cookie header string for a given URL. */
|
|
264
274
|
headerFor(url) {
|
|
265
275
|
const domain = new URL(url).hostname;
|
|
@@ -373,6 +383,36 @@ function createUnofficialClient(session) {
|
|
|
373
383
|
}
|
|
374
384
|
return resp.json();
|
|
375
385
|
}
|
|
386
|
+
async function doPost(path, body) {
|
|
387
|
+
const url = `${base}${path}`;
|
|
388
|
+
const headers = {
|
|
389
|
+
Cookie: session.jar.headerFor(url),
|
|
390
|
+
Accept: "application/json",
|
|
391
|
+
"Content-Type": "application/json"
|
|
392
|
+
};
|
|
393
|
+
const xsrf = session.jar.getCookie(url, "XSRF-TOKEN");
|
|
394
|
+
if (xsrf) {
|
|
395
|
+
headers["X-XSRF-TOKEN"] = xsrf;
|
|
396
|
+
}
|
|
397
|
+
const resp = await fetch(url, {
|
|
398
|
+
method: "POST",
|
|
399
|
+
headers,
|
|
400
|
+
body: JSON.stringify(body)
|
|
401
|
+
});
|
|
402
|
+
if (resp.status === 401 || resp.status === 302) {
|
|
403
|
+
throw new Error(
|
|
404
|
+
"Session expired \u2014 run `acculynx unofficial login` to re-authenticate"
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
if (!resp.ok) {
|
|
408
|
+
throw new Error(
|
|
409
|
+
`Unofficial API error (${resp.status}): ${await resp.text()}`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
const text = await resp.text();
|
|
413
|
+
if (!text) return {};
|
|
414
|
+
return JSON.parse(text);
|
|
415
|
+
}
|
|
376
416
|
async function doGetBuffer(url) {
|
|
377
417
|
const fullUrl = url.startsWith("http") ? url : `${base}${url}`;
|
|
378
418
|
const resp = await fetch(fullUrl, {
|
|
@@ -383,7 +423,7 @@ function createUnofficialClient(session) {
|
|
|
383
423
|
}
|
|
384
424
|
return Buffer.from(await resp.arrayBuffer());
|
|
385
425
|
}
|
|
386
|
-
return { get: doGet, getBuffer: doGetBuffer };
|
|
426
|
+
return { get: doGet, post: doPost, getBuffer: doGetBuffer };
|
|
387
427
|
}
|
|
388
428
|
|
|
389
429
|
// src/unofficial/session.ts
|
|
@@ -605,6 +645,125 @@ function registerDocumentsCommands(parentCmd, getClient2) {
|
|
|
605
645
|
});
|
|
606
646
|
}
|
|
607
647
|
|
|
648
|
+
// src/unofficial/commands/messages.ts
|
|
649
|
+
import TurndownService from "turndown";
|
|
650
|
+
function createTurndown() {
|
|
651
|
+
const td = new TurndownService({
|
|
652
|
+
headingStyle: "atx",
|
|
653
|
+
bulletListMarker: "-"
|
|
654
|
+
});
|
|
655
|
+
td.addRule("removeImages", {
|
|
656
|
+
filter: "img",
|
|
657
|
+
replacement: () => ""
|
|
658
|
+
});
|
|
659
|
+
td.addRule("removeStyle", {
|
|
660
|
+
filter: ["style", "script"],
|
|
661
|
+
replacement: () => ""
|
|
662
|
+
});
|
|
663
|
+
return td;
|
|
664
|
+
}
|
|
665
|
+
var looksLikeHtml = /<[a-z][\s\S]*?>/i;
|
|
666
|
+
function cleanMessage(html) {
|
|
667
|
+
if (!looksLikeHtml.test(html)) return html;
|
|
668
|
+
const td = createTurndown();
|
|
669
|
+
return td.turndown(html).replace(/\n{3,}/g, "\n\n").trim();
|
|
670
|
+
}
|
|
671
|
+
function registerMessagesCommands(parentCmd, getClient2) {
|
|
672
|
+
const messages = parentCmd.command("messages").description("Job message/comment operations");
|
|
673
|
+
messages.command("list").argument("<jobId>", "Job ID (GUID)").option(
|
|
674
|
+
"--sort <sort>",
|
|
675
|
+
"Sort field and direction (field|asc or field|desc)",
|
|
676
|
+
"createdDate|desc"
|
|
677
|
+
).option("--count-only", "Return only the total count of messages").option(
|
|
678
|
+
"--type <type>",
|
|
679
|
+
"Filter by message type: Comment, Email, or Signatures"
|
|
680
|
+
).description("List all messages and comments for a job").action(async (jobId, opts) => {
|
|
681
|
+
const params = new URLSearchParams({ sort: opts.sort });
|
|
682
|
+
if (opts.countOnly) {
|
|
683
|
+
params.set("countOnly", "true");
|
|
684
|
+
}
|
|
685
|
+
if (opts.type) {
|
|
686
|
+
params.append("filters", `type=${opts.type}`);
|
|
687
|
+
}
|
|
688
|
+
const data = await getClient2().get(
|
|
689
|
+
`/api/jobs/${jobId}/JobMessageFeed?${params.toString()}`
|
|
690
|
+
);
|
|
691
|
+
if (opts.countOnly) {
|
|
692
|
+
console.log(JSON.stringify({ totalRecords: data.TotalRecords }));
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
const result = {
|
|
696
|
+
totalRecords: data.TotalRecords,
|
|
697
|
+
currentPage: data.CurrentPage,
|
|
698
|
+
totalPages: data.TotalPages,
|
|
699
|
+
messages: data.results.map((msg) => ({
|
|
700
|
+
id: msg.id,
|
|
701
|
+
jobId: msg.JobId,
|
|
702
|
+
type: msg.Type,
|
|
703
|
+
messageType: msg.MessageType,
|
|
704
|
+
message: cleanMessage(msg.Message),
|
|
705
|
+
subject: msg.Subject,
|
|
706
|
+
createdBy: msg.CreatedBy,
|
|
707
|
+
createdById: msg.CreatedByID,
|
|
708
|
+
createdDate: msg.CreatedDate,
|
|
709
|
+
latestMessage: msg.LatestMessage,
|
|
710
|
+
parentMessageId: msg.ParentMessageId,
|
|
711
|
+
attachmentOnly: msg.AttachmentOnly,
|
|
712
|
+
replyEmail: msg.ReplyEmail,
|
|
713
|
+
sentDate: msg.SentDate,
|
|
714
|
+
recipients: msg.Recipients.map((r) => ({
|
|
715
|
+
id: r.id,
|
|
716
|
+
companyUserId: r.companyUserId,
|
|
717
|
+
sent: r.Sent,
|
|
718
|
+
sentDate: r.SentDate,
|
|
719
|
+
delivered: r.Delivered,
|
|
720
|
+
deliveredDate: r.DeliveredDate,
|
|
721
|
+
failed: r.Failed,
|
|
722
|
+
failedDate: r.FailedDate,
|
|
723
|
+
failedDescription: r.FailedDescription
|
|
724
|
+
})),
|
|
725
|
+
attachments: msg.Attachments,
|
|
726
|
+
childMessageCount: msg.ChildMessages.length,
|
|
727
|
+
childMessages: msg.ChildMessages.map((child) => ({
|
|
728
|
+
id: child.id,
|
|
729
|
+
type: child.Type,
|
|
730
|
+
message: cleanMessage(child.Message),
|
|
731
|
+
createdBy: child.CreatedBy,
|
|
732
|
+
createdDate: child.CreatedDate
|
|
733
|
+
}))
|
|
734
|
+
}))
|
|
735
|
+
};
|
|
736
|
+
console.log(JSON.stringify(result));
|
|
737
|
+
});
|
|
738
|
+
messages.command("post").argument("<jobId>", "Job ID (GUID)").argument("<message>", "Message text to post").option(
|
|
739
|
+
"--notify <userIds>",
|
|
740
|
+
"Comma-separated user IDs (GUIDs) to notify"
|
|
741
|
+
).description("Post a comment/message to a job, optionally notifying users").action(async (jobId, message, opts) => {
|
|
742
|
+
const emailRecipients = opts.notify ? opts.notify.split(",").map((id) => id.trim()) : [];
|
|
743
|
+
const data = await getClient2().post(
|
|
744
|
+
`/api/jobs/${jobId}/Messages`,
|
|
745
|
+
{
|
|
746
|
+
JobId: jobId,
|
|
747
|
+
Message: message,
|
|
748
|
+
RoleId: "1111111",
|
|
749
|
+
MessageType: "General Comment",
|
|
750
|
+
emailRecipients,
|
|
751
|
+
index: -1
|
|
752
|
+
}
|
|
753
|
+
);
|
|
754
|
+
console.log(
|
|
755
|
+
JSON.stringify({
|
|
756
|
+
id: data.JobMessageId,
|
|
757
|
+
jobId: data.JobId,
|
|
758
|
+
message: data.Message,
|
|
759
|
+
messageType: data.MessageType,
|
|
760
|
+
createdDate: data.CreatedDate,
|
|
761
|
+
notified: emailRecipients.length
|
|
762
|
+
})
|
|
763
|
+
);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
|
|
608
767
|
// src/unofficial/commands/index.ts
|
|
609
768
|
function getSessionFromEnv() {
|
|
610
769
|
const email = process.env.ACCULYNX_EMAIL;
|
|
@@ -635,6 +794,7 @@ function registerUnofficialCommands(parentCmd) {
|
|
|
635
794
|
return _client2;
|
|
636
795
|
}
|
|
637
796
|
registerDocumentsCommands(unofficial, getClient2);
|
|
797
|
+
registerMessagesCommands(unofficial, getClient2);
|
|
638
798
|
}
|
|
639
799
|
|
|
640
800
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opsrev/acculynx-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "CLI for the AccuLynx roofing CRM API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,10 +28,12 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"commander": "^14.0.3"
|
|
31
|
+
"commander": "^14.0.3",
|
|
32
|
+
"turndown": "^7.2.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/node": "^25.4.0",
|
|
36
|
+
"@types/turndown": "^5.0.6",
|
|
35
37
|
"tsup": "^8.5.1",
|
|
36
38
|
"tsx": "^4.21.0",
|
|
37
39
|
"typescript": "^5.9.3",
|