# Region-स्तर के obfuscation directives

आपके source में लिखे comments जो अपने द्वारा mark किए गए code के लिए AfterPack की protection बदल देते हैं।

Source: https://www.afterpack.dev/hi/docs/directives

Directive एक comment है जो अपने द्वारा mark किए गए code के लिए AfterPack की protection बदल देता है। Build का बाकी हर हिस्सा उसी [configuration](https://www.afterpack.dev/hi/docs/config) पर रहता है जो आपने पूरे program के लिए तय की है। Directives एक [Pro](https://www.afterpack.dev/hi/docs/pro) feature हैं।

## Directive कैसे लिखें

Directive एक block comment है जो `@afterpack` से शुरू होता है। अगर वह अपनी लाइन पर अकेला हो, तो वह उसके बाद के पूरे code पर, मेल खाने वाले `/* @afterpack end */` तक, लागू होता है। अगर उसी लाइन पर उसके बाद code आता है, तो वह उस लाइन के बाकी हिस्से पर लागू होता है।

```js
/* @afterpack preset=hard */
function checkLicense(token) {
  return verifySignature(token, PUBLIC_KEY);
}
/* @afterpack end */

const apiKey = /* @afterpack preset=extreme */ "YOUR_SECRET";
```

Keys [Configuration](https://www.afterpack.dev/hi/docs/config) पेज के dotted नाम हैं, जिन्हें space से अलग किया जाता है: `/* @afterpack preset=hard inflation.max=6 */`। अकेली लिखी boolean key का मतलब `true` है। Directives केवल उसी code पर लागू होते हैं जिसे वे घेरते हैं: न उससे call किए गए functions पर, न imports पर।

## आप क्या सेट कर सकते हैं

हर वह option जो region-स्तर पर लागू होता है। हर option अपनी definition से link करता है, और वहां का `directive` tab सटीक spelling दिखाता है।

- [`skip`](https://www.afterpack.dev/docs/config#skip) — directive only
- [`preset`](https://www.afterpack.dev/docs/config#preset)
- [`complexity`](https://www.afterpack.dev/docs/config#complexity)
- [`inflation.max`](https://www.afterpack.dev/docs/config#inflation-max)
- [`strings.encode`](https://www.afterpack.dev/docs/config#strings-encode)

Directive में लिखा कोई भी दूसरा option ignore कर दिया जाता है और info के रूप में report होता है। कोई unknown key या गलत बना directive एक error है।

## Directive कब इस्तेमाल करें

- सबसे महत्वपूर्ण code को, जैसे licence checks, anti-tamper logic या bundle में शामिल कोई secret, `preset=extreme` से mark करें। Program का बाकी हिस्सा हल्का और छोटा रहता है।
- जो code पढ़ने योग्य या तेज़ रहना चाहिए, जैसे कोई hot loop या third-party snippet, उसे `skip` या किसी कम `preset` से mark करें।

## क्या mark करें

| Asset | Directive | क्यों |
| --- | --- | --- |
| Licence / entitlement checks | [`preset=hard`](https://www.afterpack.dev/hi/docs/config#preset) | एक अकेला patched bit आपका software किसी के भी हाथ में दे देता है। इसे [`transforms.comparisonHardening.enabled`](https://www.afterpack.dev/hi/docs/best-practices#the-two-anti-tamper-transforms) के साथ जोड़ें। |
| Payment validators | `preset=hard` | यहां खतरा tampering है, सिर्फ़ पढ़ा जाना नहीं। |
| Anti-cheat / anti-bot logic | `preset=hard` या `preset=extreme` | Cheat development की लागत बढ़ाता है और उसे बार-बार दोहराना ज़रूरी बना देता है। विरोधियों के पास समय और इरादा दोनों हैं, इसलिए इसे server-authoritative validation के साथ जोड़ें। |
| Hardcoded secrets जिन्हें आप server-side नहीं ले जा सकते | [`/* @afterpack preset=extreme */`](https://www.afterpack.dev/hi/docs/config#preset) inline, literal से पहले | सबसे अच्छा है इन्हें पूरी तरह हटा देना, लेकिन कुछ हमेशा छूट जाते हैं। `preset=extreme` recovery को महंगा बना देता है, फिर भी literal output में मौजूद रहता है। जिस literal से आपका code तुलना करता है, उसे [`transforms.comparisonHardening.enabled`](https://www.afterpack.dev/hi/docs/config#transforms-kind-enabled) के साथ output से पूरी तरह बाहर रखें। जो secret पहले ही ship हो चुका है, उसके लिए [अगर आपने गलती से कोई secret ship कर दिया](https://www.afterpack.dev/hi/docs/best-practices#if-you-shipped-a-secret-by-accident) देखें। |
| Proprietary algorithms (pricing, routing, ML glue) | core function के चारों ओर `/* @afterpack preset=extreme */ … /* @afterpack end */` | यह आपका सबसे मूल्यवान code है। अधिकतम complexity target और constants floor चालू। |

Directive को उस सबसे छोटे scope पर लगाएं जो asset को cover करता हो। 500 लाइनों की फ़ाइल को `preset=extreme` mark करने से पूरा bundle फूल जाता है और फ़ायदा बहुत कम मिलता है।

## क्या लागू हुआ, यह कैसे जांचें

[Protection Map](https://www.afterpack.dev/hi/docs/protection-map) हर वह region दिखाता है जो किसी directive से बना, और उसके अंदर क्या लागू हुआ। जो directive पढ़ा तो गया लेकिन जिसका कोई असर नहीं हुआ, वह build के [diagnostics](https://www.afterpack.dev/hi/docs/diagnostics) में दिखता है।

## Free builds

Local build पूरे program पर एक ही configuration लागू करती है। protection बढ़ाने वाला directive build को एक ऐसे error के साथ रोक देता है जो Pro key माँगता है ([`DIAG_PRO_DIRECTIVE_REQUIRES_KEY`](https://www.afterpack.dev/hi/docs/diagnostics#complete-reference)): program के preset से ऊँचा `preset`, program के target से ऊपर या `light` program पर शून्य से अलग `complexity`, program के budget से ऊँचा `inflation.max`, या program का string floor बंद होने पर `strings.encode=on`। कोई भी दूसरा directive ignore कर दिया जाता है, और उसके region को program की configuration मिलती है, जिसमें `skip`, कम `preset` या `complexity`, कम `inflation.max` और transform masks (`transforms.only`, `transforms.deny`, `controlFlow.enabled=off`) शामिल हैं। [CLI](https://www.afterpack.dev/hi/docs/cli) किसी भी tier पर कोई directive नहीं पढ़ता।
