11#!/usr/bin/env tsx
22/**
3- * NOTE: Make sure to set CLIENT_URL in .env to the correct deployment URL
43 * Script to generate N seeds for a given location
54 * Usage: npm run generate-seeds -- <hubName|objectId> <count>
65 * Example: npm run generate-seeds -- "Main Hub" 10
@@ -49,9 +48,9 @@ function generateTimestampFilename(locationName: string, outputDir: string): str
4948 return path . join ( outputDir , filename ) ;
5049}
5150
52- async function generateQRCodeBuffer ( surveyCode : string , baseUrl : string , qrSize : number ) : Promise < Buffer > {
53- const qrUrl = ` ${ baseUrl } /survey?ref= ${ surveyCode } ` ;
54- const qrDataUrl = await QRCode . toDataURL ( qrUrl , {
51+ async function generateQRCodeBuffer ( surveyCode : string , qrSize : number ) : Promise < Buffer > {
52+ // Encode only the referral code (no URL) so QR codes work across any deployment
53+ const qrDataUrl = await QRCode . toDataURL ( surveyCode , {
5554 width : qrSize ,
5655 margin : 1 ,
5756 errorCorrectionLevel : 'M' ,
@@ -63,8 +62,7 @@ async function addQRCodePage(
6362 doc : any ,
6463 surveyCode : string ,
6564 locationName : string ,
66- baseUrl : string ,
67- isFirstPage : boolean ,
65+ isFirstPage : boolean
6866) : Promise < void > {
6967 if ( ! isFirstPage ) {
7068 doc . addPage ( ) ;
@@ -136,8 +134,8 @@ async function addQRCodePage(
136134 // QR Code and Referral Code
137135 const qrSize = 100 ;
138136 const qrX = ( pageWidth - qrSize ) / 2 ;
139-
140- const qrBuffer = await generateQRCodeBuffer ( surveyCode , baseUrl , qrSize ) ;
137+
138+ const qrBuffer = await generateQRCodeBuffer ( surveyCode , qrSize ) ;
141139 doc . image ( qrBuffer , qrX , currentY , {
142140 width : qrSize ,
143141 height : qrSize ,
@@ -219,7 +217,7 @@ async function generatePDF(seeds: any[], locationName: string): Promise<void> {
219217
220218 // Generate one page per seed
221219 for ( let i = 0 ; i < seeds . length ; i ++ ) {
222- await addQRCodePage ( doc , seeds [ i ] . surveyCode , locationName , baseUrl , i === 0 ) ;
220+ await addQRCodePage ( doc , seeds [ i ] . surveyCode , locationName , i === 0 ) ;
223221 }
224222
225223 doc . end ( ) ;
@@ -331,15 +329,6 @@ async function generateSeeds(locationIdentifier: string, count: number): Promise
331329 }
332330}
333331
334- // Require CLIENT_URL to be set
335- const baseUrl = process . env . CLIENT_URL ;
336- if ( ! baseUrl ) {
337- console . error ( '\n✗ Error: CLIENT_URL environment variable is not set' ) ;
338- console . error ( ' Please set CLIENT_URL in your .env file before running this script.' ) ;
339- console . error ( ' Example: CLIENT_URL=https://your-domain.com\n' ) ;
340- process . exit ( 1 ) ;
341- }
342-
343332// Parse command line arguments
344333const args = process . argv . slice ( 2 ) ;
345334
0 commit comments