@opsrev/acculynx-cli 1.4.0 → 1.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/dist/index.js +71 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -68,9 +68,27 @@ function createApiClient(config) {
|
|
|
68
68
|
}
|
|
69
69
|
return response.json();
|
|
70
70
|
}
|
|
71
|
+
async function doPostForm(path, body) {
|
|
72
|
+
const url = `${config.baseUrl}${path}`;
|
|
73
|
+
const { "Content-Type": _, ...formHeaders } = headers;
|
|
74
|
+
const response = await fetchWithRetry(url, {
|
|
75
|
+
method: "POST",
|
|
76
|
+
headers: formHeaders,
|
|
77
|
+
body
|
|
78
|
+
});
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
const text2 = await response.text();
|
|
81
|
+
throw new Error(
|
|
82
|
+
`API error (${response.status} ${response.statusText}): ${text2}`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
const text = await response.text();
|
|
86
|
+
return text ? JSON.parse(text) : { status: response.status };
|
|
87
|
+
}
|
|
71
88
|
return {
|
|
72
89
|
get: doGet,
|
|
73
|
-
post: doPost
|
|
90
|
+
post: doPost,
|
|
91
|
+
postForm: doPostForm
|
|
74
92
|
};
|
|
75
93
|
}
|
|
76
94
|
|
|
@@ -82,6 +100,10 @@ function registerPingCommand(parentCmd, getClient2) {
|
|
|
82
100
|
});
|
|
83
101
|
}
|
|
84
102
|
|
|
103
|
+
// src/commands/jobs.ts
|
|
104
|
+
import { readFileSync } from "fs";
|
|
105
|
+
import { basename, extname } from "path";
|
|
106
|
+
|
|
85
107
|
// src/api-helpers.ts
|
|
86
108
|
var DEFAULT_PAGE_SIZE = 25;
|
|
87
109
|
var DEFAULT_LIMIT = 25;
|
|
@@ -125,6 +147,19 @@ async function readStdin(stream = process.stdin) {
|
|
|
125
147
|
}
|
|
126
148
|
|
|
127
149
|
// src/commands/jobs.ts
|
|
150
|
+
var DISALLOWED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
151
|
+
".exe",
|
|
152
|
+
".com",
|
|
153
|
+
".dll",
|
|
154
|
+
".msi",
|
|
155
|
+
".bat",
|
|
156
|
+
".cmd",
|
|
157
|
+
".sh",
|
|
158
|
+
".pl",
|
|
159
|
+
".vbs",
|
|
160
|
+
".py",
|
|
161
|
+
".php"
|
|
162
|
+
]);
|
|
128
163
|
function registerJobsCommands(parentCmd, getClient2) {
|
|
129
164
|
const jobs = parentCmd.command("jobs").description("Job operations");
|
|
130
165
|
jobs.command("list").description("List jobs (paginated)").option("--start-date <date>", "Start date (YYYY-MM-DD)").option("--end-date <date>", "End date (YYYY-MM-DD)").option("--date-filter-type <type>", "Date field to filter on").option("--milestones <milestones>", "Filter by milestones").option("--sort-by <field>", "Sort by: CreatedDate, MilestoneDate, ModifiedDate").option("--sort-order <order>", "Ascending or Descending").option("--includes <fields>", "Include: contact, initialAppointment").option("--assignment <type>", "Filter by assignment: assigned, unassigned").option("--limit <n>", "Max total results (default: 25)").option("--all", "Fetch all results (no limit)").action(async (opts) => {
|
|
@@ -171,6 +206,38 @@ function registerJobsCommands(parentCmd, getClient2) {
|
|
|
171
206
|
console.log(JSON.stringify(result));
|
|
172
207
|
});
|
|
173
208
|
}
|
|
209
|
+
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) => {
|
|
210
|
+
const params = {
|
|
211
|
+
recordStartIndex: opts.recordStartIndex,
|
|
212
|
+
sortOrder: opts.sortOrder
|
|
213
|
+
};
|
|
214
|
+
if (opts.pageSize) params.pageSize = opts.pageSize;
|
|
215
|
+
const result = await getClient2().get(
|
|
216
|
+
"/company-settings/job-file-settings/document-folders",
|
|
217
|
+
params
|
|
218
|
+
);
|
|
219
|
+
console.log(JSON.stringify(result));
|
|
220
|
+
});
|
|
221
|
+
jobs.command("upload-document").argument("<jobId>", "Job ID").argument("<filePath>", "Path to the file to upload").requiredOption("--folder-id <id>", "Document folder ID (required)").option("--description <text>", "Brief description of the file").option("--external-id <id>", "External reference identifier").option("--external-source <source>", "External reference source").description("Upload a document to a job").action(async (jobId, filePath, opts) => {
|
|
222
|
+
const ext = extname(filePath).toLowerCase();
|
|
223
|
+
if (DISALLOWED_EXTENSIONS.has(ext)) {
|
|
224
|
+
throw new Error(`File type ${ext} is not allowed`);
|
|
225
|
+
}
|
|
226
|
+
const fileBuffer = readFileSync(filePath);
|
|
227
|
+
const fileName = basename(filePath);
|
|
228
|
+
const file = new File([fileBuffer], fileName);
|
|
229
|
+
const form = new FormData();
|
|
230
|
+
form.append("file", file);
|
|
231
|
+
form.append("documentFolderId", opts.folderId);
|
|
232
|
+
if (opts.description) form.append("description", opts.description);
|
|
233
|
+
if (opts.externalId) form.append("externalId", opts.externalId);
|
|
234
|
+
if (opts.externalSource) form.append("externalSource", opts.externalSource);
|
|
235
|
+
const result = await getClient2().postForm(
|
|
236
|
+
`/jobs/${jobId}/documents`,
|
|
237
|
+
form
|
|
238
|
+
);
|
|
239
|
+
console.log(JSON.stringify(result));
|
|
240
|
+
});
|
|
174
241
|
}
|
|
175
242
|
|
|
176
243
|
// src/commands/contacts.ts
|
|
@@ -237,7 +304,7 @@ function registerEstimatesCommands(parentCmd, getClient2) {
|
|
|
237
304
|
// src/unofficial/session-store.ts
|
|
238
305
|
import {
|
|
239
306
|
existsSync,
|
|
240
|
-
readFileSync,
|
|
307
|
+
readFileSync as readFileSync2,
|
|
241
308
|
writeFileSync,
|
|
242
309
|
mkdirSync,
|
|
243
310
|
readdirSync,
|
|
@@ -315,7 +382,7 @@ function loadSession(email, companyId) {
|
|
|
315
382
|
const file = join(SESSIONS_DIR, sessionKey(email, companyId));
|
|
316
383
|
if (!existsSync(file)) return null;
|
|
317
384
|
try {
|
|
318
|
-
const data = JSON.parse(
|
|
385
|
+
const data = JSON.parse(readFileSync2(file, "utf-8"));
|
|
319
386
|
return {
|
|
320
387
|
jar: CookieJar.fromJSON(data.cookies),
|
|
321
388
|
companyId: data.companyId,
|
|
@@ -352,7 +419,7 @@ function listSessions() {
|
|
|
352
419
|
return readdirSync(SESSIONS_DIR).filter((f) => f.endsWith(".json")).map((f) => {
|
|
353
420
|
try {
|
|
354
421
|
const data = JSON.parse(
|
|
355
|
-
|
|
422
|
+
readFileSync2(join(SESSIONS_DIR, f), "utf-8")
|
|
356
423
|
);
|
|
357
424
|
return { email: data.email, companyId: data.companyId, file: f };
|
|
358
425
|
} catch {
|