Skip to content

BREAKING: fatura 0.2.0 - TS, FaturaClient, dokümantasyon, testler ve daha fazlası#41

Merged
f merged 13 commits intof:masterfrom
boraoksuzoglu:feat/typescript-client-and-tests
Apr 8, 2026
Merged

BREAKING: fatura 0.2.0 - TS, FaturaClient, dokümantasyon, testler ve daha fazlası#41
f merged 13 commits intof:masterfrom
boraoksuzoglu:feat/typescript-client-and-tests

Conversation

@boraoksuzoglu
Copy link
Copy Markdown
Contributor

Özet

Bu PR, fatura paketini tek dosyalık CommonJS (index.js) yapısından çıkarıp TypeScript, derlenmiş dist/, FaturaClient tabanlı API, Vitest testleri, ESLint + Prettier ve isteğe bağlı yerel Next.js tabanlı dokümantasyon / demo (website/) ile yeniler.

BREAKING CHANGE: Geliştiriciler artık üst seviye fonksiyonları doğrudan require('fatura') ile alamaz; createFaturaClient() veya new FaturaClient(env) kullanılmalıdır.


Paket ve bağımlılıklar

Konu Önce (upstream) Bu PR
Çalışma zamanı bağımlılıkları isomorphic-fetch, uuid, number-to-text Yok — yalnızca Node 18+ (engines)
HTTP isomorphic-fetch Yerleşik fetch
İstek kimliği (callid) uuid v1 crypto.randomUUID()
Tutarı yazıya çevirme number-to-text + TR converter src/utils/number.ts içinde yerel Türkçe sayı metni (harici paket yok)
Ana giriş index.js dist/index.js + dist/index.d.ts

Bu sayede kurulum yüzeyi sadeleşir, güvenlik taraması ve bakım kolaylaşır.


API ve mimari

  • FaturaClient: Tüm GİB çağrıları instance üzerinden; createFaturaClient('PROD' \| 'TEST') ile ortam seçimi (global CURRENT_ENV / enableTestMode() yok).
  • Dışa aktarılanlar: FaturaClient, createFaturaClient, ilgili TypeScript tipleri (src/index.ts).

GİB hata işleme

  • assertApiSuccess: error alanı başarısızlık gösteriyorsa Error fırlatılır.
  • Geliştirme: messages[0] hem string hem { text } nesnesi olabilecek şekilde ele alınır (entegrasyonda görülen cevaplara uyum).

Upstream index.js ile hizalanan düzeltmeler (özet)

Ayrıntılar için önceki inceleme ve birim testleri geçerli; bu PR’da da korunur:

  1. verifySignSMSCode / COMMANDS uyumsuzluğu → doğru komut anahtarı (verifySMSCode) kullanımı.
  2. Yüksek seviye: createInvoiceAndGetDownloadURL / createInvoiceAndGetHTML{ sign } seçeneği; getDownloadURL / getInvoiceHTML için üçüncü argüman { signed }.
  3. getRecipientDataByTaxIDOrTRID çift tanımın kaldırılması.
  4. Taslak gövdesi: irsaliyeTarihi için doğru alan; halRusumuTutari eşlemesi düzeltilmiş.
  5. createInvoice: findInvoice sonuç vermezken imza çağrılmaz.

Geliştirici araçları

  • ESLint (flat config, eslint.config.mjs) + typescript-eslint + eslint-config-prettier
  • Prettier (.prettierrc.json, .prettierignore)
  • Script’ler: lint, lint:fix, format, format:check

Testler

  • Birim: tests/unit/**/*.test.tsfetch mock ile istek gövdesi ve mapping doğrulanır (235 test, 10 dosya).
  • Entegrasyon: vitest.config.integration.ts — gerçek GİB TEST; npm run test:integration. CI’da CI=true ile birim testleri entegrasyonu atlayacak şekilde kullanılabilir.
  • Coverage: vitest.config.ts içinde eşikler (lines / functions %80).

CI / yayın

  • .github/workflows/ci.yml: pull_request ve main / master push için Node 20, npm ci, npx tsc --noEmit, npm test (CI=true), npm run lint.
  • .github/workflows/npm-publish.yml: Release’te aynı doğrulamalar + npm run lint + publish öncesi npm run build, ardından npm publish.

website/ (Next.js)

  • Repoda website/ altında Next.js (App Router) projesi: dokümantasyon sayfaları, demo, stil.
  • Yerel GİB erişimi için app/api/gib-proxy/route.ts benzeri sunucu tarafı proxy deseni (tarayıcıdan doğrudan GİB’e CORS sorunu yaşamamak için); kimlik bilgileri yalnızca kullanıcının çalıştırdığı yerel sürece kalacak şekilde tasarlanmalıdır (üretimde halka açık deploy + gerçek şifre önerilmez).
  • llms.txt route’ları doküman keşfi için eklenebilir.

(Maintainer: website/ ana paketle birlikte mi tutulacak, ayrı repo mu — tercihinize göre PR bölünebilir.)


Dokümantasyon (README.md)

  • Üst kısımdaki ana kullanım createFaturaClient / client örnekleriyle uyumlu.
  • enableTestMode, üst seviye fonksiyon anlatımı ve findDraftInvoice hatası kaldırıldı; findInvoice, getDownloadURL / getInvoiceHTML için { signed }, test ortamı için createFaturaClient('TEST') ve Node 18+ notu eklendi.

Sürüm

  • package.json 0.2.0 — maintainer semver politikasına göre 1.0.0 da değerlendirilebilir (breaking API).

Nasıl doğrulandı?

npm ci
npx tsc --noEmit
npm test
npm run lint
npm run format:check   # isteğe bağlı
npm run build

- Replace legacy index.js with src/ compiled to dist/
- Introduce FaturaClient and createFaturaClient (per-environment base URL)
- Add tsconfig, ambient typings for number-to-text, engines.node >= 18

BREAKING CHANGE: Module API is no longer a bag of functions; use
createFaturaClient() or new FaturaClient(env) and call methods on the instance.
- Use actions/checkout and setup-node v4
- Align Node with package engines (20)
- Run build before tests and publish; enable npm cache
- Set contents: read permission; fix workflow comment
Introduce assertApiSuccess to read GİB API error/messages and throw a descriptive Error when the API reports an error. Extend ApiResponse with error/messages and add GibApiMessage and GibAuthResponse types. Use assertApiSuccess in client JSON parsing for fetch, adjust login/logout parsing to use GibAuthResponse, and change logout return type to Promise<unknown>. This surfaces API errors consistently and normalizes message extraction.
- Unit tests for FaturaClient (auth, invoice, query, user, SMS, etc.)
- Shared mock-fetch helpers and invoice/user fixtures
- Integration tests against earsivportaltest (skipped on CI when appropriate)
- Vitest config, coverage thresholds, and npm test scripts
Update GitHub Actions workflow to run a dedicated `test` job that performs npm ci, a TypeScript type-check (npx tsc --noEmit) and tests with CI=true, then run `publish-npm` only after tests succeed. Previously a combined `build` job ran install/build/test; now publish depends on the test job which then rebuilds and publishes using NODE_AUTH_TOKEN. Also updated the workflow comment to reflect the new order (type-check, test, then build/publish).
- Add eslint.config.mjs, .prettierrc.json, .prettierignore
- Add npm scripts: lint, lint:fix, format, format:check
- Fix test imports and @ts-expect-error comments
…rkish number text)

- Use crypto.randomUUID for GIB dispatch callid
- Replace number-to-text with local Turkish amount-to-words in utils/number
- Drop uuid and number-to-text from package.json dependencies
@f f merged commit 39b6061 into f:master Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants