@opsrev/acculynx-cli 1.8.1 → 1.9.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.
Files changed (2) hide show
  1. package/dist/index.js +37 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -62,12 +62,13 @@ function createApiClient(config) {
62
62
  body: JSON.stringify(body)
63
63
  });
64
64
  if (!response.ok) {
65
- const text = await response.text();
65
+ const text2 = await response.text();
66
66
  throw new Error(
67
- `API error (${response.status} ${response.statusText}): ${text}`
67
+ `API error (${response.status} ${response.statusText}): ${text2}`
68
68
  );
69
69
  }
70
- return response.json();
70
+ const text = await response.text();
71
+ return text ? JSON.parse(text) : { status: response.status };
71
72
  }
72
73
  async function doPostForm(path, body) {
73
74
  const url = `${config.baseUrl}${path}`;
@@ -169,7 +170,7 @@ function registerJobsCommands(parentCmd, getClient2) {
169
170
  if (opts.endDate) params.endDate = opts.endDate;
170
171
  if (opts.dateFilterType) params.dateFilterType = opts.dateFilterType;
171
172
  if (opts.milestones) params.milestones = opts.milestones;
172
- if (opts.sortBy) params.sortBy = opts.sortBy;
173
+ params.sortBy = opts.sortBy ?? "CreatedDate";
173
174
  if (opts.sortOrder) params.sortOrder = opts.sortOrder;
174
175
  if (opts.includes) params.includes = opts.includes;
175
176
  if (opts.assignment) params.assignment = opts.assignment;
@@ -207,6 +208,17 @@ function registerJobsCommands(parentCmd, getClient2) {
207
208
  console.log(JSON.stringify(result));
208
209
  });
209
210
  }
211
+ jobs.command("reps").argument("<jobId>", "Job ID").description("List all representatives for a job").action(async (jobId) => {
212
+ const result = await getClient2().get(`/jobs/${jobId}/representatives`);
213
+ console.log(JSON.stringify(result));
214
+ });
215
+ jobs.command("reps-assign").argument("<jobId>", "Job ID").description("Assign a representative to a job").requiredOption("--user-id <id>", "User ID to assign").option("--type <type>", "Rep type: company, sales-owner, ar-owner", "company").action(async (jobId, opts) => {
216
+ const result = await getClient2().post(
217
+ `/jobs/${jobId}/representatives/${opts.type}`,
218
+ { id: opts.userId }
219
+ );
220
+ console.log(JSON.stringify(result));
221
+ });
210
222
  jobs.command("document-folders").description("List document folders for the company").option("--page-size <n>", "Number of items per page").option("--record-start-index <n>", "Index of first element to return", "0").option("--sort-order <order>", "Ascending or Descending", "Ascending").action(async (opts) => {
211
223
  const params = {
212
224
  recordStartIndex: opts.recordStartIndex,
@@ -310,6 +322,26 @@ function registerEstimatesCommands(parentCmd, getClient2) {
310
322
  });
311
323
  }
312
324
 
325
+ // src/commands/users.ts
326
+ function registerUsersCommands(parentCmd, getClient2) {
327
+ const users = parentCmd.command("users").description("User operations");
328
+ users.command("list").description("List users (paginated)").option("--limit <n>", "Max total results (default: 25)").option("--all", "Fetch all results (no limit)").option("--search <text>", "Filter users by name or email (client-side)").action(async (opts) => {
329
+ if (opts.search) {
330
+ const all = await paginate(getClient2(), "/users", {}, Infinity);
331
+ const term = opts.search.toLowerCase();
332
+ const filtered = all.filter((u) => {
333
+ const fields = [u.displayName, u.firstName, u.lastName, u.email];
334
+ return fields.some((f) => f && f.toLowerCase().includes(term));
335
+ });
336
+ console.log(JSON.stringify(filtered));
337
+ return;
338
+ }
339
+ const limit = opts.all ? Infinity : opts.limit ? parseInt(opts.limit, 10) : void 0;
340
+ const result = await paginate(getClient2(), "/users", {}, limit);
341
+ console.log(JSON.stringify(result));
342
+ });
343
+ }
344
+
313
345
  // src/index.ts
314
346
  var require2 = createRequire(import.meta.url);
315
347
  var { version } = require2("../package.json");
@@ -342,6 +374,7 @@ registerPingCommand(program, getClient);
342
374
  registerJobsCommands(program, getClient);
343
375
  registerContactsCommands(program, getClient);
344
376
  registerEstimatesCommands(program, getClient);
377
+ registerUsersCommands(program, getClient);
345
378
  try {
346
379
  const resolved = require2.resolve("@opsrev/acculynx-cli-unofficial");
347
380
  const mod = await import(resolved);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opsrev/acculynx-cli",
3
- "version": "1.8.1",
3
+ "version": "1.9.1",
4
4
  "description": "CLI for the AccuLynx roofing CRM API",
5
5
  "type": "module",
6
6
  "bin": {