enhanced-printer 1.0.1 → 1.0.3

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 CHANGED
@@ -50,6 +50,16 @@ async function printPDF() {
50
50
  printPDF();
51
51
  ```
52
52
 
53
+ ## Available Methods
54
+
55
+ - `print()` - Print PDF with custom settings
56
+ - `getPrinters()` - Get list of available printers
57
+ - `getDefaultPrinter()` - Get default printer name
58
+ - `getJobs()` - Get all print jobs with custom names
59
+ - `getPrinterJobs()` - Get all print jobs (alias for getJobs)
60
+ - `getJobStatus()` - Get status of specific job by ID
61
+ - `cancelJob()` - Cancel a print job
62
+
53
63
  ## API Reference
54
64
 
55
65
  ### `print(options: PrintOptions): Promise<PrintResult>`
package/lib/index.d.ts CHANGED
@@ -10,5 +10,6 @@
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, cancelJob } from './print-manager';
13
+ export { print, getPrinters, getDefaultPrinter, getJobStatus, getPrinterJobs, getJobs, // New method for getting jobs with custom names
14
+ cancelJob } from './print-manager';
14
15
  export { PrintOptions, PrintResult, PrinterInfo, JobInfo } from './types';
package/lib/index.js CHANGED
@@ -12,11 +12,12 @@
12
12
  * - Query job status and printer information
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.cancelJob = exports.getPrinterJobs = exports.getJobStatus = exports.getDefaultPrinter = exports.getPrinters = exports.print = void 0;
15
+ exports.cancelJob = exports.getJobs = exports.getPrinterJobs = exports.getJobStatus = 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
20
  Object.defineProperty(exports, "getJobStatus", { enumerable: true, get: function () { return print_manager_1.getJobStatus; } });
21
21
  Object.defineProperty(exports, "getPrinterJobs", { enumerable: true, get: function () { return print_manager_1.getPrinterJobs; } });
22
+ Object.defineProperty(exports, "getJobs", { enumerable: true, get: function () { return print_manager_1.getJobs; } });
22
23
  Object.defineProperty(exports, "cancelJob", { enumerable: true, get: function () { return print_manager_1.cancelJob; } });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Job name mapping to track custom names
3
+ * Maps job ID to custom job name provided by user
4
+ */
5
+ /**
6
+ * Store custom job name mapping
7
+ */
8
+ export declare function storeJobName(printerName: string, jobId: number, customName: string): void;
9
+ /**
10
+ * Get custom job name for a job
11
+ */
12
+ export declare function getCustomJobName(printerName: string, jobId: number): string | null;
13
+ /**
14
+ * Clear all job name mappings
15
+ */
16
+ export declare function clearJobNames(): void;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * Job name mapping to track custom names
4
+ * Maps job ID to custom job name provided by user
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.storeJobName = storeJobName;
8
+ exports.getCustomJobName = getCustomJobName;
9
+ exports.clearJobNames = clearJobNames;
10
+ // In-memory storage for job name mappings
11
+ const jobNameMap = new Map();
12
+ // Max age for mappings (24 hours)
13
+ const MAX_MAPPING_AGE = 24 * 60 * 60 * 1000;
14
+ /**
15
+ * Store custom job name mapping
16
+ */
17
+ function storeJobName(printerName, jobId, customName) {
18
+ const key = `${printerName}_${jobId}`;
19
+ jobNameMap.set(key, {
20
+ jobId,
21
+ customName,
22
+ printerName,
23
+ timestamp: Date.now()
24
+ });
25
+ // Clean old entries
26
+ cleanOldMappings();
27
+ }
28
+ /**
29
+ * Get custom job name for a job
30
+ */
31
+ function getCustomJobName(printerName, jobId) {
32
+ const key = `${printerName}_${jobId}`;
33
+ const mapping = jobNameMap.get(key);
34
+ if (!mapping) {
35
+ return null;
36
+ }
37
+ // Check if mapping is too old
38
+ if (Date.now() - mapping.timestamp > MAX_MAPPING_AGE) {
39
+ jobNameMap.delete(key);
40
+ return null;
41
+ }
42
+ return mapping.customName;
43
+ }
44
+ /**
45
+ * Clean mappings older than MAX_MAPPING_AGE
46
+ */
47
+ function cleanOldMappings() {
48
+ const now = Date.now();
49
+ const keysToDelete = [];
50
+ jobNameMap.forEach((mapping, key) => {
51
+ if (now - mapping.timestamp > MAX_MAPPING_AGE) {
52
+ keysToDelete.push(key);
53
+ }
54
+ });
55
+ keysToDelete.forEach(key => jobNameMap.delete(key));
56
+ }
57
+ /**
58
+ * Clear all job name mappings
59
+ */
60
+ function clearJobNames() {
61
+ jobNameMap.clear();
62
+ }
@@ -8,6 +8,6 @@ export declare function getJobIdByName(printerName: string, jobName: string, max
8
8
  */
9
9
  export declare function getJobInfo(printerName: string, jobId: number): Promise<JobInfo | null>;
10
10
  /**
11
- * Gets all print jobs for a printer
11
+ * Gets all print jobs for a printer with enhanced details
12
12
  */
13
13
  export declare function getAllJobs(printerName: string): Promise<JobInfo[]>;
@@ -4,6 +4,7 @@ exports.getJobIdByName = getJobIdByName;
4
4
  exports.getJobInfo = getJobInfo;
5
5
  exports.getAllJobs = getAllJobs;
6
6
  const child_process_1 = require("child_process");
7
+ const job_name_mapper_1 = require("./job-name-mapper");
7
8
  /**
8
9
  * Retrieves job ID by document name using PowerShell
9
10
  */
@@ -27,7 +28,7 @@ async function getJobInfo(printerName, jobId) {
27
28
  const script = `
28
29
  Get-PrintJob -PrinterName "${escapePowerShellString(printerName)}" |
29
30
  Where-Object {$_.Id -eq ${jobId}} |
30
- Select-Object Id, DocumentName, JobStatus, TotalPages, Size |
31
+ Select-Object Id, DocumentName, JobStatus, TotalPages, Size, UserName, SubmittedTime |
31
32
  ConvertTo-Json
32
33
  `;
33
34
  try {
@@ -36,13 +37,18 @@ async function getJobInfo(printerName, jobId) {
36
37
  if (!result || !result.Id) {
37
38
  return null;
38
39
  }
40
+ // Get custom job name from mapper
41
+ const customName = (0, job_name_mapper_1.getCustomJobName)(printerName, result.Id);
39
42
  return {
40
43
  jobId: result.Id,
41
44
  jobName: result.DocumentName || '',
45
+ customJobName: customName || result.DocumentName || '', // Use custom name if available
42
46
  printerName: printerName,
43
47
  status: result.JobStatus || 'Unknown',
44
48
  pages: result.TotalPages || 0,
45
- size: result.Size
49
+ size: result.Size,
50
+ userName: result.UserName,
51
+ submittedTime: result.SubmittedTime
46
52
  };
47
53
  }
48
54
  catch (error) {
@@ -50,12 +56,12 @@ async function getJobInfo(printerName, jobId) {
50
56
  }
51
57
  }
52
58
  /**
53
- * Gets all print jobs for a printer
59
+ * Gets all print jobs for a printer with enhanced details
54
60
  */
55
61
  async function getAllJobs(printerName) {
56
62
  const script = `
57
63
  Get-PrintJob -PrinterName "${escapePowerShellString(printerName)}" |
58
- Select-Object Id, DocumentName, JobStatus, TotalPages, Size |
64
+ Select-Object Id, DocumentName, JobStatus, TotalPages, Size, UserName, SubmittedTime |
59
65
  ConvertTo-Json
60
66
  `;
61
67
  try {
@@ -63,14 +69,21 @@ async function getAllJobs(printerName) {
63
69
  const result = JSON.parse(output);
64
70
  // Handle single result vs array
65
71
  const jobs = Array.isArray(result) ? result : (result ? [result] : []);
66
- return jobs.map((job) => ({
67
- jobId: job.Id,
68
- jobName: job.DocumentName || '',
69
- printerName: printerName,
70
- status: job.JobStatus || 'Unknown',
71
- pages: job.TotalPages || 0,
72
- size: job.Size
73
- }));
72
+ return jobs.map((job) => {
73
+ // Get custom job name from mapper
74
+ const customName = (0, job_name_mapper_1.getCustomJobName)(printerName, job.Id);
75
+ return {
76
+ jobId: job.Id,
77
+ jobName: job.DocumentName || '',
78
+ customJobName: customName || job.DocumentName || '', // Use custom name if available
79
+ printerName: printerName,
80
+ status: job.JobStatus || 'Unknown',
81
+ pages: job.TotalPages || 0,
82
+ size: job.Size,
83
+ userName: job.UserName,
84
+ submittedTime: job.SubmittedTime
85
+ };
86
+ });
74
87
  }
75
88
  catch (error) {
76
89
  return [];
@@ -19,6 +19,11 @@ export declare function getJobStatus(printerName: string, jobId: number): Promis
19
19
  * Gets all print jobs for a specific printer
20
20
  */
21
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
+ export declare function getJobs(printerName: string): Promise<JobInfo[]>;
22
27
  /**
23
28
  * Cancels a print job
24
29
  */
@@ -5,11 +5,13 @@ exports.getPrinters = getPrinters;
5
5
  exports.getDefaultPrinter = getDefaultPrinter;
6
6
  exports.getJobStatus = getJobStatus;
7
7
  exports.getPrinterJobs = getPrinterJobs;
8
+ exports.getJobs = getJobs;
8
9
  exports.cancelJob = cancelJob;
9
10
  const pdf_to_printer_1 = require("pdf-to-printer");
10
11
  const uuid_1 = require("uuid");
11
12
  const child_process_1 = require("child_process");
12
13
  const job_tracker_1 = require("./job-tracker");
14
+ const job_name_mapper_1 = require("./job-name-mapper");
13
15
  /**
14
16
  * Prints a PDF file with the specified options
15
17
  */
@@ -63,11 +65,15 @@ async function print(options) {
63
65
  printOptions.subset = options.subset;
64
66
  }
65
67
  // Set the document name for job tracking
66
- printOptions.win32 = ['-print-settings', `${jobName}`];
68
+ printOptions.win32 = ['-print-settings', `${options.filePath}`];
67
69
  // Print the document
68
70
  await (0, pdf_to_printer_1.print)(options.filePath, printOptions);
69
71
  // Try to retrieve job ID
70
- const jobId = await (0, job_tracker_1.getJobIdByName)(options.printerName, jobName);
72
+ const jobId = await (0, job_tracker_1.getJobIdByName)(options.printerName, options.filePath);
73
+ // Store custom job name mapping if we got a job ID
74
+ if (jobId) {
75
+ (0, job_name_mapper_1.storeJobName)(options.printerName, jobId, jobName);
76
+ }
71
77
  return {
72
78
  success: true,
73
79
  jobId: jobId || undefined,
@@ -125,6 +131,13 @@ async function getJobStatus(printerName, jobId) {
125
131
  async function getPrinterJobs(printerName) {
126
132
  return (0, job_tracker_1.getAllJobs)(printerName);
127
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
+ async function getJobs(printerName) {
139
+ return (0, job_tracker_1.getAllJobs)(printerName);
140
+ }
128
141
  /**
129
142
  * Cancels a print job
130
143
  */
package/lib/types.d.ts CHANGED
@@ -62,8 +62,10 @@ export interface PrintResult {
62
62
  export interface JobInfo {
63
63
  /** Job ID in the print queue */
64
64
  jobId: number;
65
- /** Document name */
65
+ /** Document name from Windows (same as customJobName) */
66
66
  jobName: string;
67
+ /** Custom job name provided during print (same as jobName/DocumentName) */
68
+ customJobName: string;
67
69
  /** Name of the printer */
68
70
  printerName: string;
69
71
  /** Current status of the job */
@@ -72,4 +74,8 @@ export interface JobInfo {
72
74
  pages: number;
73
75
  /** Size in bytes */
74
76
  size?: number;
77
+ /** User who submitted the job */
78
+ userName?: string;
79
+ /** Time when job was submitted */
80
+ submittedTime?: string;
75
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enhanced-printer",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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",