private async canSendNotification()

in packages/web-api-scan-runner/src/sender/scan-notification-processor.ts [40:89]


    private async canSendNotification(
        scanMetadata: ScanMetadata,
        pageScanResult: OnDemandPageScanResult,
        websiteScanResult: WebsiteScanResult,
    ): Promise<boolean> {
        const featureFlags = await this.serviceConfig.getConfigValue('featureFlags');
        const scanConfig = await this.serviceConfig.getConfigValue('scanConfig');

        this.logger.logInfo(`The send scan completion feature flag is ${featureFlags.sendNotification ? 'enabled' : 'disabled'}.`, {
            sendNotificationFlag: featureFlags.sendNotification.toString(),
        });

        if (featureFlags.sendNotification !== true) {
            return false;
        }

        if (isEmpty(pageScanResult?.notification?.scanNotifyUrl)) {
            this.logger.logInfo(`Scan notification URL was not provided. Skip sending scan completion notification queue message.`);

            return false;
        }

        if (scanMetadata.deepScan !== true) {
            if (
                pageScanResult.run.state === 'completed' ||
                (pageScanResult.run.state === 'failed' && pageScanResult.run.retryCount >= scanConfig.maxFailedScanRetryCount)
            ) {
                this.logger.logInfo(`Sending scan completion notification message for a single scan.`, {
                    scanNotifyUrl: pageScanResult.notification.scanNotifyUrl,
                });

                return true;
            }
        }

        const deepScanCompleted =
            websiteScanResult.pageScans &&
            websiteScanResult.pageScans.length > 0 &&
            websiteScanResult.pageScans.every((pageScan) => pageScan.runState === 'completed' || pageScan.runState === 'failed');

        if (deepScanCompleted === true) {
            this.logger.logInfo('Sending scan completion notification message for a deep scan.', {
                deepScanId: websiteScanResult?.deepScanId,
                scannedPages: websiteScanResult.pageScans.length.toString(),
                scanNotifyUrl: pageScanResult.notification.scanNotifyUrl,
            });
        }

        return deepScanCompleted;
    }