Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Özet
Bu PR,
faturapaketini tek dosyalık CommonJS (index.js) yapısından çıkarıp TypeScript, derlenmişdist/,FaturaClienttabanlı 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()veyanew FaturaClient(env)kullanılmalıdır.Paket ve bağımlılıklar
isomorphic-fetch,uuid,number-to-textengines)isomorphic-fetchfetchcallid)uuidv1crypto.randomUUID()number-to-text+ TR convertersrc/utils/number.tsiçinde yerel Türkçe sayı metni (harici paket yok)index.jsdist/index.js+dist/index.d.tsBu 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 (globalCURRENT_ENV/enableTestMode()yok).FaturaClient,createFaturaClient, ilgili TypeScript tipleri (src/index.ts).GİB hata işleme
assertApiSuccess:erroralanı başarısızlık gösteriyorsa Error fırlatılır.messages[0]hem string hem{ text }nesnesi olabilecek şekilde ele alınır (entegrasyonda görülen cevaplara uyum).Upstream
index.jsile hizalanan düzeltmeler (özet)Ayrıntılar için önceki inceleme ve birim testleri geçerli; bu PR’da da korunur:
verifySignSMSCode/COMMANDSuyumsuzluğu → doğru komut anahtarı (verifySMSCode) kullanımı.createInvoiceAndGetDownloadURL/createInvoiceAndGetHTML→{ sign }seçeneği;getDownloadURL/getInvoiceHTMLiçin üçüncü argüman{ signed }.getRecipientDataByTaxIDOrTRIDçift tanımın kaldırılması.irsaliyeTarihiiçin doğru alan;halRusumuTutarieşlemesi düzeltilmiş.createInvoice:findInvoicesonuç vermezken imza çağrılmaz.Geliştirici araçları
eslint.config.mjs) + typescript-eslint + eslint-config-prettier.prettierrc.json,.prettierignore)lint,lint:fix,format,format:checkTestler
tests/unit/**/*.test.ts—fetchmock ile istek gövdesi ve mapping doğrulanır (235 test, 10 dosya).vitest.config.integration.ts— gerçek GİB TEST;npm run test:integration. CI’daCI=trueile birim testleri entegrasyonu atlayacak şekilde kullanılabilir.vitest.config.tsiçinde eşikler (lines/functions%80).CI / yayın
.github/workflows/ci.yml:pull_requestvemain/masterpush 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 öncesinpm run build, ardındannpm publish.website/(Next.js)website/altında Next.js (App Router) projesi: dokümantasyon sayfaları, demo, stil.app/api/gib-proxy/route.tsbenzeri 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.txtroute’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)createFaturaClient/clientörnekleriyle uyumlu.enableTestMode, üst seviye fonksiyon anlatımı vefindDraftInvoicehatası kaldırıldı;findInvoice,getDownloadURL/getInvoiceHTMLiçin{ signed }, test ortamı içincreateFaturaClient('TEST')ve Node 18+ notu eklendi.Sürüm
package.json0.2.0 — maintainer semver politikasına göre 1.0.0 da değerlendirilebilir (breaking API).Nasıl doğrulandı?