enhanced-printer 1.0.3 → 1.0.4

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/lib/index.d.ts CHANGED
@@ -10,6 +10,5 @@
10
10
  * - Automatic use of printer defaults when settings not specified
11
11
  * - Query job status and printer information
12
12
  */
13
- export { print, getPrinters, getDefaultPrinter, getJobStatus, getPrinterJobs, getJobs, // New method for getting jobs with custom names
14
- cancelJob } from './print-manager';
13
+ export { print, getPrinters, getDefaultPrinter, getJobInfo, getJobs, cancelJob } from './print-manager';
15
14
  export { PrintOptions, PrintResult, PrinterInfo, JobInfo } from './types';
package/lib/index.js CHANGED
@@ -12,12 +12,11 @@
12
12
  * - Query job status and printer information
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.cancelJob = exports.getJobs = exports.getPrinterJobs = exports.getJobStatus = exports.getDefaultPrinter = exports.getPrinters = exports.print = void 0;
15
+ exports.cancelJob = exports.getJobs = exports.getJobInfo = exports.getDefaultPrinter = exports.getPrinters = exports.print = void 0;
16
16
  var print_manager_1 = require("./print-manager");
17
17
  Object.defineProperty(exports, "print", { enumerable: true, get: function () { return print_manager_1.print; } });
18
18
  Object.defineProperty(exports, "getPrinters", { enumerable: true, get: function () { return print_manager_1.getPrinters; } });
19
19
  Object.defineProperty(exports, "getDefaultPrinter", { enumerable: true, get: function () { return print_manager_1.getDefaultPrinter; } });
20
- Object.defineProperty(exports, "getJobStatus", { enumerable: true, get: function () { return print_manager_1.getJobStatus; } });
21
- Object.defineProperty(exports, "getPrinterJobs", { enumerable: true, get: function () { return print_manager_1.getPrinterJobs; } });
20
+ Object.defineProperty(exports, "getJobInfo", { enumerable: true, get: function () { return print_manager_1.getJobInfo; } });
22
21
  Object.defineProperty(exports, "getJobs", { enumerable: true, get: function () { return print_manager_1.getJobs; } });
23
22
  Object.defineProperty(exports, "cancelJob", { enumerable: true, get: function () { return print_manager_1.cancelJob; } });
@@ -10,6 +10,14 @@ export declare function storeJobName(printerName: string, jobId: number, customN
10
10
  * Get custom job name for a job
11
11
  */
12
12
  export declare function getCustomJobName(printerName: string, jobId: number): string | null;
13
+ /**
14
+ * Get system job ID from a custom job name (reverse lookup)
15
+ * Returns the jobId and printerName if found, null otherwise
16
+ */
17
+ export declare function getSystemJobId(customJobName: string, printerName?: string): {
18
+ jobId: number;
19
+ printerName: string;
20
+ } | null;
13
21
  /**
14
22
  * Clear all job name mappings
15
23
  */
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.storeJobName = storeJobName;
8
8
  exports.getCustomJobName = getCustomJobName;
9
+ exports.getSystemJobId = getSystemJobId;
9
10
  exports.clearJobNames = clearJobNames;
10
11
  // In-memory storage for job name mappings
11
12
  const jobNameMap = new Map();
@@ -41,6 +42,27 @@ function getCustomJobName(printerName, jobId) {
41
42
  }
42
43
  return mapping.customName;
43
44
  }
45
+ /**
46
+ * Get system job ID from a custom job name (reverse lookup)
47
+ * Returns the jobId and printerName if found, null otherwise
48
+ */
49
+ function getSystemJobId(customJobName, printerName) {
50
+ const now = Date.now();
51
+ for (const [key, mapping] of jobNameMap.entries()) {
52
+ // Skip expired mappings
53
+ if (now - mapping.timestamp > MAX_MAPPING_AGE) {
54
+ continue;
55
+ }
56
+ if (mapping.customName === customJobName) {
57
+ // If printerName is provided, match it too
58
+ if (printerName && mapping.printerName !== printerName) {
59
+ continue;
60
+ }
61
+ return { jobId: mapping.jobId, printerName: mapping.printerName };
62
+ }
63
+ }
64
+ return null;
65
+ }
44
66
  /**
45
67
  * Clean mappings older than MAX_MAPPING_AGE
46
68
  */
@@ -4,9 +4,14 @@ import { JobInfo } from './types';
4
4
  */
5
5
  export declare function getJobIdByName(printerName: string, jobName: string, maxRetries?: number, retryDelay?: number): Promise<number | null>;
6
6
  /**
7
- * Gets detailed information about a print job
7
+ * Gets detailed information about a print job using system job ID
8
8
  */
9
- export declare function getJobInfo(printerName: string, jobId: number): Promise<JobInfo | null>;
9
+ export declare function getJobInfoBySystemId(printerName: string, jobId: number): Promise<JobInfo | null>;
10
+ /**
11
+ * Gets detailed information about a print job using custom job name
12
+ * Resolves the custom job name to the system job ID, then queries the spooler
13
+ */
14
+ export declare function getJobInfo(customJobName: string, printerName?: string): Promise<JobInfo | null>;
10
15
  /**
11
16
  * Gets all print jobs for a printer with enhanced details
12
17
  */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getJobIdByName = getJobIdByName;
4
+ exports.getJobInfoBySystemId = getJobInfoBySystemId;
4
5
  exports.getJobInfo = getJobInfo;
5
6
  exports.getAllJobs = getAllJobs;
6
7
  const child_process_1 = require("child_process");
@@ -22,9 +23,9 @@ async function getJobIdByName(printerName, jobName, maxRetries = 3, retryDelay =
22
23
  return null;
23
24
  }
24
25
  /**
25
- * Gets detailed information about a print job
26
+ * Gets detailed information about a print job using system job ID
26
27
  */
27
- async function getJobInfo(printerName, jobId) {
28
+ async function getJobInfoBySystemId(printerName, jobId) {
28
29
  const script = `
29
30
  Get-PrintJob -PrinterName "${escapePowerShellString(printerName)}" |
30
31
  Where-Object {$_.Id -eq ${jobId}} |
@@ -42,7 +43,7 @@ async function getJobInfo(printerName, jobId) {
42
43
  return {
43
44
  jobId: result.Id,
44
45
  jobName: result.DocumentName || '',
45
- customJobName: customName || result.DocumentName || '', // Use custom name if available
46
+ customJobName: customName || result.DocumentName || '',
46
47
  printerName: printerName,
47
48
  status: result.JobStatus || 'Unknown',
48
49
  pages: result.TotalPages || 0,
@@ -55,6 +56,18 @@ async function getJobInfo(printerName, jobId) {
55
56
  return null;
56
57
  }
57
58
  }
59
+ /**
60
+ * Gets detailed information about a print job using custom job name
61
+ * Resolves the custom job name to the system job ID, then queries the spooler
62
+ */
63
+ async function getJobInfo(customJobName, printerName) {
64
+ // Resolve custom job name to system job ID
65
+ const mapping = (0, job_name_mapper_1.getSystemJobId)(customJobName, printerName);
66
+ if (!mapping) {
67
+ return null;
68
+ }
69
+ return getJobInfoBySystemId(mapping.printerName, mapping.jobId);
70
+ }
58
71
  /**
59
72
  * Gets all print jobs for a printer with enhanced details
60
73
  */
@@ -12,19 +12,14 @@ export declare function getPrinters(): Promise<PrinterInfo[]>;
12
12
  */
13
13
  export declare function getDefaultPrinter(): Promise<string | null>;
14
14
  /**
15
- * Gets information about a specific print job
15
+ * Gets detailed information about a print job using custom job name
16
16
  */
17
- export declare function getJobStatus(printerName: string, jobId: number): Promise<JobInfo | null>;
17
+ export declare function getJobInfo(customJobName: string, printerName?: string): Promise<JobInfo | null>;
18
18
  /**
19
19
  * Gets all print jobs for a specific printer
20
20
  */
21
- export declare function getPrinterJobs(printerName: string): Promise<JobInfo[]>;
22
- /**
23
- * Gets all print jobs with custom job names for a specific printer
24
- * This is an alias for getPrinterJobs with clearer intent
25
- */
26
21
  export declare function getJobs(printerName: string): Promise<JobInfo[]>;
27
22
  /**
28
- * Cancels a print job
23
+ * Cancels a print job using custom job name
29
24
  */
30
- export declare function cancelJob(printerName: string, jobId: number): Promise<boolean>;
25
+ export declare function cancelJob(customJobName: string, printerName?: string): Promise<boolean>;
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.print = print;
4
4
  exports.getPrinters = getPrinters;
5
5
  exports.getDefaultPrinter = getDefaultPrinter;
6
- exports.getJobStatus = getJobStatus;
7
- exports.getPrinterJobs = getPrinterJobs;
6
+ exports.getJobInfo = getJobInfo;
8
7
  exports.getJobs = getJobs;
9
8
  exports.cancelJob = cancelJob;
10
9
  const pdf_to_printer_1 = require("pdf-to-printer");
@@ -120,30 +119,28 @@ async function getDefaultPrinter() {
120
119
  return defaultPrinter ? defaultPrinter.name : null;
121
120
  }
122
121
  /**
123
- * Gets information about a specific print job
122
+ * Gets detailed information about a print job using custom job name
124
123
  */
125
- async function getJobStatus(printerName, jobId) {
126
- return (0, job_tracker_1.getJobInfo)(printerName, jobId);
124
+ async function getJobInfo(customJobName, printerName) {
125
+ return (0, job_tracker_1.getJobInfo)(customJobName, printerName);
127
126
  }
128
127
  /**
129
128
  * Gets all print jobs for a specific printer
130
129
  */
131
- async function getPrinterJobs(printerName) {
132
- return (0, job_tracker_1.getAllJobs)(printerName);
133
- }
134
- /**
135
- * Gets all print jobs with custom job names for a specific printer
136
- * This is an alias for getPrinterJobs with clearer intent
137
- */
138
130
  async function getJobs(printerName) {
139
131
  return (0, job_tracker_1.getAllJobs)(printerName);
140
132
  }
141
133
  /**
142
- * Cancels a print job
134
+ * Cancels a print job using custom job name
143
135
  */
144
- async function cancelJob(printerName, jobId) {
136
+ async function cancelJob(customJobName, printerName) {
137
+ // Resolve custom job name to system job ID
138
+ const mapping = (0, job_name_mapper_1.getSystemJobId)(customJobName, printerName);
139
+ if (!mapping) {
140
+ return false;
141
+ }
145
142
  const script = `
146
- Remove-PrintJob -PrinterName "${escapePowerShellString(printerName)}" -ID ${jobId}
143
+ Remove-PrintJob -PrinterName "${escapePowerShellString(mapping.printerName)}" -ID ${mapping.jobId}
147
144
  `;
148
145
  try {
149
146
  await executePowerShell(script);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enhanced-printer",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Advanced PDF printing library with job tracking, custom page sizes, and tray selection for Node.js and Electron",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",