frontend-data-contracts
ما الذي تفعله
تساعد هذه المهارة على ضمان أن البيانات التي تدخل موقعك أو تطبيقك موثوقة وآمنة. تنشئ نقطة واحدة تُفحص فيها البيانات وتُحوَّل إلى صيغة آمنة قبل استخدامها.
متى تستخدمها
- ✓عندما تريد التأكد من أن البيانات المستلمة من الخادم صحيحة.
- ✓عند بناء تطبيقات تتطلب أمان البيانات وموثوقيتها.
- ✓لمنع الأخطاء الناتجة عن بيانات غير متوقعة في تطبيقات React أو React Native.
رابط المهارة
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/frontend-data-contracts/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“تحقّق من بيانات الفاتورة قبل عرضها في التطبيق.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تعمل عبر تحديد نقطة دخول واحدة لكل طلبات البيانات. وفي هذه النقطة تُحوَّل البيانات الخام القادمة من الإنترنت إلى صيغة آمنة وموثوقة، أو يُعاد خطأ واضح.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
Frontend Data Contracts (typed network boundary)
When to Use
Use this skill when you need a portable, framework-agnostic discipline for type safety at the network edge of any React or React Native app. Establishes one typed API client as the single fetch boundary, a parse-don't-validate rule that turns wire JSON into trusted domain types before it enters the app, runtime parsing, normalized errors and branded identifiers.
Portable skill — readable by Claude Code, OpenCode, Codex, Cursor, Windsurf, and others. This skill describes a discipline at the network edge — one client, one envelope, one error type, validated types — not a state library or a styling system. It pairs with the frontend-architecture skill (the client lives in
shared/api-client/) and is the foundation the frontend-optimistic-mutations skill builds on.
The goal: the moment data crosses from the network into the app, it stops being any-shaped wire
JSON and becomes a trusted, typed domain value — or it becomes a single, typed error.
There is exactly one place this transformation happens, and nothing untyped escapes it.
Example contract
The snippets marked “essence” are architecture sketches with omitted project dependencies and methods, not a complete client. A generic get<Invoice> type parameter is only a compile-time assertion: it cannot establish runtime validity. Require the actual schema parse before treating a value as an Invoice, normalize parser failures into the project error type, and keep authorization independent of both schema validation and branded IDs. Bind adapter behavior to the installed library version; do not assume an unsupported per-query callback exists.
0. The five core ideas
- One client is the only fetch boundary. A single typed
apiClientwrapsfetch. Components and hooks never callfetch/axiosdirectly — the boundary is enforceable in review and lint. - Parse, don't validate. Wire JSON is parsed into domain types at the boundary. After the client returns, the value is trusted everywhere downstream — no defensive
?.chains, no re-checking shapes in components. - One envelope. Every response is
{ data }on success or{ error }on failure. The client unwrapsdataand throws onerror, so callers receive the payload directly or a typed throw. - One normalized error type. Server error envelope, non-2xx status, malformed body, network failure, and abort all become a single
ApiErrorwith a machine code, status, and optional per-field errors. Callers handle one shape. - Identifiers are branded. Domain IDs are nominal types (
InvoiceId,CustomerId) so the compiler rejects passing one where another is expected — the most common silent bug in data-heavy UIs.
1. Directory layout
The boundary is one folder in shared/ (per the frontend-architecture skill).
src/shared/api-client/
├── index.ts ← barrel: apiClient, ApiError, types
├── client.ts ← the fetch wrapper: buildUrl, headers, parse, verbs
├── config.ts ← base URL resolution, default headers
├── error.ts ← the ApiError class + code→message-key mapping
├── types.ts ← envelope types, HttpMethod, RequestOptions, field errors
└── client.test.ts ← boundary behavior tests (envelope, errors, network)
Domain entity types and their schemas live with their feature module
(modules/{feature}/types/) or a shared contract package; the client is generic over T.
2. One client, the only fetch boundary
Every verb returns the unwrapped data payload typed by the caller, and throws an
ApiError on any failure. Components never see envelopes or raw responses.
// shared/api-client/client.ts (essence)
export const apiClient = {
get<T>(path: string, options?: RequestOptions): Promise<T> {
return request<T>("GET", path, undefined, options);
},
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {
return request<T>("POST", path, body, options);
},
patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {
/* … */
},
put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {
/* … */
},
delete<T>(path: string, options?: RequestOptions): Promise<T> {
/* … */
},
} as const;
export type ApiClient = typeof apiClient;
// CORRECT — a feature hook wraps the client, typed by the caller
…
الأسئلة الشائعة
ماذا تعني «type safety»؟
تعني أن الكود يعرف بالضبط نوع المعلومات المتوقعة (رقم أو نص أو تاريخ)، مما يمنع الأخطاء غير المتوقعة.
ما هي «الشبكة» أو «حافة الشبكة» (network edge)؟
هي النقطة التي تدخل عندها البيانات إلى التطبيق من الخارج، مثل الخادم على الإنترنت.
لماذا «Parse, don't validate»؟
التحقق (validate) يفحص فقط إن كانت البيانات صحيحة، أما «التحليل» (parse) فيحوّلها إلى صيغة آمنة وموثوقة يستطيع التطبيق استخدامها بأمان.
التفاصيل
الوصف الأصلي من المؤلف
A portable, framework-agnostic discipline for type safety at the network edge of any React or React Native app.
الشعبية
- نجوم GitHub
- 48k
- الترتيب
- #4663
- الترخيص
- MIT
- آخر تحديث
- 15/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
00-andruia-consultant
48kيساعد وكيلك على بدء مشاريع الذكاء الاصطناعي أو تحسينها. يحلل الكود ويقترح الأدوات ويُعد خطط عمل بالإسبانية.
007
48kيتيح لوكيلك إجراء تدقيقات أمنية ونمذجة التهديدات. مفيد لحماية المشاريع من الهجمات والثغرات الأمنية.
10-andruia-skill-smith
48kيساعد وكيلك على إنشاء أدوات الذكاء الاصطناعي أو تحسينها. يحدد طريقة عملها، ويكتب توثيقها، ويتحقق من بنيتها.
20-andruia-niche-intelligence
48kيتيح لوكيلك إعداد ملخص عن صناعة محددة. مفيد لفهم السياق والقواعد وأنماط الاستخدام والمخاطر لمشروع ما، باستخدام مصادر موثوقة.
مهارات مشابهة
angular-developer
280kيساعد وكيلك على كتابة شيفرة Angular وتقديم نصائح لبنية المشروع، ويفيد في بدء المشاريع الجديدة وإنشاء المكونات وتحسين الأداء وإمكانية الوصول.
frontend-a11y
280kيساعد وكيلك على جعل واجهات الويب متاحة للجميع، فيضمن أن المواقع والتطبيقات تعمل جيدًا مع قارئات الشاشة والتنقل بلوحة المفاتيح.
frontend-patterns
280kيطبّق وكيلك أنماط تطوير الواجهات الحديثة، فيحسّن الأداء ويدير الحالة ويتبع أفضل الممارسات في React وNext.js.