Fix Tahesab health check to match Postman root-endpoint flow.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -177,6 +177,52 @@ export class TahesabApi {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* تست سلامت مطابق Postman تهحساب:
|
||||
* ابتدا ریشهٔ baseUrl، بعد /CheckHealth، در نهایت مسیر SSL یا No-SSL بر اساس پروتکل.
|
||||
*/
|
||||
async checkHealth() {
|
||||
const isHttps = /^https:/i.test(this.creds.baseUrl.trim());
|
||||
const timeoutMs = 12_000;
|
||||
type Health = { Status?: string; Api_Status?: string };
|
||||
const attempts: Array<{
|
||||
path: string;
|
||||
bodyKey?: string;
|
||||
method: 'GET' | 'POST';
|
||||
}> = [
|
||||
{ path: '', method: 'GET' },
|
||||
{ path: '', bodyKey: 'CheckHealth', method: 'POST' },
|
||||
{ path: 'CheckHealth', method: 'GET' },
|
||||
{
|
||||
path: isHttps ? 'CheckHealth-SSL' : 'CheckHealth-No-SSL',
|
||||
method: 'GET',
|
||||
},
|
||||
];
|
||||
|
||||
let lastErr: unknown;
|
||||
for (const attempt of attempts) {
|
||||
try {
|
||||
return await this.call<Health>(
|
||||
attempt.path,
|
||||
attempt.bodyKey,
|
||||
attempt.bodyKey ? [] : undefined,
|
||||
attempt.method,
|
||||
timeoutMs,
|
||||
);
|
||||
} catch (err) {
|
||||
lastErr = err;
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
// خطای گواهی با تلاشهای بعدی روی همان https حل نمیشود
|
||||
if (/certificate|UNABLE_TO_VERIFY|self-signed|CERT_/i.test(msg)) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw lastErr instanceof Error
|
||||
? lastErr
|
||||
: new Error('تست اتصال تهحساب ناموفق بود.');
|
||||
}
|
||||
|
||||
/** ثبت مشتری — پاسخ { OK: moshtariCode } */
|
||||
doNewMoshtari(args: unknown[]) {
|
||||
return this.call<{ OK?: number }>('DoNewMoshtari', 'DoNewMoshtari', args);
|
||||
|
||||
Reference in New Issue
Block a user