feat/cp4-cloudflare-ops-final
audit/commit-drilldown audit/finalize-workspace-menu-security audit/ops-actionability audit/pr-menu-consolidation audit/status-menu-consolidation audit/telegram-menu-e2e audit/telegram-menu-e2e-wave2 chore/actions-node24-runtime cleanup/remove-diag design/cloudflare-ops-read docs/control-plane-2-7-design docs/guide-v2-1-sync docs/menu-audit-final-sync docs/phase2-acceptance-closeout docs/phase2-multifile-design feat/bootstrap-worker feat/cloudflare-ops-read feat/cp2-multifile-final feat/cp2-multifile-workspace feat/cp3-github-write-final feat/cp4-cloudflare-ops-final feat/cp5-cicd-control-plane feat/cp6-incident-manager feat/cp7-automation-engine feat/deep-file-browser feat/final-delivery-16-20 feat/github-advanced-read feat/in-app-guide-v2 feat/navigation-recovery-ux-v2 feat/ops-console-v2-1 feat/persistent-menu-code-input feat/phase2-multifile-workspace feat/phase2-multifile-workspace-v2 feat/plugin-foundation-v1 feat/safe-github-ops feat/self-register-webhook feat/studio-g0-foundation feat/telegram-main-inline-menu feat/telegram-pr-merge feat/ux-platform-8-12 feat/v3a-readonly-copilot feat/workspace-file-upload feature/mobile-repo-browser feature/multi-file-change-set fix/approval-expiry-feedback fix/callback-resilience-and-docs fix/ci-actions-pagination fix/cloudflare-fetch-binding fix/editor-request-body-cap fix/editor-safe-file-options fix/issues-permission-release-empty-ux fix/main-menu-callback-fallback fix/phase2-file-editor-selection fix/phase2-final-ux fix/phase2-workspace-ref-persistence fix/production-auto-deploy fix/provider-write-error-feedback fix/repository-id-navigation-fallback fix/repository-pr-navigation fix/telegram-callback-updates fix/telegram-runtime-diagnostics fix/workspace-editor-flow-v2 fix/workspace-recovery-validation hardening/ci-zero-test-telegram-token hardening/pr1-destructive-totp hardening/pr2-kill-switch main multifile-workspace nexa/edit-BwJEIIY3PW nexa/edit-IPHT8irO7b nexa/edit-b4Od3BIMYd p2-multifile phase2-20261005 phase2-20261005-a phase2-20261005-b phase2-20261005-c phase2-20261005-d phase2-20261005-e phase2-20261005-f phase2-20261005-g phase2-20261005-h phase2-20261005-i phase2-20261005-j phase2-20261005-k phase2-20261005-l phase2-20261005-m phase2-20261005-n phase2-20261005-o phase2-20261005-p phase2-20261005-q phase2-20261005-r phase2-20261005-s phase2-20261005-t phase2-20261005-u phase2-20261005-v phase2-20261005-w phase2-20261005-x phase2-20261005-y phase2-20261005-z phase2-acceptance-closeout phase2-add-file-hotfix phase2-change-set phase2-design-20261005 phase2-design-final phase2-implementation phase2-multifile-implementation phase2-multifile-spec phase2-spec-final phase2-workspace phase2/multifile-workspace plan/nexa-studio-v2-reviewed security/remove-telegram-setup spec/repository-workspace-editor v3a/multifile work/multifile
js 84 lines 4.13 KB
Raw
1 import { cloudflarePluginManifest } from './manifest.js';
2
3 const escapeHtml = value => String(value ?? '')
4 .replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;');
5 const mark = value => value ? '✅' : '❌';
6 const VERSION_ID = /^[0-9a-f-]{36}$/i;
7
8 function unavailableView() {
9 return {
10 text: '☁️ <b>Cloudflare Worker</b>\n❌ Provider Cloudflare پیکربندی نشده است.\nهیچ وضعیت موفق ساختگی نمایش داده نمی‌شود.',
11 reply_markup: { inline_keyboard: [[{ text: '🔄 بررسی مجدد', callback_data: 'cf:status' }],[{ text: '🔙 ابزارها', callback_data: 'menu:tools' }]] }
12 };
13 }
14
15 function snapshotView(snapshot) {
16 const deployment=snapshot.deployment, version=snapshot.version, obs=snapshot.observability||{};
17 const traffic=deployment?.versions?.length ? deployment.versions.map(i=>`${escapeHtml(i.versionId||'-')} — ${Number(i.percentage||0)}%`).join('\n') : 'استقرار فعالی گزارش نشده است.';
18 const bindings=snapshot.bindings?.length ? snapshot.bindings.slice(0,20).map(i=>`• <code>${escapeHtml(i.name||'-')}</code> — ${escapeHtml(i.type||'-')}`).join('\n') : '<i>Bindingی گزارش نشده است.</i>';
19 return {
20 text:`☁️ <b>Cloudflare Worker — ${escapeHtml(snapshot.workerName||'-')}</b>
21 ➖➖➖➖➖➖➖➖➖➖
22 <b>Deployment</b>
23 ID: <code>${escapeHtml(deployment?.id||'-')}</code>
24 Created: <code>${escapeHtml(deployment?.createdOn||'-')}</code>
25 Traffic:
26 ${traffic}
27
28 <b>Version</b>
29 ID: <code>${escapeHtml(version?.id||'-')}</code>
30
31 <b>Bindings</b>
32 ${bindings}
33
34 <b>Observability</b>
35 • Observability: ${mark(obs.enabled)}
36 • Logs: ${mark(obs.logsEnabled)}
37 • Invocation logs: ${mark(obs.invocationLogs)}
38 • Traces: ${mark(obs.tracesEnabled)}
39
40 Secret values نمایش داده نمی‌شوند.`,
41 reply_markup:{inline_keyboard:[
42 [{text:'📚 نسخه‌ها / Rollback',callback_data:'cf:versions'}],
43 [{text:'🔄 بروزرسانی',callback_data:'cf:status'}],
44 [{text:'🔙 ابزارها',callback_data:'menu:tools'}]
45 ]}
46 };
47 }
48
49 function versionsView(versions=[]) {
50 const rows=versions.slice(0,10).filter(v=>VERSION_ID.test(v.id)).map(v=>[
51 {text:`🚀 ${v.id.slice(0,8)} · ${String(v.createdOn||'').slice(0,10)}`,callback_data:`cfdeploy:${v.id}`}
52 ]);
53 return {
54 text:`☁️ <b>Cloudflare Versions</b>
55 هر Deploy/Rollback یک عملیات DESTRUCTIVE با Safe Approval است.
56 ➖➖➖➖➖➖➖➖➖➖
57 ${versions.slice(0,10).map(v=>`• <code>${escapeHtml(v.id)}</code>\n ${escapeHtml(v.createdOn||'-')} · ${escapeHtml(v.triggeredBy||'-')}`).join('\n\n')||'<i>نسخه‌ای گزارش نشده است.</i>'}`,
58 reply_markup:{inline_keyboard:[...rows,[{text:'🔄 بروزرسانی',callback_data:'cf:versions'}],[{text:'🔙 Cloudflare',callback_data:'cf:status'}]]}
59 };
60 }
61
62 export function createCloudflarePlugin({ cloudflare } = {}) {
63 return {
64 manifest: cloudflarePluginManifest,
65 resolveCallback(data) {
66 const value=String(data||'');
67 if(value==='cf:status') return {actionId:'cloudflare.worker.status',kind:'worker-status',async execute(){if(!cloudflare?.isConfigured?.())return unavailableView();return snapshotView(await cloudflare.getWorkerSnapshot());}};
68 if(value==='cf:versions') return {actionId:'cloudflare.worker.versions',kind:'versions',async execute(){if(!cloudflare?.isConfigured?.())return unavailableView();return versionsView(await cloudflare.listVersions());}};
69 const m=value.match(/^cfdeploy:([0-9a-f-]{36})$/i);
70 if(m) {
71 const versionId=m[1];
72 return {
73 actionId:'cloudflare.worker.deploy_version',
74 approval:{input:{versionId},label:`Deploy/Rollback Cloudflare ${versionId.slice(0,8)}`,cancelCallback:'cf:versions'},
75 async execute(){
76 const result=await cloudflare.deployVersion(versionId);
77 return {text:`✅ Cloudflare version <code>${escapeHtml(result.versionId)}</code> با 100% traffic تأیید شد.`,reply_markup:{inline_keyboard:[[{text:'☁️ وضعیت',callback_data:'cf:status'}]]}};
78 }
79 };
80 }
81 return null;
82 }
83 };
84 }