{"version":3,"sources":["../../src/utils/notifier.ts"],"names":["notifier","toastedNotifier","sendNotification","options","err","createNotifier","messageTemplate","param","enableNotifications","APP_NAME","notifyPatchDetected","projectId","notifyApprovalRequired","notifySuccess","uuid","notifyFailure","notifyRollbackFailure","requestApprovalWithNotification","resolve","response","logger","getErrorMessage","cleanResponse","chalk"],"mappings":"6RAsBA,MAAMA,CAAAA,CAA4BC,kBAAAA,CAMlC,MAAMC,EAAoBC,CAAAA,EAA+E,CAErG,GAAIA,CAAAA,CAAQ,mBAAA,GAAwB,KAAA,CAIpC,GAAI,CACAH,CAAAA,CAAS,MAAA,CAAO,CACZ,KAAA,CAAOG,CAAAA,CAAQ,MACf,OAAA,CAASA,CAAAA,CAAQ,OAAA,CACjB,KAAA,CAAO,CAAA,CAAA,CACP,IAAA,CAAM,EACV,CAAA,CAAIC,CAAAA,EAAsB,CAI1B,CAAC,EACL,CAAA,KAAc,CAEd,CACJ,CAAA,CAEaC,CAAAA,CAAkBC,CAAAA,EACpB,CAACC,CAAAA,CAAeC,CAAAA,CAA+B,OAAS,CAC3DN,CAAAA,CAAiB,CACb,KAAA,CAAOO,kBAAAA,CACP,OAAA,CAASH,EAAgBC,CAAK,CAAA,CAC9B,mBAAA,CAAAC,CACJ,CAAC,EACL,EAGSE,CAAAA,CAAsBL,CAAAA,CAC9BM,CAAAA,EAAsB,CAAA,iCAAA,EAAoCA,CAAS,CAAA,GAAA,CACxE,EAEaC,CAAAA,CAAyBP,CAAAA,CACjCM,CAAAA,EAAsB,CAAA,yCAAA,EAA4CA,CAAS,CAAA,GAAA,CAChF,EAEaE,CAAAA,CAAgBR,CAAAA,CACxBS,CAAAA,EAAiB,CAAA,QAAA,EAAWA,CAAI,CAAA,wBAAA,CACrC,EAEaC,CAAAA,CAAgBV,CAAAA,CACxBS,CAAAA,EAAiB,CAAA,QAAA,EAAWA,CAAI,CAAA,8BAAA,CACrC,EAEaE,CAAAA,CAAwBX,CAAAA,CAChCS,CAAAA,EAAiB,CA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O,KAAA,CAAM,CAAA,+CAAA,EAAkDC,sBAAAA,CAAgBjB,CAAG,CAAC,CAAA,CAAE,CAAA,CACrFc,CAAAA,CAAQ,aAAa,EACzB,CACJ,CAAC","file":"notifier.cjs","sourcesContent":["// @ts-ignore - toasted-notifier doesn't have TypeScript declarations\nimport toastedNotifier from 'toasted-notifier';\nimport chalk from 'chalk';\n\n// Manually define the interface for the parts of toasted-notifier we use,\n// as it doesn't have official TypeScript definitions.\ninterface NotifyOptions {\n  title: string;\n  message: string;\n  sound: boolean;\n  wait: boolean;\n  actions?: string[];\n  timeout?: number;\n}\n\ninterface ToastedNotifier {\n  notify(\n    options: NotifyOptions,\n    callback?: (err: Error | null, response: string) => void,\n  ): void;\n}\n\nconst notifier: ToastedNotifier = toastedNotifier;\nimport { APP_NAME } from './constants';\nimport { getErrorMessage, logger } from './logger';\n\n// This is a \"fire-and-forget\" utility. If notifications fail for any reason\n// (e.g., unsupported OS, DND mode, permissions), it should not crash the app.\nconst sendNotification = (options: { title: string; message: string; enableNotifications?: boolean }) => {\n    // Skip notification if explicitly disabled\n    if (options.enableNotifications === false) {\n        return;\n    }\n    \n    try {\n        notifier.notify({\n            title: options.title,\n            message: options.message,\n            sound: false, // Keep it quiet by default\n            wait: false,\n        }, (err: Error | null) => {\n            if (err) {\n                // Silently ignore errors. This is a non-critical feature.\n            }\n        });\n    } catch (err) {\n        // Silently ignore errors.\n    }\n};\n\nexport const createNotifier = (messageTemplate: (param: string) => string) => {\n    return (param: string, enableNotifications: boolean = true) => {\n        sendNotification({\n            title: APP_NAME,\n            message: messageTemplate(param),\n            enableNotifications,\n        });\n    };\n};\n\nexport const notifyPatchDetected = createNotifier(\n    (projectId: string) => `New patch detected for project \\`${projectId}\\`.`\n);\n\nexport const notifyApprovalRequired = createNotifier(\n    (projectId: string) => `Action required to approve changes for \\`${projectId}\\`.`\n);\n\nexport const notifySuccess = createNotifier(\n    (uuid: string) => `Patch \\`${uuid}\\` applied successfully.`\n);\n\nexport const notifyFailure = createNotifier(\n    (uuid: string) => `Patch \\`${uuid}\\` failed and was rolled back.`\n);\n\nexport const notifyRollbackFailure = createNotifier(\n    (uuid: string) => `CRITICAL: Rollback for patch \\`${uuid}\\` FAILED. Manual intervention required.`\n);\n\nexport const requestApprovalWithNotification = (\n    projectId: string,\n    enableNotifications: boolean = true\n): Promise<'approved' | 'rejected' | 'timeout' | 'unsupported'> => {\n    if (enableNotifications === false) {\n        return Promise.resolve('unsupported');\n    }\n\n    return new Promise((resolve) => {\n        try {\n            notifier.notify(\n                {\n                    title: `Approval Required for ${projectId}`,\n                    message: 'A patch requires your approval. You can also approve/reject in the terminal.',\n                    sound: true,\n                    wait: true, // This is key. It makes the notifier wait for user action.\n                    actions: ['Approve', 'Reject'],\n                    timeout: 30, // seconds\n                },\n                (err: Error | null, response: string) => {\n                    if (err) {\n                        logger.debug(`Notification approval error: ${getErrorMessage(err)}`);\n                        return resolve('unsupported');\n                    }\n                    const cleanResponse = (response || '').toLowerCase().trim();\n                    if (cleanResponse.startsWith('approve')) {\n                        resolve('approved');\n                    } else if (cleanResponse.startsWith('reject')) {\n                        resolve('rejected');\n                    } else if (cleanResponse === 'timeout') {\n                        logger.info(chalk.gray('Notification timed out. Please use the terminal to respond.'));\n                        return resolve('timeout');\n                    } else {\n                        logger.debug(`Notification approval received non-action response: \"${cleanResponse}\"`);\n                        resolve('timeout');\n                    }\n                }\n            );\n        } catch (err) {\n            logger.debug(`Notification dispatch threw synchronous error: ${getErrorMessage(err)}`);\n            resolve('unsupported');\n        }\n    });\n};"]}