@botler/1403-form-filler-module 1.0.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 +203 -0
- package/dist/canvasser-data-mapper.d.ts +110 -0
- package/dist/canvasser-data-mapper.d.ts.map +1 -0
- package/dist/canvasser-data-mapper.js +259 -0
- package/dist/canvasser-data-mapper.js.map +1 -0
- package/dist/cli.d.ts +14 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +127 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +58 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +297 -0
- package/dist/config.js.map +1 -0
- package/dist/db/index.d.ts +6 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +17 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/pool.d.ts +34 -0
- package/dist/db/pool.d.ts.map +1 -0
- package/dist/db/pool.js +67 -0
- package/dist/db/pool.js.map +1 -0
- package/dist/db/queries.d.ts +56 -0
- package/dist/db/queries.d.ts.map +1 -0
- package/dist/db/queries.js +192 -0
- package/dist/db/queries.js.map +1 -0
- package/dist/form-filler.d.ts +64 -0
- package/dist/form-filler.d.ts.map +1 -0
- package/dist/form-filler.js +328 -0
- package/dist/form-filler.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/pdf-converter/converter.d.ts +77 -0
- package/dist/pdf-converter/converter.d.ts.map +1 -0
- package/dist/pdf-converter/converter.js +277 -0
- package/dist/pdf-converter/converter.js.map +1 -0
- package/dist/pdf-converter/index.d.ts +7 -0
- package/dist/pdf-converter/index.d.ts.map +1 -0
- package/dist/pdf-converter/index.js +11 -0
- package/dist/pdf-converter/index.js.map +1 -0
- package/dist/pdf-converter/types.d.ts +82 -0
- package/dist/pdf-converter/types.d.ts.map +1 -0
- package/dist/pdf-converter/types.js +16 -0
- package/dist/pdf-converter/types.js.map +1 -0
- package/dist/pdf-filler/fieldMapper.d.ts +48 -0
- package/dist/pdf-filler/fieldMapper.d.ts.map +1 -0
- package/dist/pdf-filler/fieldMapper.js +128 -0
- package/dist/pdf-filler/fieldMapper.js.map +1 -0
- package/dist/pdf-filler/file-sources/base.d.ts +42 -0
- package/dist/pdf-filler/file-sources/base.d.ts.map +1 -0
- package/dist/pdf-filler/file-sources/base.js +9 -0
- package/dist/pdf-filler/file-sources/base.js.map +1 -0
- package/dist/pdf-filler/file-sources/index.d.ts +9 -0
- package/dist/pdf-filler/file-sources/index.d.ts.map +1 -0
- package/dist/pdf-filler/file-sources/index.js +8 -0
- package/dist/pdf-filler/file-sources/index.js.map +1 -0
- package/dist/pdf-filler/file-sources/local-file-source.d.ts +56 -0
- package/dist/pdf-filler/file-sources/local-file-source.d.ts.map +1 -0
- package/dist/pdf-filler/file-sources/local-file-source.js +133 -0
- package/dist/pdf-filler/file-sources/local-file-source.js.map +1 -0
- package/dist/pdf-filler/file-sources/s3-file-source.d.ts +63 -0
- package/dist/pdf-filler/file-sources/s3-file-source.d.ts.map +1 -0
- package/dist/pdf-filler/file-sources/s3-file-source.js +141 -0
- package/dist/pdf-filler/file-sources/s3-file-source.js.map +1 -0
- package/dist/pdf-filler/filler.d.ts +60 -0
- package/dist/pdf-filler/filler.d.ts.map +1 -0
- package/dist/pdf-filler/filler.js +156 -0
- package/dist/pdf-filler/filler.js.map +1 -0
- package/dist/pdf-filler/index.d.ts +16 -0
- package/dist/pdf-filler/index.d.ts.map +1 -0
- package/dist/pdf-filler/index.js +25 -0
- package/dist/pdf-filler/index.js.map +1 -0
- package/dist/pdf-filler/pdfFormFiller.d.ts +95 -0
- package/dist/pdf-filler/pdfFormFiller.d.ts.map +1 -0
- package/dist/pdf-filler/pdfFormFiller.js +352 -0
- package/dist/pdf-filler/pdfFormFiller.js.map +1 -0
- package/dist/pdf-filler/types.d.ts +68 -0
- package/dist/pdf-filler/types.d.ts.map +1 -0
- package/dist/pdf-filler/types.js +10 -0
- package/dist/pdf-filler/types.js.map +1 -0
- package/dist/pdf-filler/utils/path-detector.d.ts +58 -0
- package/dist/pdf-filler/utils/path-detector.d.ts.map +1 -0
- package/dist/pdf-filler/utils/path-detector.js +124 -0
- package/dist/pdf-filler/utils/path-detector.js.map +1 -0
- package/dist/pdf-filler/vercelOGSignatureGenerator.d.ts +41 -0
- package/dist/pdf-filler/vercelOGSignatureGenerator.d.ts.map +1 -0
- package/dist/pdf-filler/vercelOGSignatureGenerator.js +146 -0
- package/dist/pdf-filler/vercelOGSignatureGenerator.js.map +1 -0
- package/dist/pdf-merger/index.d.ts +6 -0
- package/dist/pdf-merger/index.d.ts.map +1 -0
- package/dist/pdf-merger/index.js +9 -0
- package/dist/pdf-merger/index.js.map +1 -0
- package/dist/pdf-merger/merger.d.ts +25 -0
- package/dist/pdf-merger/merger.d.ts.map +1 -0
- package/dist/pdf-merger/merger.js +92 -0
- package/dist/pdf-merger/merger.js.map +1 -0
- package/dist/pdf-merger/types.d.ts +24 -0
- package/dist/pdf-merger/types.d.ts.map +1 -0
- package/dist/pdf-merger/types.js +9 -0
- package/dist/pdf-merger/types.js.map +1 -0
- package/dist/s3/index.d.ts +6 -0
- package/dist/s3/index.d.ts.map +1 -0
- package/dist/s3/index.js +9 -0
- package/dist/s3/index.js.map +1 -0
- package/dist/s3/types.d.ts +45 -0
- package/dist/s3/types.d.ts.map +1 -0
- package/dist/s3/types.js +9 -0
- package/dist/s3/types.js.map +1 -0
- package/dist/s3/uploader.d.ts +47 -0
- package/dist/s3/uploader.d.ts.map +1 -0
- package/dist/s3/uploader.js +112 -0
- package/dist/s3/uploader.js.map +1 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +10 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/logger.d.ts +59 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/logger.js +155 -0
- package/dist/shared/logger.js.map +1 -0
- package/dist/types/canvasser-profile.d.ts +38 -0
- package/dist/types/canvasser-profile.d.ts.map +1 -0
- package/dist/types/canvasser-profile.js +11 -0
- package/dist/types/canvasser-profile.js.map +1 -0
- package/dist/types/config.d.ts +137 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +9 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/db-tables.d.ts +143 -0
- package/dist/types/db-tables.d.ts.map +1 -0
- package/dist/types/db-tables.js +53 -0
- package/dist/types/db-tables.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +26 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -0
- package/templates/README.md +19 -0
- package/templates/template.pdf +0 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* cli.ts — CLI entry point for the 1403 form-filler-module
|
|
5
|
+
*
|
|
6
|
+
* Parses CLI arguments, loads environment variables via dotenv,
|
|
7
|
+
* creates a FormFiller instance, and dispatches to the correct mode.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* npx tsx src/cli.ts --id <userId>
|
|
11
|
+
* npx tsx src/cli.ts --ids <id1,id2,...>
|
|
12
|
+
* npx tsx src/cli.ts --all
|
|
13
|
+
*/
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
19
|
+
dotenv_1.default.config();
|
|
20
|
+
const logger_1 = require("./shared/logger");
|
|
21
|
+
const config_1 = require("./config");
|
|
22
|
+
const form_filler_1 = require("./form-filler");
|
|
23
|
+
// Configure logging
|
|
24
|
+
logger_1.logger.setLogLevel(logger_1.LogLevel.INFO);
|
|
25
|
+
/**
|
|
26
|
+
* Main CLI execution.
|
|
27
|
+
* Parses CLI arguments, creates the orchestrator, and runs it.
|
|
28
|
+
*/
|
|
29
|
+
async function main() {
|
|
30
|
+
try {
|
|
31
|
+
const args = process.argv.slice(2);
|
|
32
|
+
const config = config_1.Config.parseArgs(args);
|
|
33
|
+
logger_1.logger.info("🚀 Starting canvasser form filling process...");
|
|
34
|
+
if (config.dryRun) {
|
|
35
|
+
logger_1.logger.info("🧪 DRY RUN MODE — No PDFs will be generated");
|
|
36
|
+
}
|
|
37
|
+
// Validate template and output directory
|
|
38
|
+
await config_1.Config.validateConfig(config);
|
|
39
|
+
logger_1.logger.info(`📁 Template: ${config.templatePath} ✓`);
|
|
40
|
+
logger_1.logger.info(`📁 Output directory: ${config.outputDirectory} ✓`);
|
|
41
|
+
// Create the library-level FormFiller with CLI-derived settings
|
|
42
|
+
const formFiller = new form_filler_1.FormFiller({
|
|
43
|
+
templatePath: config.templatePath,
|
|
44
|
+
outputDirectory: config.outputDirectory,
|
|
45
|
+
batchSize: config.batchSize,
|
|
46
|
+
dryRun: config.dryRun,
|
|
47
|
+
skipExisting: config.skipExisting,
|
|
48
|
+
keepTemp: config.keepTemp,
|
|
49
|
+
});
|
|
50
|
+
logger_1.logger.info("🔗 Database pool initialised ✓");
|
|
51
|
+
let results = [];
|
|
52
|
+
if (config.userId) {
|
|
53
|
+
logger_1.logger.info(`🚀 Processing user ID: ${config.userId}`);
|
|
54
|
+
const result = await formFiller.fillForUser(config.userId);
|
|
55
|
+
results = [result];
|
|
56
|
+
logResult(result);
|
|
57
|
+
}
|
|
58
|
+
else if (config.userIds) {
|
|
59
|
+
logger_1.logger.info(`🚀 Processing ${config.userIds.length} user IDs`);
|
|
60
|
+
results = await formFiller.fillForUsers(config.userIds);
|
|
61
|
+
for (const r of results)
|
|
62
|
+
logResult(r);
|
|
63
|
+
}
|
|
64
|
+
else if (config.processAll) {
|
|
65
|
+
results = await formFiller.fillAll();
|
|
66
|
+
}
|
|
67
|
+
// Report summary
|
|
68
|
+
reportFinalResults(results, config);
|
|
69
|
+
await formFiller.destroy();
|
|
70
|
+
logger_1.logger.info("🔌 Database pool closed");
|
|
71
|
+
process.exit(0);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
75
|
+
logger_1.logger.error(`Fatal error: ${message}`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Log a single processing result. */
|
|
80
|
+
function logResult(result) {
|
|
81
|
+
if (result.success) {
|
|
82
|
+
if (result.skipped) {
|
|
83
|
+
logger_1.logger.info(`⏭️ Skipped: ${result.userId} — ${result.reason}`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
logger_1.logger.info(`✅ Generated: ${result.userId}.pdf`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
logger_1.logger.error(`❌ Failed: ${result.userId} — ${result.error}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Print a summary of all processing results. */
|
|
94
|
+
function reportFinalResults(results, config) {
|
|
95
|
+
const successful = results.filter((r) => r.success && !r.skipped).length;
|
|
96
|
+
const failed = results.filter((r) => !r.success).length;
|
|
97
|
+
const skipped = results.filter((r) => r.success && r.skipped).length;
|
|
98
|
+
logger_1.logger.info("\n📈 Summary:");
|
|
99
|
+
if (config.userId && results.length === 1) {
|
|
100
|
+
const r = results[0];
|
|
101
|
+
if (r) {
|
|
102
|
+
logger_1.logger.info(` User ID: ${r.userId}`);
|
|
103
|
+
logger_1.logger.info(` Status: ${r.success ? (r.skipped ? "Skipped" : "Success") : "Failed"}`);
|
|
104
|
+
if (r.outputPath)
|
|
105
|
+
logger_1.logger.info(` Output: ${r.outputPath}`);
|
|
106
|
+
if (r.error)
|
|
107
|
+
logger_1.logger.info(` Error: ${r.error}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
logger_1.logger.info(` Total records: ${results.length}`);
|
|
112
|
+
logger_1.logger.info(` Successful: ${successful}`);
|
|
113
|
+
logger_1.logger.info(` Failed: ${failed}`);
|
|
114
|
+
logger_1.logger.info(` Skipped: ${skipped}`);
|
|
115
|
+
}
|
|
116
|
+
if (failed > 0) {
|
|
117
|
+
logger_1.logger.info("\n❌ Failed records:");
|
|
118
|
+
for (const r of results.filter((r) => !r.success)) {
|
|
119
|
+
logger_1.logger.info(` User ${r.userId}: ${r.error}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Run when executed directly
|
|
124
|
+
if (require.main === module) {
|
|
125
|
+
main().catch(console.error);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;GAUG;;;;;AAEH,oDAA4B;AAC5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,4CAAmD;AACnD,qCAAkC;AAClC,+CAA2C;AAG3C,oBAAoB;AACpB,eAAM,CAAC,WAAW,CAAC,iBAAQ,CAAC,IAAI,CAAC,CAAC;AAElC;;;GAGG;AACH,KAAK,UAAU,IAAI;IAChB,IAAI,CAAC;QACF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,eAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAEtC,eAAM,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;QAE7D,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YACjB,eAAM,C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IAAI,CAAC,aAAa,MAAM,EAAE,CAAC,CAAC;QACnC,eAAM,CAAC,IAAI,CAAC,cAAc,OAAO,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACd,eAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QACnC,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;YACjD,eAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,CAAC;IACJ,CAAC;AACJ,CAAC;AAED,6BAA6B;AAC7B,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC3B,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config.ts - Configuration and CLI parsing for form-filler-module
|
|
3
|
+
*
|
|
4
|
+
* Handles command-line argument parsing, default configuration,
|
|
5
|
+
* and validation of file paths and directories.
|
|
6
|
+
*/
|
|
7
|
+
import type { ScriptConfig } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Static utility class for CLI parsing, configuration, and validation.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Config {
|
|
12
|
+
/** Default configuration values for all non-mode-specific options */
|
|
13
|
+
private static readonly DEFAULT_CONFIG;
|
|
14
|
+
/**
|
|
15
|
+
* Parse CLI arguments and build a ScriptConfig.
|
|
16
|
+
*
|
|
17
|
+
* @param args - Raw process.argv.slice(2) arguments
|
|
18
|
+
* @returns A fully-resolved ScriptConfig
|
|
19
|
+
* @throws Error if no processing mode (--id, --ids, --all) is specified
|
|
20
|
+
*/
|
|
21
|
+
static parseArgs(args: string[]): ScriptConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Validate configuration and environment (template exists, output dir writable).
|
|
24
|
+
*
|
|
25
|
+
* @param config - The ScriptConfig to validate
|
|
26
|
+
* @throws Error if template is missing/unreadable or output dir cannot be created
|
|
27
|
+
*/
|
|
28
|
+
static validateConfig(config: ScriptConfig): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Generate output file path for a user ID.
|
|
31
|
+
*
|
|
32
|
+
* @param config - The ScriptConfig containing outputDirectory
|
|
33
|
+
* @param userId - The user ID used as the filename stem
|
|
34
|
+
* @returns Absolute path to the output PDF
|
|
35
|
+
*/
|
|
36
|
+
static getOutputPath(config: ScriptConfig, userId: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Check if an output file already exists for a user ID.
|
|
39
|
+
*
|
|
40
|
+
* @param config - The ScriptConfig containing outputDirectory
|
|
41
|
+
* @param userId - The user ID to check
|
|
42
|
+
* @returns True if the output PDF already exists
|
|
43
|
+
*/
|
|
44
|
+
static outputExists(config: ScriptConfig, userId: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Parse CLI arguments into key-value pairs.
|
|
47
|
+
* Supports --key=value, --key value, and boolean flags.
|
|
48
|
+
*
|
|
49
|
+
* @param args - Raw CLI argument strings
|
|
50
|
+
* @returns Parsed CLIArgs object
|
|
51
|
+
*/
|
|
52
|
+
private static parseCliArgs;
|
|
53
|
+
/**
|
|
54
|
+
* Print CLI help information and usage examples.
|
|
55
|
+
*/
|
|
56
|
+
private static showHelp;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAW,MAAM,SAAS,CAAC;AAErD;;GAEG;AACH,qBAAa,MAAM;IAChB,qEAAqE;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAYpC;IAEF;;;;;;OAMG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,YAAY;IAyErD;;;;;OAKG;WACiB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA2CvE;;;;;;OAMG;WACW,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAIzE;;;;;;OAMG;WACW,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAKzE;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;IAkD3B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ;CAmDzB"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* config.ts - Configuration and CLI parsing for form-filler-module
|
|
4
|
+
*
|
|
5
|
+
* Handles command-line argument parsing, default configuration,
|
|
6
|
+
* and validation of file paths and directories.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.Config = void 0;
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
|
+
const path = __importStar(require("node:path"));
|
|
45
|
+
/**
|
|
46
|
+
* Static utility class for CLI parsing, configuration, and validation.
|
|
47
|
+
*/
|
|
48
|
+
class Config {
|
|
49
|
+
/** Default configuration values for all non-mode-specific options */
|
|
50
|
+
static DEFAULT_CONFIG = {
|
|
51
|
+
templatePath: path.resolve(process.cwd(), "templates/template.pdf"),
|
|
52
|
+
outputDirectory: path.resolve(process.cwd(), "temp/filled-forms"),
|
|
53
|
+
batchSize: 10,
|
|
54
|
+
dryRun: false,
|
|
55
|
+
skipExisting: true,
|
|
56
|
+
maxRetries: 3,
|
|
57
|
+
retryDelay: 1000,
|
|
58
|
+
keepTemp: false,
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Parse CLI arguments and build a ScriptConfig.
|
|
62
|
+
*
|
|
63
|
+
* @param args - Raw process.argv.slice(2) arguments
|
|
64
|
+
* @returns A fully-resolved ScriptConfig
|
|
65
|
+
* @throws Error if no processing mode (--id, --ids, --all) is specified
|
|
66
|
+
*/
|
|
67
|
+
static parseArgs(args) {
|
|
68
|
+
const parsedArgs = this.parseCliArgs(args);
|
|
69
|
+
// Show help and exit if requested
|
|
70
|
+
if (parsedArgs.help) {
|
|
71
|
+
this.showHelp();
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
const config = {
|
|
75
|
+
...this.DEFAULT_CONFIG,
|
|
76
|
+
dryRun: parsedArgs.dryRun || parsedArgs["dry-run"] || false,
|
|
77
|
+
skipExisting: parsedArgs.skipExisting || parsedArgs["skip-existing"] || true,
|
|
78
|
+
batchSize: parsedArgs.batchSize
|
|
79
|
+
? parseInt(parsedArgs["batch-size"] || parsedArgs.batchSize)
|
|
80
|
+
: 10,
|
|
81
|
+
keepTemp: parsedArgs.keepTemp || parsedArgs["keep-temp"] || false,
|
|
82
|
+
};
|
|
83
|
+
// Determine processing mode from CLI arguments
|
|
84
|
+
if (parsedArgs.id) {
|
|
85
|
+
// Single user mode
|
|
86
|
+
const id = parsedArgs.id.trim();
|
|
87
|
+
if (!id || id.length === 0) {
|
|
88
|
+
throw new Error(`Invalid user ID: ${parsedArgs.id}. Must be a non-empty string.`);
|
|
89
|
+
}
|
|
90
|
+
config.userId = id;
|
|
91
|
+
}
|
|
92
|
+
else if (parsedArgs.ids) {
|
|
93
|
+
// Multiple users mode
|
|
94
|
+
const ids = parsedArgs.ids
|
|
95
|
+
.split(",")
|
|
96
|
+
.map((id) => id.trim())
|
|
97
|
+
.filter((id) => id.length > 0);
|
|
98
|
+
if (ids.length === 0) {
|
|
99
|
+
throw new Error("No valid user IDs provided. IDs must be non-empty strings.");
|
|
100
|
+
}
|
|
101
|
+
config.userIds = ids;
|
|
102
|
+
}
|
|
103
|
+
else if (parsedArgs.all) {
|
|
104
|
+
// Batch mode — process all users from open EA submission batches
|
|
105
|
+
config.processAll = true;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// No mode specified — show helpful error
|
|
109
|
+
const providedArgs = Object.keys(parsedArgs);
|
|
110
|
+
let errorMessage = "Must specify either --id, --ids, or --all. Use --help for usage information.";
|
|
111
|
+
if (providedArgs.length === 0) {
|
|
112
|
+
errorMessage += "\n\nNo arguments provided. Available options:\n";
|
|
113
|
+
errorMessage += " --id=<ID> Process single user\n";
|
|
114
|
+
errorMessage +=
|
|
115
|
+
" --ids=<IDs> Process multiple users (comma-separated)\n";
|
|
116
|
+
errorMessage +=
|
|
117
|
+
" --all Process all users from open EA batches\n";
|
|
118
|
+
errorMessage += " --help Show help information";
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
errorMessage += `\n\nReceived arguments: ${providedArgs.join(", ")}`;
|
|
122
|
+
errorMessage +=
|
|
123
|
+
"\nMake sure to use proper format: --id=value or --ids=value1,value2";
|
|
124
|
+
}
|
|
125
|
+
throw new Error(errorMessage);
|
|
126
|
+
}
|
|
127
|
+
return config;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Validate configuration and environment (template exists, output dir writable).
|
|
131
|
+
*
|
|
132
|
+
* @param config - The ScriptConfig to validate
|
|
133
|
+
* @throws Error if template is missing/unreadable or output dir cannot be created
|
|
134
|
+
*/
|
|
135
|
+
static async validateConfig(config) {
|
|
136
|
+
// Check template file exists
|
|
137
|
+
if (!fs.existsSync(config.templatePath)) {
|
|
138
|
+
throw new Error(`Template file not found: ${config.templatePath}`);
|
|
139
|
+
}
|
|
140
|
+
// Check template is readable
|
|
141
|
+
try {
|
|
142
|
+
await fs.promises.access(config.templatePath, fs.constants.R_OK);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
throw new Error(`Template file is not readable: ${config.templatePath}`);
|
|
146
|
+
}
|
|
147
|
+
// Ensure output directory exists
|
|
148
|
+
if (!fs.existsSync(config.outputDirectory)) {
|
|
149
|
+
try {
|
|
150
|
+
await fs.promises.mkdir(config.outputDirectory, {
|
|
151
|
+
recursive: true,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
throw new Error(`Failed to create output directory: ${config.outputDirectory}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Check output directory is writable
|
|
159
|
+
try {
|
|
160
|
+
await fs.promises.access(config.outputDirectory, fs.constants.W_OK);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
throw new Error(`Output directory is not writable: ${config.outputDirectory}`);
|
|
164
|
+
}
|
|
165
|
+
// Validate batch size range
|
|
166
|
+
if (config.batchSize <= 0 || config.batchSize > 100) {
|
|
167
|
+
throw new Error("Batch size must be between 1 and 100");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Generate output file path for a user ID.
|
|
172
|
+
*
|
|
173
|
+
* @param config - The ScriptConfig containing outputDirectory
|
|
174
|
+
* @param userId - The user ID used as the filename stem
|
|
175
|
+
* @returns Absolute path to the output PDF
|
|
176
|
+
*/
|
|
177
|
+
static getOutputPath(config, userId) {
|
|
178
|
+
return path.join(config.outputDirectory, `${userId}.pdf`);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Check if an output file already exists for a user ID.
|
|
182
|
+
*
|
|
183
|
+
* @param config - The ScriptConfig containing outputDirectory
|
|
184
|
+
* @param userId - The user ID to check
|
|
185
|
+
* @returns True if the output PDF already exists
|
|
186
|
+
*/
|
|
187
|
+
static outputExists(config, userId) {
|
|
188
|
+
const outputPath = this.getOutputPath(config, userId);
|
|
189
|
+
return fs.existsSync(outputPath);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Parse CLI arguments into key-value pairs.
|
|
193
|
+
* Supports --key=value, --key value, and boolean flags.
|
|
194
|
+
*
|
|
195
|
+
* @param args - Raw CLI argument strings
|
|
196
|
+
* @returns Parsed CLIArgs object
|
|
197
|
+
*/
|
|
198
|
+
static parseCliArgs(args) {
|
|
199
|
+
const result = {};
|
|
200
|
+
for (let i = 0; i < args.length; i++) {
|
|
201
|
+
const arg = args[i];
|
|
202
|
+
// Handle --key=value format
|
|
203
|
+
if (arg.startsWith("--") && arg.includes("=")) {
|
|
204
|
+
const [key, ...valueParts] = arg.slice(2).split("=");
|
|
205
|
+
const value = valueParts.join("="); // Rejoin in case value contains =
|
|
206
|
+
result[key] = value;
|
|
207
|
+
}
|
|
208
|
+
// Handle --key value format
|
|
209
|
+
else if (arg.startsWith("--")) {
|
|
210
|
+
const key = arg.slice(2);
|
|
211
|
+
const nextArg = args[i + 1];
|
|
212
|
+
// Boolean flags (no value expected)
|
|
213
|
+
if ([
|
|
214
|
+
"help",
|
|
215
|
+
"all",
|
|
216
|
+
"dry-run",
|
|
217
|
+
"skip-existing",
|
|
218
|
+
"keep-temp",
|
|
219
|
+
].includes(key)) {
|
|
220
|
+
result[key] = true;
|
|
221
|
+
}
|
|
222
|
+
// Value flags (consume next argument)
|
|
223
|
+
else if (nextArg && !nextArg.startsWith("--")) {
|
|
224
|
+
result[key] = nextArg;
|
|
225
|
+
i++; // Skip next argument as it has been consumed
|
|
226
|
+
}
|
|
227
|
+
// Fallback to boolean
|
|
228
|
+
else {
|
|
229
|
+
result[key] = true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Handle key=value format (without --)
|
|
233
|
+
else if (arg.includes("=")) {
|
|
234
|
+
const [key, ...valueParts] = arg.split("=");
|
|
235
|
+
const value = valueParts.join("=");
|
|
236
|
+
result[key] = value;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Print CLI help information and usage examples.
|
|
243
|
+
*/
|
|
244
|
+
static showHelp() {
|
|
245
|
+
console.log(`
|
|
246
|
+
🔧 Fill Canvasser 1403 Form Generator
|
|
247
|
+
|
|
248
|
+
USAGE:
|
|
249
|
+
npx tsx src/index.ts [OPTIONS]
|
|
250
|
+
|
|
251
|
+
OPTIONS:
|
|
252
|
+
--id <userId> Process single user by ID
|
|
253
|
+
--id=<userId> Alternative format
|
|
254
|
+
--ids <id1,id2,id3> Process multiple users by comma-separated IDs
|
|
255
|
+
--ids=<id1,id2,id3> Alternative format
|
|
256
|
+
--all Process all users from open EA submission batches
|
|
257
|
+
--dry-run Show what would be processed without generating PDFs
|
|
258
|
+
--skip-existing Skip users with existing PDF files (default: true)
|
|
259
|
+
--batch-size <N> Number of records to process in each batch (default: 10)
|
|
260
|
+
--keep-temp Keep per-user PDF files after batch merge + S3 upload
|
|
261
|
+
--help Show this help message
|
|
262
|
+
|
|
263
|
+
ENVIRONMENT:
|
|
264
|
+
TEAM_DATABASE_URL Neon PostgreSQL connection string (required)
|
|
265
|
+
|
|
266
|
+
EXAMPLES:
|
|
267
|
+
# Generate form for a specific user
|
|
268
|
+
npx tsx src/index.ts --id=abc123
|
|
269
|
+
|
|
270
|
+
# Generate forms for multiple users
|
|
271
|
+
npx tsx src/index.ts --ids=abc,def,ghi
|
|
272
|
+
|
|
273
|
+
# Dry-run all open EA submission batches
|
|
274
|
+
npx tsx src/index.ts --all --dry-run
|
|
275
|
+
|
|
276
|
+
# Process all with custom batch size
|
|
277
|
+
npx tsx src/index.ts --all --batch-size=20
|
|
278
|
+
|
|
279
|
+
FILES:
|
|
280
|
+
Template: templates/template.pdf
|
|
281
|
+
Output: temp/filled-forms/{userId}.pdf
|
|
282
|
+
|
|
283
|
+
DATA FLOW:
|
|
284
|
+
1. Fetches open batches from ea_submission_batches (--all mode)
|
|
285
|
+
2. Sets batch status to SUBMITTING
|
|
286
|
+
3. Joins ea_submissions → profile_reviews to get userId per submission
|
|
287
|
+
4. Builds canvasser profile from user_profiles + form_1403_signatures + addresses
|
|
288
|
+
5. Maps profile to PDF form fields and generates signed, flattened PDF
|
|
289
|
+
6. Merges all per-user PDFs in the batch into a single document
|
|
290
|
+
7. Uploads merged PDF to S3 (batches/1403/{batchId}.pdf)
|
|
291
|
+
8. Sets batch status to COMPLETED with s3Key (or FAILED on error)
|
|
292
|
+
9. Deletes per-user temp files (unless --keep-temp)
|
|
293
|
+
`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.Config = Config;
|
|
297
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAA8B;AAC9B,gDAAkC;AAGlC;;GAEG;AACH,MAAa,MAAM;IAChB,qEAAqE;IAC7D,MAAM,CAAU,cAAc,GAGlC;QACD,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,wBAAwB,CAAC;QACnE,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,mBAAmB,CAAC;QACjE,SAAS,EAAE,EAAE;QACb,MAAM,EAAE,KAAK;QACb,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,KAAK;KACjB,CAAC;IAEF;;;;;;OAMG;IACI,MAAM,CAAC,SAAS,CAAC,IAAc;QACnC,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAE3C,kCAAkC;QAClC,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACnB,CAAC;QAED,MAAM,MAAM,GAAiB;YAC1B,GAAG,IAAI,CAAC,cAAc;YACtB,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,KAAK;YAC3D,YAAY,EACT,UAAU,CAAC,YAAY,IAAI,UAAU,CAAC,eAAe,CAAC,IAAI,IAAI;YACjE,SAAS,EAAE,UAAU,CAAC,SAAS;g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,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC5C,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACnC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACvB,CAAC;QACJ,CAAC;QAED,OAAO,MAAiB,CAAC;IAC5B,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,QAAQ;QACpB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDjB,CAAC,CAAC;IACA,CAAC;;AAtRJ,wBAuRC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* db/index.ts — Barrel export for the database module
|
|
3
|
+
*/
|
|
4
|
+
export { getPool, setPool, closePool } from "./pool";
|
|
5
|
+
export { getOpenBatches, getSubmissionsWithUserIds, getCanvasserProfile, updateBatchStatus, updateBatchS3Key, } from "./queries";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,EACJ,cAAc,EACd,yBAAyB,EACzB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,GAClB,MAAM,WAAW,CAAC"}
|
package/dist/db/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateBatchS3Key = exports.updateBatchStatus = exports.getCanvasserProfile = exports.getSubmissionsWithUserIds = exports.getOpenBatches = exports.closePool = exports.setPool = exports.getPool = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* db/index.ts — Barrel export for the database module
|
|
6
|
+
*/
|
|
7
|
+
var pool_1 = require("./pool");
|
|
8
|
+
Object.defineProperty(exports, "getPool", { enumerable: true, get: function () { return pool_1.getPool; } });
|
|
9
|
+
Object.defineProperty(exports, "setPool", { enumerable: true, get: function () { return pool_1.setPool; } });
|
|
10
|
+
Object.defineProperty(exports, "closePool", { enumerable: true, get: function () { return pool_1.closePool; } });
|
|
11
|
+
var queries_1 = require("./queries");
|
|
12
|
+
Object.defineProperty(exports, "getOpenBatches", { enumerable: true, get: function () { return queries_1.getOpenBatches; } });
|
|
13
|
+
Object.defineProperty(exports, "getSubmissionsWithUserIds", { enumerable: true, get: function () { return queries_1.getSubmissionsWithUserIds; } });
|
|
14
|
+
Object.defineProperty(exports, "getCanvasserProfile", { enumerable: true, get: function () { return queries_1.getCanvasserProfile; } });
|
|
15
|
+
Object.defineProperty(exports, "updateBatchStatus", { enumerable: true, get: function () { return queries_1.updateBatchStatus; } });
|
|
16
|
+
Object.defineProperty(exports, "updateBatchS3Key", { enumerable: true, get: function () { return queries_1.updateBatchS3Key; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,+BAAqD;AAA5C,+FAAA,OAAO,OAAA;AAAE,+FAAA,OAAO,OAAA;AAAE,iGAAA,SAAS,OAAA;AACpC,qCAMmB;AALhB,yGAAA,cAAc,OAAA;AACd,oHAAA,yBAAyB,OAAA;AACzB,8GAAA,mBAAmB,OAAA;AACnB,4GAAA,iBAAiB,OAAA;AACjB,2GAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* db/pool.ts — Neon PostgreSQL connection pool
|
|
3
|
+
*
|
|
4
|
+
* Creates and manages a singleton pg.Pool connected to the team
|
|
5
|
+
* Neon database. Supports dependency injection via setPool(), or
|
|
6
|
+
* auto-creates from a connection string / environment variables.
|
|
7
|
+
*
|
|
8
|
+
* Resolution order for the connection string:
|
|
9
|
+
* 1. Explicit `databaseUrl` passed to `getPool()`
|
|
10
|
+
* 2. `TEAM_DATABASE_URL` environment variable
|
|
11
|
+
* 3. `WNC_TRACKING_DATABASE_URI` environment variable
|
|
12
|
+
*/
|
|
13
|
+
import { Pool } from "pg";
|
|
14
|
+
/**
|
|
15
|
+
* Inject an externally-created Pool instance.
|
|
16
|
+
* Useful when the consumer already has a connection pool (e.g. a web server).
|
|
17
|
+
*
|
|
18
|
+
* @param externalPool - A pg.Pool to use for all subsequent queries
|
|
19
|
+
*/
|
|
20
|
+
export declare function setPool(externalPool: Pool): void;
|
|
21
|
+
/**
|
|
22
|
+
* Create or return the singleton PostgreSQL connection pool.
|
|
23
|
+
*
|
|
24
|
+
* @param databaseUrl - Optional explicit connection string (highest priority)
|
|
25
|
+
* @returns A connected pg.Pool instance
|
|
26
|
+
* @throws Error if no connection string can be resolved
|
|
27
|
+
*/
|
|
28
|
+
export declare function getPool(databaseUrl?: string): Pool;
|
|
29
|
+
/**
|
|
30
|
+
* Gracefully close the connection pool and release all clients.
|
|
31
|
+
* Safe to call multiple times or when no pool exists.
|
|
32
|
+
*/
|
|
33
|
+
export declare function closePool(): Promise<void>;
|
|
34
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/db/pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAK1B;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,YAAY,EAAE,IAAI,GAAG,IAAI,CAEhD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CA0BlD;AAED;;;GAGG;AACH,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAK/C"}
|
package/dist/db/pool.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* db/pool.ts — Neon PostgreSQL connection pool
|
|
4
|
+
*
|
|
5
|
+
* Creates and manages a singleton pg.Pool connected to the team
|
|
6
|
+
* Neon database. Supports dependency injection via setPool(), or
|
|
7
|
+
* auto-creates from a connection string / environment variables.
|
|
8
|
+
*
|
|
9
|
+
* Resolution order for the connection string:
|
|
10
|
+
* 1. Explicit `databaseUrl` passed to `getPool()`
|
|
11
|
+
* 2. `TEAM_DATABASE_URL` environment variable
|
|
12
|
+
* 3. `WNC_TRACKING_DATABASE_URI` environment variable
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.setPool = setPool;
|
|
16
|
+
exports.getPool = getPool;
|
|
17
|
+
exports.closePool = closePool;
|
|
18
|
+
const pg_1 = require("pg");
|
|
19
|
+
/** Singleton pool instance */
|
|
20
|
+
let pool = null;
|
|
21
|
+
/**
|
|
22
|
+
* Inject an externally-created Pool instance.
|
|
23
|
+
* Useful when the consumer already has a connection pool (e.g. a web server).
|
|
24
|
+
*
|
|
25
|
+
* @param externalPool - A pg.Pool to use for all subsequent queries
|
|
26
|
+
*/
|
|
27
|
+
function setPool(externalPool) {
|
|
28
|
+
pool = externalPool;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create or return the singleton PostgreSQL connection pool.
|
|
32
|
+
*
|
|
33
|
+
* @param databaseUrl - Optional explicit connection string (highest priority)
|
|
34
|
+
* @returns A connected pg.Pool instance
|
|
35
|
+
* @throws Error if no connection string can be resolved
|
|
36
|
+
*/
|
|
37
|
+
function getPool(databaseUrl) {
|
|
38
|
+
if (pool) {
|
|
39
|
+
return pool;
|
|
40
|
+
}
|
|
41
|
+
const connectionString = databaseUrl ||
|
|
42
|
+
process.env.TEAM_DATABASE_URL ||
|
|
43
|
+
process.env.WNC_TRACKING_DATABASE_URI;
|
|
44
|
+
if (!connectionString) {
|
|
45
|
+
throw new Error("No database connection string found. " +
|
|
46
|
+
"Provide a `pool` or `databaseUrl` in FormFillerConfig, " +
|
|
47
|
+
"or set TEAM_DATABASE_URL / WNC_TRACKING_DATABASE_URI.");
|
|
48
|
+
}
|
|
49
|
+
pool = new pg_1.Pool({
|
|
50
|
+
connectionString,
|
|
51
|
+
max: 10,
|
|
52
|
+
idleTimeoutMillis: 30_000,
|
|
53
|
+
connectionTimeoutMillis: 10_000,
|
|
54
|
+
});
|
|
55
|
+
return pool;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gracefully close the connection pool and release all clients.
|
|
59
|
+
* Safe to call multiple times or when no pool exists.
|
|
60
|
+
*/
|
|
61
|
+
async function closePool() {
|
|
62
|
+
if (pool) {
|
|
63
|
+
await pool.end();
|
|
64
|
+
pool = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../src/db/pool.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAaH,0BAEC;AASD,0BA0BC;AAMD,8BAKC;AA3DD,2BAA0B;AAE1B,8BAA8B;AAC9B,IAAI,IAAI,GAAgB,IAAI,CAAC;AAE7B;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,YAAkB;IACvC,IAAI,GAAG,YAAY,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,WAAoB;IACzC,IAAI,IAAI,EAAE,CAAC;QACR,OAAO,IAAI,CAAC;IACf,CAAC;IAED,MAAM,gBAAgB,GACnB,WAAW;QACX,OAAO,CAAC,GAAG,CAAC,iBAAiB;QAC7B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;IAEzC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACZ,uCAAuC;YACpC,yDAAyD;YACzD,uDAAuD,CAC5D,CAAC;IACL,CAAC;IAED,IAAI,GAAG,IAAI,SAAI,CAAC;QACb,gBAAgB;QAChB,GAAG,EAAE,EAAE;QACP,iBAAiB,EAAE,MAAM;QACzB,uBAAuB,EAAE,MAAM;KACjC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACf,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,SAAS;IAC5B,IAAI,IAAI,EAAE,CAAC;QACR,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QACjB,IAAI,GAAG,IAAI,CAAC;IACf,CAAC;AACJ,CAAC"}
|