{"id":476466,"date":"2026-04-18T14:07:08","date_gmt":"2026-04-18T14:07:08","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=476466"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=476466","title":{"rendered":"\u041a\u0430\u043a \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u043b\u0438\u0434\u044b \u0438\u0437 Next.js \u0432 1\u0421 \u0411\u0438\u0442\u0440\u0438\u043a\u0441: outbound \u0431\u0435\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u0438 \u0432\u043e\u0440\u043a\u0435\u0440\u043e\u0432"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u041e \u0447\u0451\u043c \u044d\u0442\u043e<\/h3>\n<p>\u0422\u0438\u043f\u043e\u0432\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u043c \u0440\u044b\u043d\u043a\u0435: \u0435\u0441\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0441\u0430\u0439\u0442 (\u043b\u0435\u043d\u0434\u0438\u043d\u0433, \u043c\u0430\u0440\u043a\u0435\u0442\u043f\u043b\u0435\u0439\u0441, \u043a\u0430\u0442\u0430\u043b\u043e\u0433), \u043d\u0430 \u043d\u0451\u043c \u0444\u043e\u0440\u043c\u044b \u2014 \u0437\u0430\u044f\u0432\u043a\u0430, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f, \u0437\u0430\u044f\u0432\u043a\u0430 \u043f\u0430\u0440\u0442\u043d\u0451\u0440\u0430. \u042d\u0442\u0438 \u043b\u0438\u0434\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0432 1\u0421 \u0411\u0438\u0442\u0440\u0438\u043a\u0441, \u0433\u0434\u0435 \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u0434\u0435\u043b \u043f\u0440\u043e\u0434\u0430\u0436.<\/p>\n<p>\u041f\u043e\u0434\u0445\u043e\u0434 &#171;\u0432 \u043b\u043e\u0431&#187; \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0444\u043e\u0440\u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>await fetch('<\/code><a href=\"https:\/\/bitrix...\/crm.lead.add\" rel=\"noopener noreferrer nofollow\"><code>https:\/\/bitrix...\/crm.lead.add<\/code><\/a><code>', ...)<\/code> \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043b\u0438\u0434\u0430.<\/p>\n<p>\u042d\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0411\u0438\u0442\u0440\u0438\u043a\u0441 REST API \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u0435\u043d \u043f\u043e latency \u2014 200 \u043c\u0441 \u0432 \u043d\u043e\u0440\u043c\u0435, 8 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0440\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 CRM. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0430\u0439\u0442\u0430 \u0432 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u043d\u0430 \u043a\u0440\u0443\u0442\u0438\u043b\u043a\u0443. \u0415\u0441\u043b\u0438 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u0443\u043f\u0430\u043b \u0438\u043b\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0438\u0442 \u2014 \u0441\u0430\u0439\u0442 \u043e\u0442\u0434\u0430\u0451\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0445\u043e\u0442\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0444\u043e\u0440\u043c\u0443 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u2014 \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043d\u0430 \u043c\u0430\u0440\u043a\u0435\u0442\u043f\u043b\u0435\u0439\u0441\u0435 \u043d\u0435\u0434\u0432\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 Next.js 16 + PostgreSQL 16 + 1\u0421 \u0411\u0438\u0442\u0440\u0438\u043a\u0441. \u0411\u0435\u0437 Redis, \u0431\u0435\u0437 BullMQ, \u0431\u0435\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u043e\u0440\u043a\u0435\u0440\u0430. \u041f\u0440\u043e\u0441\u0442\u043e Next.js API route + <code>after()<\/code> + \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u0441 retry \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c.<\/p>\n<p>\u0426\u0438\u0444\u0440\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430: 25 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0435\u0434\u0432\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 (\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <code>ready_homes<\/code> \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0437\u0430 \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u0438), 57 API-\u0440\u043e\u0443\u0442\u043e\u0432, PostgreSQL 16.13 \u043d\u0430 VPS, \u0434\u0435\u043f\u043b\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 systemd + nginx, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u2014 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e outbound (\u0441\u0430\u0439\u0442 \u2192 CRM).<\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0432 \u043e\u0434\u043d\u0443 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443<\/h3>\n<p>\u0422\u0440\u0438 \u0441\u043b\u043e\u044f, \u0431\u0435\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439:<\/p>\n<pre><code>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510       POST \/api\/leads        \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u2502   Browser    \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25b6 \u2502  Next.js API Route      \u2502\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518                              \u2502  1. \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f (zod)     \u2502                                              \u2502  2. INSERT \u0432 PostgreSQL \u2502                                              \u2502  3. 200 OK \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u2502                                              \u2502  4. after() \u2192 \u0411\u0438\u0442\u0440\u0438\u043a\u0441   \u2502                                              \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518                                                       \u2502                                        \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510                                        \u25bc                             \u25bc                              \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510          \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510                              \u2502   PostgreSQL     \u2502          \u2502   \u0411\u0438\u0442\u0440\u0438\u043a\u0441 REST   \u2502                              \u2502   leads table    \u2502          \u2502   crm.lead.add   \u2502                              \u2502   bitrix_id NULL \u2502          \u2502                  \u2502                              \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518          \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518                                       \u2502                             \u2502                                       \u2502        UPDATE leads         \u2502                                       \u2502  SET bitrix_id = $1         \u2502                                       \u2502  WHERE id = $2              \u2502                                       \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0438\u0434\u0435\u044f: <strong>\u043b\u0438\u0434 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435<\/strong>, \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u0441\u0440\u0430\u0437\u0443. \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0444\u043e\u043d\u043e\u0432\u043e \u0447\u0435\u0440\u0435\u0437 <code>after()<\/code>, \u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 (\u0432\u043d\u0435\u0448\u043d\u0438\u0439 ID \u043b\u0438\u0434\u0430 \u0432 CRM) \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 PostgreSQL \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u043f\u0434\u0435\u0439\u0442\u043e\u043c.<\/p>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e:<\/p>\n<ul>\n<li>\n<p>\u041f\u0430\u0434\u0435\u043d\u0438\u0435 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0430 \u043d\u0435 \u043b\u043e\u043c\u0430\u0435\u0442 \u0441\u0430\u0439\u0442.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043d\u0435 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p>\u041c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a\u0438\u0435 \u043b\u0438\u0434\u044b \u0443\u043b\u0435\u0442\u0435\u043b\u0438 \u0432 CRM (<code>bitrix_id IS NOT NULL<\/code>), \u0430 \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0451 \u043d\u0435\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u2014 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0442\u0440\u0430\u0438\u0442\u044c \u0432 \u0444\u043e\u043d\u0435, \u0438\u0434\u044f \u043f\u043e <code>bitrix_id IS NULL<\/code> (\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u044e, \u043f\u043e\u0447\u0435\u043c\u0443 \u2014 \u043d\u0438\u0436\u0435).<\/p>\n<\/li>\n<\/ul>\n<h3>after() \u0432 Next.js 16 \u2014 \u0447\u0442\u043e \u044d\u0442\u043e \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d<\/h3>\n<p>Next.js 16 \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b <code>after()<\/code> \u2014 API \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b <strong>\u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d<\/strong>. \u041d\u0435 &#171;\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e&#187;, \u043d\u0435 &#171;\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435&#187; \u2014 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a response \u0443\u043b\u0435\u0442\u0435\u043b \u0432 \u043a\u043b\u0438\u0435\u043d\u0442. \u0420\u0430\u043d\u043d\u0435\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0447\u0435\u0440\u0435\u0437 <code>Promise.resolve().then(...)<\/code> \u0431\u0435\u0437 <code>await<\/code> \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 fire-and-forget \u0441 \u0440\u0438\u0441\u043a\u0430\u043c\u0438 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043b\u0435\u0441\u0441-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0434\u043e \u0435\u0451 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p><code>after()<\/code> \u0440\u0435\u0448\u0430\u0435\u0442 \u044d\u0442\u043e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430: Next.js \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 response \u0443\u0436\u0435 \u043e\u0442\u0434\u0430\u043d, \u0438 \u0447\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0434\u043e \u0435\u0451 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f (\u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0434\u0435\u043f\u043b\u043e\u044f).<\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043b\u0438\u0434\u043e\u043c \u0432 API route \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">\/\/ \u0423\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0438\u0437 src\/app\/api\/leads\/route.tsimport { after } from \"next\/server\";export async function POST(request: Request) {  const payload = await request.json();  const parsed = LeadSchema.safeParse(payload);  if (!parsed.success) {    return Response.json({ error: \"invalid\" }, { status: 422 });  }  \/\/ \u0410\u043d\u0442\u0438\u0434\u0443\u0431\u043b\u044c \u043f\u043e \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0443 \u0432 \u043e\u043a\u043d\u0435 10 \u043c\u0438\u043d\u0443\u0442  const recent = await pgQuery&lt;{ count: bigint }&gt;(    `SELECT count(*)::bigint AS count     FROM public.leads     WHERE phone = $1 AND created_at &gt; $2::timestamptz`,    [parsed.data.phone, new Date(Date.now() - 10 * 60 * 1000).toISOString()]  );  if (recent[0].count &gt; 0n) {    return Response.json({ ok: true, deduplicated: true });  }  \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043d\u0430\u0448\u0443 \u0411\u0414. bitrix_id \u043f\u043e\u043a\u0430 NULL.  const [lead] = await pgQuery&lt;{ id: string }&gt;(    `INSERT INTO public.leads (name, phone, source)     VALUES ($1, $2, $3)     RETURNING id`,    [parsed.data.name, parsed.data.phone, parsed.data.source ?? \"website\"]  );  \/\/ \u041e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0443\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441.  \/\/ \u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u043e\u043c \u2014 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 response.  after(async () =&gt; {    try {      const bitrixId = await sendToBitrix24({        title: `\u0417\u0430\u044f\u0432\u043a\u0430: ${parsed.data.name}`,        phone: parsed.data.phone,        sourceDescription: parsed.data.source,      });      if (!bitrixId) return;      await pgQuery(        `UPDATE public.leads SET bitrix_id = $1 WHERE id = $2`,        [bitrixId, lead.id]      );    } catch (error) {      console.error(\"[Leads API] \u041e\u0448\u0438\u0431\u043a\u0430 \u0444\u043e\u043d\u043e\u0432\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441:\", error);    }  });  return Response.json({ ok: true, id: lead.id });}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e:<\/p>\n<ol>\n<li>\n<p><strong>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043f\u0440\u0430\u0432\u0434\u044b \u2014 \u043d\u0430\u0448\u0430 \u0411\u0414.<\/strong> \u041b\u0438\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d \u0432 <code>public.leads<\/code> \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u043e\u043b\u0435\u0437\u043b\u0438 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441. \u0415\u0441\u043b\u0438 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043b\u0435\u0436\u0438\u0442 \u2014 \u0443 \u043d\u0430\u0441 \u0432 \u0431\u0430\u0437\u0435 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u044f\u0432\u043a\u0430, \u0441 \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u0410\u043d\u0442\u0438\u0434\u0443\u0431\u043b\u044c \u043d\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 CRM, \u0430 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043d\u0430\u0448\u0435\u0439 \u0411\u0414.<\/strong> \u041e\u043a\u043d\u043e 10 \u043c\u0438\u043d\u0443\u0442 \u043f\u043e \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0443. \u0411\u0438\u0442\u0440\u0438\u043a\u0441, \u043a \u0441\u043b\u043e\u0432\u0443, \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0434\u0443\u0431\u043b\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043e\u043b\u0447\u0430 (\u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0451\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443) \u2014 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p><code><strong>bitrix_id<\/strong><\/code><strong> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043b\u0438\u0434\u043e\u0432.<\/strong> \u042d\u0442\u043e \u043d\u0430\u0448\u0430 &#171;\u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0430\u044f \u043d\u0438\u0442\u044c&#187; \u2014 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 ID \u043b\u0438\u0434\u0430 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0435. <code>NULL<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 &#171;\u0432 CRM \u0435\u0449\u0451 \u043d\u0435 \u0443\u043b\u0435\u0442\u0435\u043b&#187;. \u041a\u043e\u043b\u043e\u043d\u043a\u0430 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f, \u0438 \u044d\u0442\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e: \u043b\u0438\u0434 \u0431\u0435\u0437 <code>bitrix_id<\/code> \u2014 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435, \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0436\u0438\u0437\u043d\u0438 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0448\u0438\u0431\u043a\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043d\u0435 \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0430\u0440\u0443\u0436\u0443.<\/strong> \u041b\u043e\u0433\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 <code>journalctl<\/code> (\u0443 \u043d\u0430\u0441 systemd), \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u044d\u0442\u043e \u043d\u0435 \u0432\u0438\u0434\u043d\u043e.<\/p>\n<\/li>\n<\/ol>\n<h3>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u043a \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0443: retry, \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430<\/h3>\n<p>\u0420\u043e\u0432\u043d\u043e \u044d\u0442\u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u2014 \u0442\u043e, \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043b\u044e\u0431\u0430\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c API:<\/p>\n<pre><code class=\"typescript\">\/\/ src\/lib\/bitrix-runtime.tsconst MAX_ATTEMPTS = 2;const REQUEST_TIMEOUT_MS = 8000;const RETRY_DELAY_MS = 1500;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><code><strong>MAX_ATTEMPTS = 2<\/strong><\/code><strong>.<\/strong> \u041e\u0434\u043d\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u2014 \u043c\u0430\u043b\u043e: \u0441\u0435\u0442\u044c \u0434\u0440\u043e\u0433\u043d\u0443\u043b\u0430, \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043e\u0442\u0432\u0435\u0442\u0438\u043b 502 \u2014 \u043b\u0438\u0434 \u043f\u043e\u0442\u0435\u0440\u044f\u043d. \u0422\u0440\u0438 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u2014 \u0443\u0436\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u044b: \u0435\u0441\u043b\u0438 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043b\u0435\u0436\u0438\u0442 30 \u0441\u0435\u043a\u0443\u043d\u0434, \u043c\u044b \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u0435\u0440\u0436\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435. \u0414\u0432\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u0445\u043e\u0432\u043a\u0430 \u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0441\u0431\u043e\u0435\u0432, \u043d\u043e \u043d\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u0434\u043e\u043b\u0433\u043e\u0433\u043e \u0432\u0438\u0441\u044f\u0449\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p><code><strong>REQUEST_TIMEOUT_MS = 8000<\/strong><\/code><strong>.<\/strong> \u042d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. p95 latency \u0443 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 webhook \u043d\u0430 <code>crm.lead.add<\/code> \u2014 400-700 \u043c\u0441 \u043d\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0435. 8 \u0441\u0435\u043a\u0443\u043d\u0434 \u2014 \u044d\u0442\u043e &#171;\u0447\u0442\u043e-\u0442\u043e \u044f\u0432\u043d\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a, \u0445\u0432\u0430\u0442\u0438\u0442 \u0436\u0434\u0430\u0442\u044c&#187;. <code>AbortController<\/code> \u0441 \u0442\u0430\u043a\u0438\u043c \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c \u0440\u0435\u0436\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0434\u0430\u0451\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0448\u0430\u043d\u0441.<\/p>\n<\/li>\n<li>\n<p><code><strong>RETRY_DELAY_MS = 1500<\/strong><\/code><strong>.<\/strong> \u041b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 backoff. \u041d\u0435 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u2014 \u043f\u0440\u0438 \u0434\u0432\u0443\u0445 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u044d\u0442\u043e \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0430\u043c \u043a\u043b\u0438\u0435\u043d\u0442 (\u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0436\u0438\u0432\u0451\u0442 \u0432 <code>BitrixWebhookClient<\/code> \u043f\u043e\u0434 migration toolkit):<\/p>\n<pre><code class=\"typescript\">async function bitrixRequest(method: string, payload: Record&lt;string, unknown&gt;) {  const url = `${BITRIX_WEBHOOK_URL}\/${method}.json`;  for (let attempt = 1; attempt &lt;= MAX_ATTEMPTS; attempt++) {    const controller = new AbortController();    const timer = setTimeout(() =&gt; controller.abort(), REQUEST_TIMEOUT_MS);    try {      const response = await fetch(url, {        method: \"POST\",        headers: { \"Content-Type\": \"application\/json\" },        body: JSON.stringify(payload),        signal: controller.signal,      });      const text = await response.text();      const json = text ? JSON.parse(text) : {};      if (!response.ok || json.error) {        throw new Error(          json.error_description || json.error || `HTTP ${response.status}`        );      }      return json;    } catch (error) {      if (attempt &gt;= MAX_ATTEMPTS) throw error;      await new Promise((r) =&gt; setTimeout(r, RETRY_DELAY_MS));    } finally {      clearTimeout(timer);    }  }  throw new Error(`${method}: retries exhausted`);}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0440\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0442\u044b\u043a\u0430\u044e\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p><code><strong>AbortController<\/strong><\/code><strong> \u0441 \u043e\u0447\u0438\u0441\u0442\u043a\u043e\u0439 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0432 <\/strong><code><strong>finally<\/strong><\/code><strong>.<\/strong> \u0418\u043d\u0430\u0447\u0435 \u0432 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0442\u0430\u0439\u043c\u0435\u0440 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0442\u0438\u043a\u0430\u0442\u044c \u0438 \u0443\u0440\u043e\u043d\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0447\u0435\u0440\u0435\u0437 8 \u0441\u0435\u043a\u0443\u043d\u0434. \u0417\u0430\u0431\u044b\u0442\u044b\u0439 <code>clearTimeout<\/code> \u2014 \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><code><strong>response.text()<\/strong><\/code><strong> \u2192 <\/strong><code><strong>JSON.parse<\/strong><\/code><strong>, \u0430 \u043d\u0435 <\/strong><code><strong>response.json()<\/strong><\/code><strong>.<\/strong> \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u0442\u0434\u0430\u0451\u0442 \u043f\u0443\u0441\u0442\u043e\u0435 \u0442\u0435\u043b\u043e \u0441 200-\u043c \u043a\u043e\u0434\u043e\u043c \u0438\u043b\u0438 HTML. <code>response.json()<\/code> \u043d\u0430 \u044d\u0442\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043d\u0435\u0432\u043d\u044f\u0442\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430. \u0420\u0443\u0447\u043d\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0434\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043b\u043e\u0433 \u0441\u044b\u0440\u043e\u0439 \u0442\u0435\u043a\u0441\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u2014 \u044d\u0442\u043e \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0447\u0430\u0441\u044b \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041e\u0448\u0438\u0431\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432 \u0434\u0432\u0443\u0445 \u043c\u0435\u0441\u0442\u0430\u0445.<\/strong> <code>!response.ok<\/code> (HTTP-\u043e\u0448\u0438\u0431\u043a\u0430) \u0438 <code>json.error<\/code> (\u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u0432\u0435\u0440\u043d\u0443\u043b 200, \u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 <code>{error: \"INVALID_CREDENTIALS\"}<\/code>). \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u2014 throw \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f: incoming webhook, \u043d\u0435 OAuth<\/h3>\n<p>\u0414\u043b\u044f outbound-\u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0443 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0430 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0443\u0442\u0438: OAuth-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 incoming webhook (\u043b\u0438\u0447\u043d\u044b\u0439 URL \u0441 \u0442\u043e\u043a\u0435\u043d\u043e\u043c \u0432 \u043f\u0443\u0442\u0438).<\/p>\n<p>\u042f \u0432\u044b\u0431\u0440\u0430\u043b webhook. \u041f\u0440\u0438\u0447\u0438\u043d\u044b:<\/p>\n<ul>\n<li>\n<p>\u041d\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 Marketplace \u2192 \u043d\u0435\u0442 \u0430\u043f\u0440\u0443\u0432\u0430\u043b\u043e\u0432, \u043d\u0435\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<\/li>\n<li>\n<p>URL \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0443\u044e env-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>BITRIX24_WEBHOOK_URL<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043a\u043e\u0443\u043f\u044b \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0430 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0432\u0435\u0431\u0445\u0443\u043a\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u043e\u0432\u043e\u0439 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 (\u043e \u043d\u0435\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430 URL: <code>BITRIX24_SOURCE_WEBHOOK_URL<\/code> (\u043e\u0442\u043a\u0443\u0434\u0430 \u0442\u044f\u043d\u0435\u043c) \u0438 <code>BITRIX24_TARGET_WEBHOOK_URL<\/code> (\u043a\u0443\u0434\u0430 \u043f\u0438\u0448\u0435\u043c). \u0412 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043e\u0434\u043d\u043e\u0433\u043e.<\/p>\n<p>\u041c\u0438\u043d\u0443\u0441 webhook-\u043f\u043e\u0434\u0445\u043e\u0434\u0430: \u0442\u043e\u043a\u0435\u043d \u0432 URL. \u0415\u0441\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u043b\u043e\u0433\u0438\u0440\u0443\u0435\u0448\u044c \u043f\u043e\u043b\u043d\u044b\u0439 URL \u043a\u0443\u0434\u0430-\u0442\u043e \u0432 Sentry \u0438\u043b\u0438 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u2014 \u0441\u043e\u043b\u044c\u0451\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f \u043a CRM. \u041b\u0435\u0447\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u043e\u043c: \u043d\u0438 \u0432 \u043a\u043e\u0434\u0435, \u043d\u0438 \u0432 \u043b\u043e\u0433\u0430\u0445 \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c URL \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438 payload (\u0431\u0435\u0437 \u043f\u043e\u043b\u0435\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d).<\/p>\n<h3>PostgreSQL-\u0441\u0445\u0435\u043c\u0430: \u043e\u0434\u0438\u043d \u0441\u0442\u043e\u043b\u0431\u0435\u0446, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0448\u0430\u0435\u0442 \u0432\u0441\u0451<\/h3>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043b\u0438\u0434\u043e\u0432 \u2014 <code>bitrix_id<\/code>. \u0412\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2014 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0437\u0430\u044f\u0432\u043a\u0438.<\/p>\n<pre><code class=\"sql\">-- \u0423\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442CREATE TABLE IF NOT EXISTS public.leads (  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),  name text NOT NULL,  phone text NOT NULL,  source text,  bitrix_id text,  created_at timestamptz NOT NULL DEFAULT now());<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0422\u0440\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f:<\/p>\n<ol>\n<li>\n<p><code><strong>bitrix_id<\/strong><\/code><strong> \u2014 <\/strong><code><strong>text<\/strong><\/code><strong>, \u043d\u0435 <\/strong><code><strong>integer<\/strong><\/code><strong>.<\/strong> \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 ID \u043a\u0430\u043a \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 JSON. \u041c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0430\u043a \u0447\u0438\u0441\u043b\u043e, \u043d\u043e \u0437\u0430\u0447\u0435\u043c \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0438\u043b\u044b \u043d\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p><code><strong>bitrix_id<\/strong><\/code><strong> nullable.<\/strong> \u042d\u0442\u043e \u044f\u0432\u043d\u043e\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0432 CRM \u2014 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0438 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438. NULL \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 &#171;\u043b\u0438\u0431\u043e \u0435\u0449\u0451 \u043d\u0435 \u0443\u043b\u0435\u0442\u0435\u043b\u043e, \u043b\u0438\u0431\u043e \u0443\u043b\u0435\u0442\u0435\u043b\u043e, \u043d\u043e \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439&#187;. \u0420\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u044d\u0442\u0438 \u0434\u0432\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0411\u0414 \u044f \u043d\u0435 \u0441\u0442\u0430\u043b \u2014 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c.<\/p>\n<\/li>\n<li>\n<p><code><strong>id<\/strong><\/code><strong> \u0432 PostgreSQL \u2014 <\/strong><code><strong>uuid<\/strong><\/code><strong> \u0441 <\/strong><code><strong>gen_random_uuid()<\/strong><\/code><strong>.<\/strong> \u042d\u0442\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0438\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043d\u0430\u0448\u0435\u0439 \u0411\u0414 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c ID \u043b\u0438\u0434\u0430 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043a\u0430\u043a &#171;\u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a&#187; (\u0443 \u043d\u0430\u0441 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 migration toolkit \u0447\u0435\u0440\u0435\u0437 <code>ORIGINATOR_ID<\/code> + <code>ORIGIN_ID<\/code>, \u043d\u043e \u044d\u0442\u043e \u0442\u0435\u043c\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438).<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438:<\/p>\n<pre><code class=\"sql\">ALTER TABLE public.user_profiles  ADD COLUMN registration_bitrix_id text,  ADD COLUMN registration_bitrix_synced_at timestamptz;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u2014 <code>synced_at<\/code> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c &#171;\u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0438&#187; \u043e\u0442 &#171;\u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0442\u043e\u0433\u0434\u0430-\u0442\u043e&#187; \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0447\u0451\u0442\u044b &#171;\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0439 \u0437\u0430 \u043d\u0435\u0434\u0435\u043b\u044e \u0434\u043e\u0448\u043b\u0438 \u0434\u043e CRM&#187;.<\/p>\n<h3>\u0427\u0442\u043e \u044f \u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u043b<\/h3>\n<p>\u042d\u0442\u043e, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u0430\u044f \u0432\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043f\u0440\u043e &#171;\u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 CRM&#187; \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0436\u0435 \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Redis.<\/p>\n<p><strong>\u041d\u0435 \u0437\u0430\u0432\u0451\u043b Redis + BullMQ.<\/strong> \u0421\u043e\u0431\u043b\u0430\u0437\u043d \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0439: \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0437\u0430\u0434\u0430\u0447, \u0440\u0435\u0442\u0440\u0430\u0438 \u043f\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u044e, dead letter queue. \u041d\u0430 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0435 25 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u0438 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043b\u0438\u0434\u043e\u0432 \u0432 \u0434\u0435\u043d\u044c \u044d\u0442\u043e over-engineering. <code>after()<\/code> \u0432 Next.js 16 \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 99% \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432. Redis \u0434\u043e\u0431\u0430\u0432\u043b\u044e, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0445 \u0440\u0435\u0441\u0442\u0430\u0440\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.<\/p>\n<p><strong>\u041d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b inbound webhook \u043e\u0442 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0430.<\/strong> \u042d\u0442\u043e\u0433\u043e \u0447\u0430\u0441\u0442\u043e \u0436\u0434\u0443\u0442 \u043e\u0442 &#171;\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438&#187;: \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043e\u0431\u043d\u043e\u0432\u0438\u043b \u0441\u0442\u0430\u0442\u0443\u0441 \u0441\u0434\u0435\u043b\u043a\u0438 \u2192 \u043f\u0440\u0438\u043b\u0435\u0442\u0430\u0435\u0442 \u0432 \u043d\u0430\u0448 \u0441\u0430\u0439\u0442. \u041d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u044d\u0442\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e: \u0432\u0441\u044f \u043b\u043e\u0433\u0438\u043a\u0430 &#171;\u043a\u043b\u0438\u0435\u043d\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043e \u0441\u0442\u0430\u0442\u0443\u0441\u0430\u043c\u0438&#187; \u0436\u0438\u0432\u0451\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0430, \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0435 \u043d\u0430\u0434\u043e. \u0415\u0441\u043b\u0438 \u0437\u0430\u0432\u0442\u0440\u0430 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f endpoint <code>\/api\/bitrix\/webhook<\/code> \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0448\u0430\u0440\u0435\u0434-\u0441\u0435\u043a\u0440\u0435\u0442\u0430, \u0438 \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f.<\/p>\n<p><strong>\u041d\u0435 \u0434\u0435\u043b\u0430\u044e \u0434\u0432\u0443\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044e\u044e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0435\u0434\u0432\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u0438.<\/strong> \u041e\u0431\u044a\u0435\u043a\u0442\u044b \u0432 \u043c\u0430\u0440\u043a\u0435\u0442\u043f\u043b\u0435\u0439\u0441\u0435 \u0436\u0438\u0432\u0443\u0442 \u0432 PostgreSQL, \u043c\u043e\u0434\u0435\u0440\u0430\u0446\u0438\u044f \u2014 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0436\u0435 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 (<code>projects.moderation_status<\/code> + <code>pending_changes<\/code>). \u0412 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043b\u0435\u0442\u044f\u0442 <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0434\u044b \u0438 \u0437\u0430\u044f\u0432\u043a\u0438<\/strong>. \u042d\u0442\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0430 \u043d\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435: \u0431\u0438\u0437\u043d\u0435\u0441-\u0441\u043c\u044b\u0441\u043b &#171;\u0434\u0430\u0442\u044c \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0443 \u043e\u0431\u044a\u0435\u043a\u0442 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 CRM&#187; \u043d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442.<\/p>\n<p><strong>\u041d\u0435 \u0433\u043e\u043d\u044e\u0441\u044c \u0437\u0430 99.99% \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u043b\u0438\u0434\u043e\u0432 \u0432 CRM.<\/strong> \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u044b: \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0435\u0440\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c\u044e, \u0432\u043e\u0440\u043a\u0435\u0440-\u0440\u0435\u0442\u0440\u0430\u0435\u0440 \u043f\u043e \u043a\u0440\u043e\u043d\u0443, \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0437\u0430\u0441\u0442\u0440\u044f\u0432\u0448\u0438\u0445 \u0437\u0430\u0434\u0430\u0447. \u042f \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u043d\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 &#171;\u043f\u043e\u0441\u043b\u0435 \u0434\u0432\u0443\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u2014 \u043b\u043e\u0433 \u0438 \u0440\u0443\u043a\u0430\u043c\u0438&#187;. \u0417\u0430 \u0432\u0441\u0451 \u0432\u0440\u0435\u043c\u044f \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u0441\u0442\u0440\u044f\u0432\u0448\u0435\u0433\u043e \u043b\u0438\u0434\u0430 \u2014 \u0430\u043d\u0442\u0438\u0434\u0443\u0431\u043b\u044c \u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 retry \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0438\u043d\u0446\u0438\u0434\u0435\u043d\u0442\u044b. \u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u0430\u0441\u0448\u0442\u0430\u0431 \u0431\u044b\u043b \u043d\u0430 \u0434\u0432\u0430 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0432\u044b\u0448\u0435 \u2014 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0434\u0440\u0443\u0433\u0438\u043c.<\/p>\n<h3>Observability: \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440<\/h3>\n<p>\u0418\u0437 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><strong>\u0412\u043d\u0435\u0448\u043d\u0438\u0439 uptime-monitor \u0447\u0435\u0440\u0435\u0437 GitHub Actions<\/strong> \u0441 <code>cron: \"*\/5 * * * *\"<\/code>. \u0414\u0435\u0440\u0433\u0430\u0435\u0442 \u043f\u0440\u043e\u0434-\u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442, \u043f\u0440\u0438 \u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u2014 \u0430\u043b\u0435\u0440\u0442 \u0432 Telegram.<\/p>\n<\/li>\n<li>\n<p><code><strong>journalctl<\/strong><\/code><strong> \u043d\u0430 VPS<\/strong> \u0434\u043b\u044f \u0440\u0430\u043d\u0442\u0430\u0439\u043c-\u043b\u043e\u0433\u043e\u0432 Next.js-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u043e\u0434 systemd. \u041e\u0448\u0438\u0431\u043a\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u0432\u0438\u0434\u043d\u044b \u0447\u0435\u0440\u0435\u0437 <code>journalctl -u marketplace-next -f | grep Bitrix<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u0411\u044b\u0441\u0442\u0440\u044b\u0439 smoke-\u0442\u0435\u0441\u0442 \u0432 CI<\/strong> \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u0443\u0448\u0435 \u0432 main.<\/p>\n<\/li>\n<\/ul>\n<p>\u0427\u0435\u0433\u043e \u043d\u0435\u0442: Sentry, Grafana, Prometheus, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u0430 \u043f\u043e \u0411\u0438\u0442\u0440\u0438\u043a\u0441-\u0441\u0438\u043d\u043a\u0443. \u0414\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430 \u044d\u0442\u043e \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u043b\u043e\u0432\u0438\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <code>journalctl<\/code>, \u0430 &#171;\u043d\u0435 \u0434\u043e\u0435\u0445\u0430\u043b \u043b\u0438 \u043b\u0438\u0434&#187; \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c:<\/p>\n<pre><code class=\"sql\">SELECT id, name, created_atFROM public.leadsWHERE bitrix_id IS NULL  AND created_at &lt; now() - interval '5 minutes'ORDER BY created_at DESC;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432\u044b\u0440\u0430\u0441\u0442\u0435\u0442 \u2014 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f Sentry \u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 health-endpoint \u0434\u043b\u044f \u0411\u0438\u0442\u0440\u0438\u043a\u0441-\u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u041f\u043e\u043a\u0430 \u0440\u0430\u043d\u043e.<\/p>\n<h3>\u0427\u0442\u043e \u0437\u0430\u0431\u0440\u0430\u0442\u044c \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438<\/h3>\n<p>\u0422\u0440\u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u044e\u0442 90% \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430:<\/p>\n<ol>\n<li>\n<p><strong>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043f\u0440\u0430\u0432\u0434\u044b \u2014 \u0432\u0430\u0448\u0430 \u0411\u0414, \u043d\u0435 CRM.<\/strong> \u041f\u0438\u0448\u0438\u0442\u0435 \u043b\u0438\u0434 \u0432 PostgreSQL \u0441\u0440\u0430\u0437\u0443, <code>bitrix_id<\/code> \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0439\u0442\u0435 \u043f\u043e\u0442\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u0438 CRM.<\/strong> <code>after()<\/code> \u0432 Next.js 16 \u2014 \u0440\u043e\u0432\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>Retry + \u0442\u0430\u0439\u043c\u0430\u0443\u0442 + \u0430\u043d\u0442\u0438\u0434\u0443\u0431\u043b\u044c \u2014 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u0436\u0435\u043d\u0442\u043b\u044c\u043c\u0435\u043d\u0441\u043a\u0438\u0439 \u043d\u0430\u0431\u043e\u0440.<\/strong> \u0414\u0432\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438, 8 \u0441\u0435\u043a\u0443\u043d\u0434 \u0442\u0430\u0439\u043c\u0430\u0443\u0442, 10 \u043c\u0438\u043d\u0443\u0442 \u043e\u043a\u043d\u043e \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e \u043a\u043b\u044e\u0447\u0443. \u0414\u0430\u043b\u044c\u0448\u0435 \u2014 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043b\u0435\u043d\u0434\u0438\u043d\u0433, \u043c\u0430\u0440\u043a\u0435\u0442\u043f\u043b\u0435\u0439\u0441, \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0441 \u0437\u0430\u044f\u0432\u043a\u0430\u043c\u0438 \u2014 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c Redis \u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0434\u043d\u044f \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043f\u0430\u0442\u044c \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e.<\/p>\n<hr\/>\n<p><em>\u042f\u043a\u043e\u0432 \u0420\u0430\u0434\u0447\u0435\u043d\u043a\u043e. \u0414\u0435\u043b\u0430\u044e \u0432\u0435\u0431-\u043f\u0440\u043e\u0434\u0443\u043a\u0442\u044b \u043d\u0430 Next.js. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u2014 \u043f\u0440\u043e migration toolkit \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043c\u0435\u0436\u0434\u0443 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430\u043c\u0438: <\/em><code><em>crm.*.list<\/em><\/code><em> + \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044f + \u0438\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e <\/em><code><em>ORIGINATOR_ID<\/em><\/code><em>.<\/em><\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1025026\/\">https:\/\/habr.com\/ru\/articles\/1025026\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041e \u0447\u0451\u043c \u044d\u0442\u043e\u0422\u0438\u043f\u043e\u0432\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 \u0440\u043e\u0441\u0441\u0438\u0439\u0441\u043a\u043e\u043c \u0440\u044b\u043d\u043a\u0435: \u0435\u0441\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0441\u0430\u0439\u0442 (\u043b\u0435\u043d\u0434\u0438\u043d\u0433, \u043c\u0430\u0440\u043a\u0435\u0442\u043f\u043b\u0435\u0439\u0441, \u043a\u0430\u0442\u0430\u043b\u043e\u0433), \u043d\u0430 \u043d\u0451\u043c \u0444\u043e\u0440\u043c\u044b \u2014 \u0437\u0430\u044f\u0432\u043a\u0430, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f, \u0437\u0430\u044f\u0432\u043a\u0430 \u043f\u0430\u0440\u0442\u043d\u0451\u0440\u0430. \u042d\u0442\u0438 \u043b\u0438\u0434\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0432 1\u0421 \u0411\u0438\u0442\u0440\u0438\u043a\u0441, \u0433\u0434\u0435 \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u0434\u0435\u043b \u043f\u0440\u043e\u0434\u0430\u0436.\u041f\u043e\u0434\u0445\u043e\u0434 &#171;\u0432 \u043b\u043e\u0431&#187; \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0444\u043e\u0440\u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c await fetch(&#8216;https:\/\/bitrix&#8230;\/crm.lead.add&#8217;, &#8230;) \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u043b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043b\u0438\u0434\u0430.\u042d\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0411\u0438\u0442\u0440\u0438\u043a\u0441 REST API \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u0435\u043d \u043f\u043e latency \u2014 200 \u043c\u0441 \u0432 \u043d\u043e\u0440\u043c\u0435, 8 \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0440\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 CRM. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0430\u0439\u0442\u0430 \u0432 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u043d\u0430 \u043a\u0440\u0443\u0442\u0438\u043b\u043a\u0443. \u0415\u0441\u043b\u0438 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u0443\u043f\u0430\u043b \u0438\u043b\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u0438\u0442 \u2014 \u0441\u0430\u0439\u0442 \u043e\u0442\u0434\u0430\u0451\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0445\u043e\u0442\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0444\u043e\u0440\u043c\u0443 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e.\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u2014 \u043f\u0430\u0442\u0442\u0435\u0440\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u043d\u0430 \u043c\u0430\u0440\u043a\u0435\u0442\u043f\u043b\u0435\u0439\u0441\u0435 \u043d\u0435\u0434\u0432\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u0438 \u043d\u0430 Next.js 16 + PostgreSQL 16 + 1\u0421 \u0411\u0438\u0442\u0440\u0438\u043a\u0441. \u0411\u0435\u0437 Redis, \u0431\u0435\u0437 BullMQ, \u0431\u0435\u0437 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u043e\u0440\u043a\u0435\u0440\u0430. \u041f\u0440\u043e\u0441\u0442\u043e Next.js API route + after() + \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u0441 retry \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c.\u0426\u0438\u0444\u0440\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430: 25 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0435\u0434\u0432\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 (\u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c ready_homes \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0437\u0430 \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 \u0441\u0442\u0430\u0442\u044c\u0438), 57 API-\u0440\u043e\u0443\u0442\u043e\u0432, PostgreSQL 16.13 \u043d\u0430 VPS, \u0434\u0435\u043f\u043b\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 systemd + nginx, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u2014 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e outbound (\u0441\u0430\u0439\u0442 \u2192 CRM).\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0432 \u043e\u0434\u043d\u0443 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443\u0422\u0440\u0438 \u0441\u043b\u043e\u044f, \u0431\u0435\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439:\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510       POST \/api\/leads        \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u2502   Browser    \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25b6 \u2502  Next.js API Route      \u2502\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518                              \u2502  1. \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f (zod)     \u2502                                              \u2502  2. INSERT \u0432 PostgreSQL \u2502                                              \u2502  3. 200 OK \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u2502                                              \u2502  4. after() \u2192 \u0411\u0438\u0442\u0440\u0438\u043a\u0441   \u2502                                              \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518                                                       \u2502                                        \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510                                        \u25bc                             \u25bc                              \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510          \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510                              \u2502   PostgreSQL     \u2502          \u2502   \u0411\u0438\u0442\u0440\u0438\u043a\u0441 REST   \u2502                              \u2502   leads table    \u2502          \u2502   crm.lead.add   \u2502                              \u2502   bitrix_id NULL \u2502          \u2502                  \u2502                              \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518          \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518                                       \u2502                             \u2502                                       \u2502        UPDATE leads         \u2502                                       \u2502  SET bitrix_id = $1         \u2502                                       \u2502  WHERE id = $2              \u2502                                       \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u041a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0438\u0434\u0435\u044f: \u043b\u0438\u0434 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435, \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u0441\u0440\u0430\u0437\u0443. \u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0444\u043e\u043d\u043e\u0432\u043e \u0447\u0435\u0440\u0435\u0437 after(), \u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 (\u0432\u043d\u0435\u0448\u043d\u0438\u0439 ID \u043b\u0438\u0434\u0430 \u0432 CRM) \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 PostgreSQL \u0432\u0442\u043e\u0440\u044b\u043c \u0430\u043f\u0434\u0435\u0439\u0442\u043e\u043c.\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e:\u041f\u0430\u0434\u0435\u043d\u0438\u0435 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0430 \u043d\u0435 \u043b\u043e\u043c\u0430\u0435\u0442 \u0441\u0430\u0439\u0442.\u041c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043d\u0435 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442.\u041c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a\u0438\u0435 \u043b\u0438\u0434\u044b \u0443\u043b\u0435\u0442\u0435\u043b\u0438 \u0432 CRM (bitrix_id IS NOT NULL), \u0430 \u043a\u0430\u043a\u0438\u0435 \u0435\u0449\u0451 \u043d\u0435\u0442.\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u2014 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0442\u0440\u0430\u0438\u0442\u044c \u0432 \u0444\u043e\u043d\u0435, \u0438\u0434\u044f \u043f\u043e bitrix_id IS NULL (\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u044e, \u043f\u043e\u0447\u0435\u043c\u0443 \u2014 \u043d\u0438\u0436\u0435).after() \u0432 Next.js 16 \u2014 \u0447\u0442\u043e \u044d\u0442\u043e \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043dNext.js 16 \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b after() \u2014 API \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0443\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d. \u041d\u0435 &#171;\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e&#187;, \u043d\u0435 &#171;\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435&#187; \u2014 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a response \u0443\u043b\u0435\u0442\u0435\u043b \u0432 \u043a\u043b\u0438\u0435\u043d\u0442. \u0420\u0430\u043d\u043d\u0435\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0447\u0435\u0440\u0435\u0437 Promise.resolve().then(&#8230;) \u0431\u0435\u0437 await \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 fire-and-forget \u0441 \u0440\u0438\u0441\u043a\u0430\u043c\u0438 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043b\u0435\u0441\u0441-\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0434\u043e \u0435\u0451 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.after() \u0440\u0435\u0448\u0430\u0435\u0442 \u044d\u0442\u043e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430: Next.js \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 response \u0443\u0436\u0435 \u043e\u0442\u0434\u0430\u043d, \u0438 \u0447\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u0434\u043e \u0435\u0451 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f (\u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0434\u0435\u043f\u043b\u043e\u044f).\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043b\u0438\u0434\u043e\u043c \u0432 API route \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:\/\/ \u0423\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0438\u0437 src\/app\/api\/leads\/route.tsimport { after } from &#171;next\/server&#187;;export async function POST(request: Request) {  const payload = await request.json();  const parsed = LeadSchema.safeParse(payload);  if (!parsed.success) {    return Response.json({ error: &#171;invalid&#187; }, { status: 422 });  }  \/\/ \u0410\u043d\u0442\u0438\u0434\u0443\u0431\u043b\u044c \u043f\u043e \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0443 \u0432 \u043e\u043a\u043d\u0435 10 \u043c\u0438\u043d\u0443\u0442  const recent = await pgQuery&lt;{ count: bigint }&gt;(    `SELECT count(*)::bigint AS count     FROM public.leads     WHERE phone = $1 AND created_at &gt; $2::timestamptz`,    [parsed.data.phone, new Date(Date.now() &#8212; 10 * 60 * 1000).toISOString()]  );  if (recent[0].count &gt; 0n) {    return Response.json({ ok: true, deduplicated: true });  }  \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043d\u0430\u0448\u0443 \u0411\u0414. bitrix_id \u043f\u043e\u043a\u0430 NULL.  const [lead] = await pgQuery&lt;{ id: string }&gt;(    `INSERT INTO public.leads (name, phone, source)     VALUES ($1, $2, $3)     RETURNING id`,    [parsed.data.name, parsed.data.phone, parsed.data.source ?? &#171;website&#187;]  );  \/\/ \u041e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0443\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u044f\u043c\u043e \u0441\u0435\u0439\u0447\u0430\u0441.  \/\/ \u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u043e\u043c \u2014 \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 response.  after(async () =&gt; {    try {      const bitrixId = await sendToBitrix24({        title: `\u0417\u0430\u044f\u0432\u043a\u0430: ${parsed.data.name}`,        phone: parsed.data.phone,        sourceDescription: parsed.data.source,      });      if (!bitrixId) return;      await pgQuery(        `UPDATE public.leads SET bitrix_id = $1 WHERE id = $2`,        [bitrixId, lead.id]      );    } catch (error) {      console.error(&#171;[Leads API] \u041e\u0448\u0438\u0431\u043a\u0430 \u0444\u043e\u043d\u043e\u0432\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441:&#187;, error);    }  });  return Response.json({ ok: true, id: lead.id });}\u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e:\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043f\u0440\u0430\u0432\u0434\u044b \u2014 \u043d\u0430\u0448\u0430 \u0411\u0414. \u041b\u0438\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d \u0432 public.leads \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u043e\u043b\u0435\u0437\u043b\u0438 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441. \u0415\u0441\u043b\u0438 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043b\u0435\u0436\u0438\u0442 \u2014 \u0443 \u043d\u0430\u0441 \u0432 \u0431\u0430\u0437\u0435 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u044f\u0432\u043a\u0430, \u0441 \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438.\u0410\u043d\u0442\u0438\u0434\u0443\u0431\u043b\u044c \u043d\u0435 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 CRM, \u0430 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043d\u0430\u0448\u0435\u0439 \u0411\u0414. \u041e\u043a\u043d\u043e 10 \u043c\u0438\u043d\u0443\u0442 \u043f\u043e \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0443. \u0411\u0438\u0442\u0440\u0438\u043a\u0441, \u043a \u0441\u043b\u043e\u0432\u0443, \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0434\u0443\u0431\u043b\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u043e\u043b\u0447\u0430 (\u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0451\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443) \u2014 \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u0433\u043e.bitrix_id \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043b\u0438\u0434\u043e\u0432. \u042d\u0442\u043e \u043d\u0430\u0448\u0430 &#171;\u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0430\u044f \u043d\u0438\u0442\u044c&#187; \u2014 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 ID \u043b\u0438\u0434\u0430 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0435. NULL \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 &#171;\u0432 CRM \u0435\u0449\u0451 \u043d\u0435 \u0443\u043b\u0435\u0442\u0435\u043b&#187;. \u041a\u043e\u043b\u043e\u043d\u043a\u0430 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f, \u0438 \u044d\u0442\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e: \u043b\u0438\u0434 \u0431\u0435\u0437 bitrix_id \u2014 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435, \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0435 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0436\u0438\u0437\u043d\u0438 \u0437\u0430\u043f\u0438\u0441\u0438.\u041e\u0448\u0438\u0431\u043a\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043d\u0435 \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0430\u0440\u0443\u0436\u0443. \u041b\u043e\u0433\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 journalctl (\u0443 \u043d\u0430\u0441 systemd), \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u044d\u0442\u043e \u043d\u0435 \u0432\u0438\u0434\u043d\u043e.\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u043a \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0443: retry, \u0442\u0430\u0439\u043c\u0430\u0443\u0442, \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0420\u043e\u0432\u043d\u043e \u044d\u0442\u0438 \u0447\u0435\u0442\u044b\u0440\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u2014 \u0442\u043e, \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043b\u044e\u0431\u0430\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c API:\/\/ src\/lib\/bitrix-runtime.tsconst MAX_ATTEMPTS = 2;const REQUEST_TIMEOUT_MS = 8000;const RETRY_DELAY_MS = 1500;\u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:MAX_ATTEMPTS = 2. \u041e\u0434\u043d\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u2014 \u043c\u0430\u043b\u043e: \u0441\u0435\u0442\u044c \u0434\u0440\u043e\u0433\u043d\u0443\u043b\u0430, \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043e\u0442\u0432\u0435\u0442\u0438\u043b 502 \u2014 \u043b\u0438\u0434 \u043f\u043e\u0442\u0435\u0440\u044f\u043d. \u0422\u0440\u0438 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u2014 \u0443\u0436\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u044b: \u0435\u0441\u043b\u0438 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043b\u0435\u0436\u0438\u0442 30 \u0441\u0435\u043a\u0443\u043d\u0434, \u043c\u044b \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u0435\u0440\u0436\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435. \u0414\u0432\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u0430\u044f \u0441\u0442\u0440\u0430\u0445\u043e\u0432\u043a\u0430 \u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0441\u0431\u043e\u0435\u0432, \u043d\u043e \u043d\u0435 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u0434\u043e\u043b\u0433\u043e\u0433\u043e \u0432\u0438\u0441\u044f\u0449\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430.REQUEST_TIMEOUT_MS = 8000. \u042d\u043c\u043f\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. p95 latency \u0443 \u0411\u0438\u0442\u0440\u0438\u043a\u0441 webhook \u043d\u0430 crm.lead.add \u2014 400-700 \u043c\u0441 \u043d\u0430 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0435. 8 \u0441\u0435\u043a\u0443\u043d\u0434 \u2014 \u044d\u0442\u043e &#171;\u0447\u0442\u043e-\u0442\u043e \u044f\u0432\u043d\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a, \u0445\u0432\u0430\u0442\u0438\u0442 \u0436\u0434\u0430\u0442\u044c&#187;. AbortController \u0441 \u0442\u0430\u043a\u0438\u043c \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u043c \u0440\u0435\u0436\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0434\u0430\u0451\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0448\u0430\u043d\u0441.RETRY_DELAY_MS = 1500. \u041b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 backoff. \u041d\u0435 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u2014 \u043f\u0440\u0438 \u0434\u0432\u0443\u0445 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u0445 \u044d\u0442\u043e \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c.\u0421\u0430\u043c \u043a\u043b\u0438\u0435\u043d\u0442 (\u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0436\u0438\u0432\u0451\u0442 \u0432 BitrixWebhookClient \u043f\u043e\u0434 migration toolkit):async function bitrixRequest(method: string, payload: Record&lt;string, unknown&gt;) {  const url = `${BITRIX_WEBHOOK_URL}\/${method}.json`;  for (let attempt = 1; attempt &lt;= MAX_ATTEMPTS; attempt++) {    const controller = new AbortController();    const timer = setTimeout(() =&gt; controller.abort(), REQUEST_TIMEOUT_MS);    try {      const response = await fetch(url, {        method: &#171;POST&#187;,        headers: { &#171;Content-Type&#187;: &#171;application\/json&#187; },        body: JSON.stringify(payload),        signal: controller.signal,      });      const text = await response.text();      const json = text ? JSON.parse(text) : {};      if (!response.ok || json.error) {        throw new Error(          json.error_description || json.error || `HTTP ${response.status}`        );      }      return json;    } catch (error) {      if (attempt &gt;= MAX_ATTEMPTS) throw error;      await new Promise((r) =&gt; setTimeout(r, RETRY_DELAY_MS));    } finally {      clearTimeout(timer);    }  }  throw new Error(`${method}: retries exhausted`);}\u0422\u0440\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0442\u044b\u043a\u0430\u044e\u0442\u0441\u044f:AbortController \u0441 \u043e\u0447\u0438\u0441\u0442\u043a\u043e\u0439 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0432 finally. \u0418\u043d\u0430\u0447\u0435 \u0432 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0442\u0430\u0439\u043c\u0435\u0440 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0442\u0438\u043a\u0430\u0442\u044c \u0438 \u0443\u0440\u043e\u043d\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0447\u0435\u0440\u0435\u0437 8 \u0441\u0435\u043a\u0443\u043d\u0434. \u0417\u0430\u0431\u044b\u0442\u044b\u0439 clearTimeout \u2014 \u043a\u043b\u0430\u0441\u0441\u0438\u043a\u0430.response.text() \u2192 JSON.parse, \u0430 \u043d\u0435 response.json(). \u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u0445 \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u0442\u0434\u0430\u0451\u0442 \u043f\u0443\u0441\u0442\u043e\u0435 \u0442\u0435\u043b\u043e \u0441 200-\u043c \u043a\u043e\u0434\u043e\u043c \u0438\u043b\u0438 HTML. response.json() \u043d\u0430 \u044d\u0442\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043d\u0435\u0432\u043d\u044f\u0442\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430. \u0420\u0443\u0447\u043d\u043e\u0439 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0434\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432 \u043b\u043e\u0433 \u0441\u044b\u0440\u043e\u0439 \u0442\u0435\u043a\u0441\u0442 \u043e\u0442\u0432\u0435\u0442\u0430 \u2014 \u044d\u0442\u043e \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0447\u0430\u0441\u044b \u043e\u0442\u043b\u0430\u0434\u043a\u0438.\u041e\u0448\u0438\u0431\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432 \u0434\u0432\u0443\u0445 \u043c\u0435\u0441\u0442\u0430\u0445. !response.ok (HTTP-\u043e\u0448\u0438\u0431\u043a\u0430) \u0438 json.error (\u0411\u0438\u0442\u0440\u0438\u043a\u0441 \u0432\u0435\u0440\u043d\u0443\u043b 200, \u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 {error: &#171;INVALID_CREDENTIALS&#187;}). \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u2014 throw \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c.\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f: incoming webhook, \u043d\u0435 OAuth\u0414\u043b\u044f outbound-\u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0443 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0430 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0443\u0442\u0438: OAuth-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 incoming webhook (\u043b\u0438\u0447\u043d\u044b\u0439 URL \u0441 \u0442\u043e\u043a\u0435\u043d\u043e\u043c \u0432 \u043f\u0443\u0442\u0438).\u042f \u0432\u044b\u0431\u0440\u0430\u043b webhook. \u041f\u0440\u0438\u0447\u0438\u043d\u044b:\u041d\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 Marketplace \u2192 \u043d\u0435\u0442 \u0430\u043f\u0440\u0443\u0432\u0430\u043b\u043e\u0432, \u043d\u0435\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u043e\u043a\u0435\u043d\u0430.URL \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u0443\u044e env-\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e BITRIX24_WEBHOOK_URL.\u0421\u043a\u043e\u0443\u043f\u044b \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u0411\u0438\u0442\u0440\u0438\u043a\u0441\u0430 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0432\u0435\u0431\u0445\u0443\u043a\u0430.\u0414\u043b\u044f \u0440\u0430\u0437\u043e\u0432\u043e\u0439 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 (\u043e \u043d\u0435\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430 URL: BITRIX24_SOURCE_WEBHOOK_URL (\u043e\u0442\u043a\u0443\u0434\u0430 \u0442\u044f\u043d\u0435\u043c) \u0438 BITRIX24_TARGET_WEBHOOK_URL (\u043a\u0443\u0434\u0430 \u043f\u0438\u0448\u0435\u043c). \u0412 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043e\u0434\u043d\u043e\u0433\u043e.\u041c\u0438\u043d\u0443\u0441 webhook-\u043f\u043e\u0434\u0445\u043e\u0434\u0430: \u0442\u043e\u043a\u0435\u043d \u0432 URL. \u0415\u0441\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u043b\u043e\u0433\u0438\u0440\u0443\u0435\u0448\u044c \u043f\u043e\u043b\u043d\u044b\u0439 URL \u043a\u0443\u0434\u0430-\u0442\u043e \u0432 Sentry \u0438\u043b\u0438 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u2014 \u0441\u043e\u043b\u044c\u0451\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f \u043a CRM. \u041b\u0435\u0447\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u043e\u043c: \u043d\u0438 \u0432 \u043a\u043e\u0434\u0435, \u043d\u0438 \u0432 \u043b\u043e\u0433\u0430\u0445 \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c URL \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438 payload (\u0431\u0435\u0437 \u043f\u043e\u043b\u0435\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0442\u043e\u043a\u0435\u043d).PostgreSQL-\u0441\u0445\u0435\u043c\u0430: \u043e\u0434\u0438\u043d&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-476466","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/476466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=476466"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/476466\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=476466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=476466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=476466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}