@stewardhq/sdk 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +123 -88
  2. package/dist/_chunks/errors.js +1 -1
  3. package/dist/_chunks/events.d.ts +315 -4
  4. package/dist/_chunks/events.js +1155 -9
  5. package/dist/_chunks/index.d.ts +3473 -90
  6. package/dist/_chunks/locale.d.ts +269 -1
  7. package/dist/_chunks/src.js +842 -24
  8. package/dist/_chunks/validators.d.ts +45 -1
  9. package/dist/_chunks/validators.js +128 -27
  10. package/dist/contract.d.ts +4 -4
  11. package/dist/contract.js +4 -4
  12. package/dist/index.d.ts +436 -22
  13. package/dist/index.js +1659 -26
  14. package/dist/server.d.ts +44 -6
  15. package/dist/server.js +29 -2
  16. package/package.json +4 -10
  17. package/dist/_chunks/steward.d.ts +0 -189
  18. package/dist/_chunks/steward.js +0 -560
  19. package/dist/testing/fixtures/events/LOCK.json +0 -27
  20. package/dist/testing/fixtures/events/account.deleted.json +0 -36
  21. package/dist/testing/fixtures/events/account.state_changed.json +0 -53
  22. package/dist/testing/fixtures/events/account.updated.json +0 -37
  23. package/dist/testing/fixtures/events/checkout.completed.json +0 -36
  24. package/dist/testing/fixtures/events/checkout.expired.json +0 -26
  25. package/dist/testing/fixtures/events/checkout.failed.json +0 -27
  26. package/dist/testing/fixtures/events/invoice.created.json +0 -37
  27. package/dist/testing/fixtures/events/invoice.issued.json +0 -38
  28. package/dist/testing/fixtures/events/invoice.voided.json +0 -39
  29. package/dist/testing/fixtures/events/subscription.activated.json +0 -40
  30. package/dist/testing/fixtures/events/subscription.cancel_scheduled.json +0 -38
  31. package/dist/testing/fixtures/events/subscription.canceled.json +0 -29
  32. package/dist/testing/fixtures/events/subscription.expired.json +0 -27
  33. package/dist/testing/fixtures/events/subscription.payment_failed.json +0 -38
  34. package/dist/testing/fixtures/events/subscription.reactivated.json +0 -36
  35. package/dist/testing/fixtures/events/subscription.renewed.json +0 -39
  36. package/dist/testing/fixtures/events/subscription.suspended.json +0 -36
  37. package/dist/testing/fixtures/events/subscription.terminated.json +0 -28
  38. package/dist/testing.d.ts +0 -626
  39. package/dist/testing.js +0 -3638
package/dist/testing.d.ts DELETED
@@ -1,626 +0,0 @@
1
- import { An as Stats, Cn as CancelSubscriptionInputSchema, En as GrantCreateInputSchema, Fn as PortalSession, Ft as ErrorCode, Gt as CheckoutSessionResponse, Jn as CheckoutSession, Ln as PortalSessionCreateInputSchema, Pr as EntitlementValue, Qn as CheckoutSessionCreated, Ut as CancelSubscriptionResponse, Vt as AccountUpsertResponse, Wn as CheckoutPrefill, Wr as Interval, Zn as CheckoutSessionCreateParsed, _r as FeatureDef, cn as InvoiceIssueInputSchema, en as InvoiceIssueResponse, gt as PlanSetInputSchema, hr as CatalogSyncResult, lr as AccountsRefreshResult, mr as CatalogSyncInputSchema, nt as ProductSettingsPatch, on as Invoice, pr as CatalogSyncInput, qt as GrantCreateResponse, rr as Consent, tt as ProductSettings, wt as ResyncResult, yt as PlanSetResponse, zt as AccountDetail } from "./_chunks/index.js";
2
- import { B as AccountUpsertInputSchema, C as AccountDeleteResponse, D as AccountInclude, F as AccountState, V as BillingProfile, a as BillingEvent, f as EventType, o as BillingEventOf, q as SubscriptionStatus, u as EventDetail } from "./_chunks/events.js";
3
- import { i as Steward, s as StewardOptions } from "./_chunks/steward.js";
4
- import { z } from "zod";
5
- //#endregion
6
- //#region src/testing/world.d.ts
7
- type Ms = number;
8
- type DunningAction = "retry_payment" | "suspend" | "terminate";
9
- /** Servisin `products.dunning_policy` şekli. */
10
- type FakeDunningPolicy = {
11
- readonly steps: readonly {
12
- readonly afterDays: number;
13
- readonly action: DunningAction;
14
- }[];
15
- /** true (servisin varsayılanı): adımlar yalnızca sayılır, askı/sonlandırma yok. */
16
- readonly dryRun: boolean;
17
- };
18
- /** Servisin `DEFAULT_DUNNING_POLICY` kopyası (`domain/dunning-policy.ts`). */
19
- export declare const DEFAULT_DUNNING_POLICY: FakeDunningPolicy;
20
- type PlanRow = {
21
- code: string;
22
- name: string;
23
- rank: number;
24
- sellable: boolean;
25
- active: boolean;
26
- entitlements: Record<string, EntitlementValue>;
27
- };
28
- type PriceRow = {
29
- id: string;
30
- planCode: string;
31
- interval: Interval;
32
- intervalCount: number;
33
- currency: string;
34
- amountMinor: number;
35
- taxInclusive: boolean;
36
- taxRateBps: number;
37
- active: boolean;
38
- createdAt: Ms;
39
- };
40
- type AccountRow = {
41
- ref: string;
42
- displayName: string;
43
- metadata: Record<string, string>;
44
- createdAt: Ms;
45
- version: number;
46
- /** Saklı durum; ilk commit'e kadar null. */
47
- state: AccountState | null;
48
- /** Yazılan her durum (version sırasıyla); `simulate.deliver({outOfOrder})` eski durumu buradan alır. */
49
- history: AccountState[];
50
- profile: BillingProfile | null;
51
- /** KVKK anonimleştirme anı (F4e, `deleteAccount`); doluysa hesap yolunun uçları 410. */
52
- deletedAt?: Ms;
53
- };
54
- type SubscriptionRow = {
55
- id: string;
56
- accountRef: string;
57
- priceId: string;
58
- providerSubscriptionRef: string;
59
- status: SubscriptionStatus;
60
- cancelAtPeriodEnd: boolean;
61
- cancelAt: Ms | null;
62
- cancelReason: string | null;
63
- canceledAt: Ms | null;
64
- startedAt: Ms;
65
- currentPeriodStart: Ms | null;
66
- currentPeriodEnd: Ms | null;
67
- dunningStartedAt: Ms | null;
68
- pastDueSince: Ms | null;
69
- dunningStep: number;
70
- nextDunningAt: Ms | null;
71
- /**
72
- * Sağlayıcıya giden son "ödemeyi yeniden dene" (portal ya da dunning adımı). Servis bunu
73
- * denetim izinden okur (`lastPaymentRetryAt`); portal sıklık sınırı (F3a) buna bakar.
74
- */
75
- lastPaymentRetryAt: Ms | null;
76
- };
77
- /** Hosted müşteri portalı oturumu (F3a; servisin `portal_sessions`). Satır değişmez; süresi geçince silinir. */
78
- type PortalSessionRow = {
79
- id: string;
80
- accountRef: string;
81
- /** Sayfa anahtarı (`url`deki `k`; sahtede düz saklanır, servis yalnızca sha256'sını). */
82
- pageKey: string;
83
- locale: "tr" | "en";
84
- /** "Ürüne dön"; verilmediyse null (sayfa `settings.appUrl`e döner). */
85
- returnUrl: string | null;
86
- actorRef: string;
87
- expiresAt: Ms;
88
- createdAt: Ms;
89
- };
90
- type SessionRow = {
91
- id: string;
92
- accountRef: string;
93
- priceId: string;
94
- status: CheckoutSession["status"];
95
- locale: string;
96
- /** Success URL (with placeholders, if any). */
97
- successUrl: string;
98
- /** Hosted: "Vazgeç" hedefi; verilmediyse null (dönüş `settings.appUrl`). */
99
- cancelUrl: string | null;
100
- /** Hosted: onaylatılacak belgeler. */
101
- consentDocs: {
102
- document: string;
103
- version: string;
104
- url: string;
105
- }[];
106
- /** Hosted: ürünün ön doldurması; oturum kapanınca silinir (servis K21). */
107
- prefill: CheckoutPrefill | null;
108
- /** Hosted sayfa anahtarı (`url`deki `k`; sahtede düz saklanır); oturum kapanınca null. */
109
- pageKey: string | null;
110
- consents: Consent[];
111
- actorRef: string | null;
112
- failureReason: string | null;
113
- subscriptionId: string | null;
114
- expiresAt: Ms;
115
- createdAt: Ms;
116
- completedAt: Ms | null;
117
- };
118
- type PaymentRow = {
119
- id: string;
120
- subscriptionId: string;
121
- providerOrderRef: string;
122
- status: "succeeded" | "failed";
123
- attempt: number;
124
- amountMinor: number;
125
- currency: string;
126
- periodStart: Ms | null;
127
- periodEnd: Ms | null;
128
- occurredAt: Ms;
129
- createdAt: Ms;
130
- };
131
- type InvoiceRow = {
132
- id: string;
133
- accountRef: string;
134
- subscriptionId: string | null;
135
- paymentId: string | null;
136
- status: Invoice["status"];
137
- number: string | null;
138
- currency: string;
139
- subtotalMinor: number;
140
- taxMinor: number;
141
- totalMinor: number;
142
- taxRateBps: number;
143
- buyer: BillingProfile;
144
- lines: Invoice["lines"];
145
- externalRef: string | null;
146
- issuedAt: Ms | null;
147
- createdAt: Ms;
148
- document: {
149
- bytes: Uint8Array;
150
- sha256: string;
151
- } | null;
152
- /** Manuel fatura (F4f); ödemeli faturada null. */
153
- dueAt?: Ms | null;
154
- note?: string | null;
155
- voidedAt?: Ms | null;
156
- voidReason?: string | null;
157
- };
158
- type GrantRow = {
159
- id: string;
160
- accountRef: string;
161
- planCode: string | null;
162
- overrides: Record<string, EntitlementValue>;
163
- reason: string;
164
- actorRef: string | null;
165
- startsAt: Ms;
166
- endsAt: Ms | null;
167
- revokedAt: Ms | null;
168
- createdAt: Ms;
169
- startApplied: boolean;
170
- endApplied: boolean;
171
- };
172
- type DeliveryRow = {
173
- status: "pending" | "delivered" | "dead";
174
- attempts: number;
175
- lastHttpStatus: number | null;
176
- lastError: string | null;
177
- nextAttemptAt: Ms;
178
- deliveredAt: Ms | null;
179
- };
180
- /** Yönetim ucuyla açılan endpoint (`admin.ts`): yalnızca kayıt, teslimat yok; sır saklanmaz. */
181
- type AdminEndpointRow = {
182
- id: string;
183
- url: string;
184
- status: "active" | "inactive";
185
- eventTypes: EventType[];
186
- description: string | null;
187
- createdAt: Ms;
188
- rotatedAt: Ms | null;
189
- };
190
- type EventRow = {
191
- id: string;
192
- accountRef: string;
193
- type: EventType;
194
- /** Servisin outbox'taki gövdesi: eski tiplerde de `data.account` tam durum. */
195
- payload: BillingEvent;
196
- /** Endpoint yoksa ya da filtresi tipi içermiyorsa null. */
197
- delivery: DeliveryRow | null;
198
- };
199
- type World = {
200
- readonly productCode: string;
201
- /** Ürün ayarları (`GET/PATCH /v1/admin/settings`; checkout TTL ve dönüş origin'i buradan). */
202
- settings: ProductSettings;
203
- /**
204
- * true: dönüş origin'i ayarlanana kadar (`appUrl`/`extraReturnOrigins` boş ve yamada
205
- * verilmedi) every return URL is accepted — a fake convenience; the service requires the setting.
206
- */
207
- permissiveReturnOrigins: boolean;
208
- adminEndpoints: AdminEndpointRow[];
209
- readonly dunningPolicy: FakeDunningPolicy;
210
- /** Endpoint'in aldığı tipler; webhook yoksa null. */
211
- readonly endpoint: {
212
- readonly id: string;
213
- readonly types: ReadonlySet<string>;
214
- } | null;
215
- features: FeatureDef[];
216
- plans: Map<string, PlanRow>;
217
- prices: PriceRow[];
218
- defaultPlanCode: string | null;
219
- accounts: Map<string, AccountRow>;
220
- subscriptions: SubscriptionRow[];
221
- sessions: SessionRow[];
222
- portalSessions: PortalSessionRow[];
223
- payments: PaymentRow[];
224
- invoices: InvoiceRow[];
225
- grants: GrantRow[];
226
- events: EventRow[];
227
- now(): Ms;
228
- /** Saati ileri alır (geri almaz). */
229
- setNow(ms: Ms): void;
230
- /** Saate göre monoton UUIDv7. */
231
- id(): string;
232
- };
233
- declare namespace operations_d_exports {
234
- export { Failure, PORTAL_CANCEL_REASON, PORTAL_INVOICE_LIMIT, PORTAL_RETRY_INTERVAL_MS, PortalActionResult, PortalView, Result, accountDetail, advanceTo, applyRenewalPayment, cancelCheckout, cancelSubscription, checkoutSessionResponse, completeCheckout, createCheckoutSession, createGrant, createPortalSession, customerActorRef, deleteAccount, failCheckout, hostedPageUrl, hostedPortalUrl, issueInvoice, livePortalSession, openHostedSession, openPortalSession, portalCancel, portalInvoiceDocument, portalRetryPayment, portalView, redeliverEvent, refreshAccounts, resyncAccount, revokeGrant, sessionRow, setPlan, stats, syncCatalog, updatePortalProfile, upsertAccount, validatePortalProfile };
235
- }
236
- type Failure = {
237
- ok: false;
238
- code: ErrorCode;
239
- message?: string;
240
- };
241
- type Result<T> = {
242
- ok: true;
243
- value: T;
244
- } | Failure;
245
- type CatalogInput = z.output<typeof CatalogSyncInputSchema>;
246
- type UpsertInput = z.output<typeof AccountUpsertInputSchema>;
247
- type CheckoutInput = CheckoutSessionCreateParsed;
248
- type CancelInput = z.output<typeof CancelSubscriptionInputSchema>;
249
- type GrantInput = z.output<typeof GrantCreateInputSchema>;
250
- type IssueInput = z.output<typeof InvoiceIssueInputSchema>;
251
- type PlanSetInput = z.output<typeof PlanSetInputSchema>;
252
- /** `syncCatalogWithProvider`: K4 tamlığı, farkın uygulanması, etkilenen hesapların yenilenmesi. */
253
- declare function syncCatalog(w: World, input: CatalogInput): Result<CatalogSyncResult>;
254
- /** `refreshAccounts` (`POST /v1/admin/accounts/refresh`). */
255
- declare function refreshAccounts(w: World): AccountsRefreshResult;
256
- declare function upsertAccount(w: World, ref: string, input: UpsertInput): {
257
- account: AccountUpsertResponse;
258
- created: boolean;
259
- };
260
- declare function accountDetail(w: World, ref: string, include: readonly AccountInclude[]): AccountDetail | null;
261
- /** Hosted checkout sayfası (servisin `hostedCheckoutUrl`); sahtede `hosted.ts` sunar. */
262
- declare const hostedPageUrl: (baseUrl: string, id: string, pageKey: string) => string;
263
- /**
264
- * `createHostedCheckoutSession` (service): no provider call; validation order and codes match the
265
- * service (account, return origins, live subscription, sellable price). A missing account is
266
- * opened with `displayName`. `url` is the fake steward's hosted page (`hosted.ts`).
267
- */
268
- declare function createCheckoutSession(w: World, baseUrl: string, ref: string, input: CheckoutInput, actorRef: string): Result<CheckoutSessionCreated>;
269
- declare function checkoutSessionResponse(w: World, id: string): CheckoutSessionResponse | null;
270
- declare function sessionRow(w: World, id: string): SessionRow;
271
- /** Hosted oturumun sayfası açık mı: anahtar bu oturumun, oturum açık ve süresi geçmemiş (servis `openSession`). */
272
- declare function openHostedSession(w: World, id: string, pageKey: string): SessionRow | null;
273
- /** `completeCheckoutReturn` başarısızlık yolu: yalnızca `open` oturum kapanır. */
274
- declare function failCheckout(w: World, session: SessionRow, reason: string): void;
275
- /**
276
- * Hosted sayfada vazgeç (`HostedCheckoutPort.cancel`; sahte sayfada sağlayıcı formu olmadığından
277
- * her zaman kapanır): yalnızca açık oturum; `canceled`, iç neden `checkout.canceled`. Dönüş
278
- * adresi `cancelUrl ?? settings.appUrl` (yoksa null). Açık olmayan oturumda değişiklik yok.
279
- */
280
- declare function cancelCheckout(w: World, session: SessionRow): string | null;
281
- /** `completeCheckoutReturn` başarı yolu: abonelik, ilk tahsilat, event'ler, taslak fatura. */
282
- declare function completeCheckout(w: World, session: SessionRow): void;
283
- declare function issueInvoice(w: World, id: string, input: IssueInput): Result<InvoiceIssueResponse>;
284
- declare function cancelSubscription(w: World, id: string, input: CancelInput, actorRef: string): Result<CancelSubscriptionResponse>;
285
- declare function createGrant(w: World, ref: string, input: GrantInput, actorRef: string): Result<GrantCreateResponse>;
286
- /** Zaten iptal edilmiş grant: idempotent başarı. */
287
- declare function revokeGrant(w: World, id: string): boolean;
288
- /**
289
- * `setPlan` (K6): aktif plan grant'leri (henüz başlamamışlar dahil; override
290
- * grant'leri hariç) iptal + yeni plan grant'i + `commitAccountChange(grant.plan_set)`.
291
- * Tek aktif plan grant'i aynı plan/`endsAt`/`overrides` ise korunur. Canlı abonelik
292
- * planı hak kuralında hedefi geçiyorsa `strict` → `subscription_plan_higher` (yazım
293
- * yok), `ensure` → uyarı. Sahtede eşzamanlılık yok (servis advisory lock'la sıralar).
294
- */
295
- declare function setPlan(w: World, ref: string, input: PlanSetInput, actorRef: string): Result<PlanSetResponse>;
296
- /** `resyncAccount`: saklı durum `account.state_changed` (`cause: "resync"`) olarak; version aynı. */
297
- declare function resyncAccount(w: World, ref: string): Result<ResyncResult>;
298
- /**
299
- * `deleteAccount` (`domain/account-deletion.ts`, F4e): önkoşullar sırayla (hesap yok 404,
300
- * silinmiş 410, canlı abonelik) ve hiçbiri tutmazsa değişiklik yok. The service's
301
- * `checkout_in_progress` (open provider form) never happens here: the fake hosted page has no
302
- * provider form, so open sessions are formless and deletion closes them. Sonra anonimleştirme:
303
- * ad/metadata/profil, oturumların ön doldurması/anahtarı ve onay izinin `ipHash`/`userAgent`'ı,
304
- * portal oturumları, aktif grant'ler; eski event yüklerinde `displayName`. Faturalar kalır.
305
- */
306
- declare function deleteAccount(w: World, ref: string, actorRef: string): Result<AccountDeleteResponse>;
307
- declare function stats(w: World): Stats;
308
- /** Portal sayfası (servisin `hostedPortalUrl`); sahtede `portal.ts` sunar. */
309
- declare const hostedPortalUrl: (baseUrl: string, id: string, pageKey: string) => string;
310
- declare const PORTAL_CANCEL_REASON = "customer_portal";
311
- /** Abonelik başına portal "yeniden dene" aralığı (sağlayıcıya giden son retry'dan itibaren; servisle aynı). */
312
- declare const PORTAL_RETRY_INTERVAL_MS: number;
313
- declare const PORTAL_INVOICE_LIMIT = 24;
314
- /** Portal aksiyonlarının aktörü (servisin `customerActorRef`). */
315
- declare const customerActorRef: (accountRef: string) => string;
316
- /**
317
- * Portal aksiyonunun sonucu: `ok` ya da servisin portal portundaki `not_allowed` nedeni
318
- * (değişiklik yok). Sahte sağlayıcı hata vermediği için `provider_error` yok.
319
- */
320
- type PortalActionResult = "ok" | "no_subscription" | "already_scheduled" | "nothing_to_retry" | "no_failed_payment" | "retry_too_soon";
321
- type PortalSessionInput = z.output<typeof PortalSessionCreateInputSchema>;
322
- /**
323
- * `createPortalSession`: hesap yoksa `account_not_found` (checkout'taki gibi açılmaz), `returnUrl`
324
- * origin'i izinli değilse `return_url_not_allowed`; dil verilmezse `defaultLocale`, süre
325
- * `portalTtlMinutes`. Anahtar 32 bayt base64url. Durum değişmez, event yok.
326
- */
327
- declare function createPortalSession(w: World, baseUrl: string, ref: string, input: PortalSessionInput, actorRef: string): Result<PortalSession>;
328
- /** Süresi geçmemiş portal oturumu (anahtarsız; `simulate`). Yoksa null. */
329
- declare function livePortalSession(w: World, id: string): PortalSessionRow | null;
330
- /** Servisin `validSession`'ı: bilinmeyen id, yanlış anahtar ve süresi geçmiş oturum AYNI sonuç (null). */
331
- declare function openPortalSession(w: World, id: string, pageKey: string): PortalSessionRow | null;
332
- type PortalView = {
333
- session: PortalSessionRow;
334
- account: AccountRow;
335
- state: AccountState;
336
- planName: string;
337
- subscription: {
338
- row: SubscriptionRow;
339
- price: PriceRow;
340
- planName: string;
341
- canCancel: boolean;
342
- canRetryPayment: boolean;
343
- } | null;
344
- /** En yeni önce, en çok 24 (ödemeli taslak dahil; manuel taslak yok). */
345
- invoices: InvoiceRow[];
346
- /** `returnUrl ?? settings.appUrl`; yoksa null. */
347
- returnUrl: string | null;
348
- };
349
- /** Servisin portal `load` görünümü (sayfa için). */
350
- declare function portalView(w: World, session: PortalSessionRow): PortalView;
351
- /**
352
- * Portal iptali (`HostedPortalPort.cancelAtPeriodEnd`): canlı abonelik dönem sonunda
353
- * (`cancelSubscription`, neden `customer_portal`, aktör `customer:<ref>`; `/v1` iptaliyle aynı
354
- * kurallar ve event'ler). Zaten planlıysa `already_scheduled` (iz/event yok).
355
- */
356
- declare function portalCancel(w: World, session: PortalSessionRow): PortalActionResult;
357
- /**
358
- * Portal "ödemeyi yeniden dene" (`HostedPortalPort.retryPayment`): past_due/suspended abonelikte
359
- * son başarısız sipariş sahte sağlayıcıya gönderilmiş sayılır — DURUM DEĞİŞMEZ, event yok;
360
- * tahsilatın sonucu servisteki gibi sonradan gelir (`simulate.renewal(ref)` aynı siparişi
361
- * başarılı/`fail` sayar). Abonelik başına 10 dakikada bir (portal ya da dunning retry'ı).
362
- */
363
- declare function portalRetryPayment(w: World, session: PortalSessionRow): PortalActionResult;
364
- /**
365
- * Servisin `validateProfile`'ı (hosted-checkout.ts `checkProfile`): alan anahtarları
366
- * `profile.<alan>`, alan başına ilk kod; öncelik required > invalid_kind > invalid_characters >
367
- * şema kodları > VKN/E.164. Değer koda girmez.
368
- */
369
- declare function validatePortalProfile(input: Record<string, unknown>): {
370
- ok: true;
371
- profile: BillingProfile;
372
- } | {
373
- ok: false;
374
- fieldErrors: Record<string, string>;
375
- };
376
- /**
377
- * Portal profil güncellemesi (`HostedPortalPort.updateProfile`): ülke verilmezse saklı değer
378
- * korunur (yoksa TR); bireyselde kurumsal alanlar düşer. Durumda yalnızca profilin varlığı ve
379
- * türü olduğundan event yalnızca bunlar değişince (`billing_profile.updated`).
380
- */
381
- declare function updatePortalProfile(w: World, session: PortalSessionRow, input: Record<string, unknown>): {
382
- ok: true;
383
- } | {
384
- ok: false;
385
- fieldErrors: Record<string, string>;
386
- };
387
- /** Portal belge indirme: yalnızca oturumun hesabının kesilmiş ve belgeli faturası; yoksa null. */
388
- declare function portalInvoiceDocument(w: World, session: PortalSessionRow, invoiceId: string): {
389
- bytes: Uint8Array;
390
- filename: string;
391
- } | null;
392
- /** Requeues the event's delivery (dead or delivered included); `false` if there is no such event. */
393
- declare function redeliverEvent(w: World, id: string): boolean;
394
- /**
395
- * Tahsilat sonucu. Dunning'deki abonelikte AYNI başarısız siparişin yeniden
396
- * denemesidir (iyzico retry'ı; servisin `existingPayment` yolu), aksi halde
397
- * mevcut dönem sonundan başlayan yeni sipariş.
398
- */
399
- declare function applyRenewalPayment(w: World, sub: SubscriptionRow, outcome: "succeeded" | "failed"): void;
400
- /** Saati `target`a ilerletir; her zamanlanmış iş kendi anında koşar. */
401
- declare function advanceTo(w: World, target: Ms): void;
402
- //#endregion
403
- //#region src/testing/fake-steward.d.ts
404
- /** Sahte steward'ın teslimat yaptığı ürün alıcısı. */
405
- type FakeWebhookHandler = (req: Request) => Response | Promise<Response>;
406
- type FakeWebhookOptions = {
407
- /** İmza sırrı; dizi verilirse rotasyondaki gibi hepsiyle imzalanır. */
408
- secret: string | readonly string[];
409
- /** Ürünün alıcısı, ör. `(req) => webhooks.handle(req)`. Verilmezse `fake.connect(handler)` ile sonradan. */
410
- handler?: FakeWebhookHandler;
411
- /**
412
- * Endpoint filtresi. Verilmezse `["account.state_changed"]` (yönetim ucunun yeni ürüne
413
- * varsayılanı); `"legacy"`: `LEGACY_EVENT_TYPES` (pod CLI `add-endpoint`'in NULL filtresi, 15 eski tip).
414
- */
415
- eventTypes?: readonly EventType[] | "legacy";
416
- /** İsteğin adresi (yalnızca `Request.url`). */
417
- url?: string;
418
- };
419
- type FakeStewardOptions = {
420
- /** Oluşturmada senkronlanan katalog. Verilmezse katalog uçları `catalog_not_configured`, hesap açılışı 500 (servis gibi). */
421
- catalog?: CatalogSyncInput | {
422
- toSyncInput(): CatalogSyncInput;
423
- };
424
- /** Ürün kapsamlı anahtar; verilmezse `stw_…` biçiminde üretilir. */
425
- apiKey?: string;
426
- /** Admin kapsamlı anahtar; verilmezse üretilir. */
427
- adminApiKey?: string;
428
- /** Varsayılan `http://steward.test`. Bu tabanın dışındaki istekler ağ hatası alır. */
429
- baseUrl?: string;
430
- /** Event'lerin `product` alanı ve `/v1/me`. Varsayılan `example`. */
431
- productCode?: string;
432
- /** Sahte saatin kaynağı; `simulate.advance`/`renewal` bunun üstüne ekler. Varsayılan gerçek saat. */
433
- now?: () => Date;
434
- webhook?: FakeWebhookOptions;
435
- /**
436
- * Başlangıç ürün ayarları (`PATCH /v1/admin/settings` yamasıyla aynı biçim). Sağlayıcı
437
- * her zaman sahte (`provider: "fake"`). Dönüş origin'i (`appUrl`, `extraReturnOrigins`,
438
- * `returnOrigins`) is never given or patched, every return URL (`successUrl`, `cancelUrl`,
439
- * portal `returnUrl`) is accepted.
440
- */
441
- settings?: ProductSettingsPatch;
442
- /** Allowed return origins for checkout and portal = `settings.extraReturnOrigins` (cannot be given together). */
443
- returnOrigins?: readonly string[];
444
- /** = `settings.checkoutTtlMinutes`; default 30. */
445
- checkoutTtlMinutes?: number;
446
- /** Varsayılan servisinki: `dryRun: true` (adımlar sayılır, askı/sonlandırma yok). */
447
- dunningPolicy?: FakeDunningPolicy;
448
- /** `fake.steward` ek ayarları (bağlantı ayarları sahteden gelir). */
449
- steward?: Omit<StewardOptions, "baseUrl" | "apiKey" | "adminBaseUrl" | "adminApiKey" | "fetch" | "env">;
450
- /** 500'e dönüşen iç hatalar (servis gibi). Varsayılan `console`. */
451
- logger?: {
452
- error(message: string): void;
453
- };
454
- };
455
- /** Sahteye gelen istek (sırasıyla). `status` 0: ağ hatası (kesinti ya da taban dışı adres). */
456
- type FakeRequest = {
457
- method: string;
458
- url: string;
459
- /** Tabana göre yol + sorgu, ör. `/v1/accounts/org_1/state`. */
460
- path: string;
461
- headers: Record<string, string>;
462
- body: string | null;
463
- status: number;
464
- };
465
- type FakeDelivery = {
466
- event: BillingEvent;
467
- body: string;
468
- headers: Record<string, string>;
469
- response: Response;
470
- };
471
- type FakeDeliverOptions = {
472
- ref: string;
473
- /** `account.state_changed` için `detail.cause`; varsayılan `account.refreshed`. */
474
- cause?: string;
475
- /** Aynı event (aynı id ve gövde) ikinci kez. */
476
- duplicate?: boolean;
477
- /** Güncel event'ten sonra bir önceki version'ın durumuyla eski bir event. */
478
- outOfOrder?: boolean;
479
- };
480
- /** `simulate.portalCancel/portalRetryPayment` sonucu. */
481
- type FakePortalActionResult = {
482
- /**
483
- * `ok` ya da servisin portal portundaki `not_allowed` nedeni (hiçbir şey değişmedi):
484
- * `no_subscription`, `already_scheduled` (iptal), `nothing_to_retry` / `no_failed_payment` /
485
- * `retry_too_soon` (yeniden dene). Sayfa bunları `error=` koduna eşler.
486
- */
487
- result: PortalActionResult;
488
- /** İşlem sonrası hesap durumu. */
489
- account: AccountState;
490
- };
491
- /** `simulate.completeHostedCheckout` sonucu. */
492
- type FakeHostedCheckoutResult = {
493
- /** Oturum id'si (`url`'den). */
494
- id: string;
495
- /** Sayfanın 303 yönlendirdiği adres: `successUrl`, yer tutucular servisle aynı kuralla dolu. */
496
- redirectUrl: string;
497
- /** İşlem sonrası oturum (`completed` ya da `failed`; `completed`'da `account`). */
498
- session: CheckoutSessionResponse;
499
- };
500
- type FakeSimulate = {
501
- /**
502
- * Sağlayıcı formu ödendi: abonelik, ilk tahsilat, fatura taslağı, event'ler. Açık olmayan
503
- * oturumda değişiklik yok. Hosted oturumda önce sayfanın `details` izi yazılır (profil yoksa
504
- * ön doldurmadan sahte profil, onay izi; `billing_profile.updated`).
505
- */
506
- checkoutCompleted(sessionId: string): Promise<CheckoutSessionResponse>;
507
- /** Kart reddedildi (`fake:card_declined`). */
508
- checkoutFailed(sessionId: string, options?: {
509
- reason?: string;
510
- }): Promise<CheckoutSessionResponse>;
511
- /**
512
- * Hosted checkout'u açılış yanıtındaki `url`'den tarayıcı gibi sürer (F2b): sahte sayfayı açar
513
- * (`fake.fetch`, `fake.requests`'e yazılır), "Tamamla" (`outcome: "succeeded"`, varsayılan) ya da
514
- * "Reddet" gönderir, 303 dönüş adresini verir. Sonuç `checkoutCompleted/Failed` ile aynıdır.
515
- * Sayfa 404 (bilinmeyen, kapalı ya da süresi geçmiş oturum, yanlış anahtar) ya da kesinti fırlatır.
516
- */
517
- completeHostedCheckout(url: string, options?: {
518
- outcome?: "succeeded" | "failed";
519
- }): Promise<FakeHostedCheckoutResult>;
520
- /**
521
- * Müşteri hosted sayfada vazgeçti (F2b): oturum `canceled`, iç neden `checkout.canceled`
522
- * (eski tipli event yok). Yalnızca hosted oturum; açık olmayan oturumda değişiklik yok.
523
- */
524
- checkoutCanceled(sessionId: string): Promise<CheckoutSessionResponse>;
525
- /**
526
- * Yenileme tahsilatı. Saat önce `advanceDays` kadar, verilmezse dönem sonuna
527
- * ilerler (arada zamanlanmış işler koşar). Başarı → `subscription.renewed`
528
- * (+fatura; dunning'deyse `subscription.reactivated`), `fail` →
529
- * `subscription.payment_failed`, `past_due`, dunning başlar. Dunning'deki
530
- * abonelikte aynı başarısız siparişin yeniden denemesidir.
531
- */
532
- renewal(ref: string, options?: {
533
- advanceDays?: number;
534
- fail?: boolean;
535
- }): Promise<AccountState>;
536
- /**
537
- * Müşteri portalda "Dönem sonunda iptal"i onayladı (F3a; sayfanın `cancel` + `confirm=1`
538
- * adımıyla aynı işlem): canlı abonelik dönem sonunda iptal edilir — `subscriptions.cancel`
539
- * (`at_period_end`) ile aynı kurallar ve event'ler (`subscription.cancel_scheduled`,
540
- * `account.state_changed`), neden `customer_portal`, aktör `customer:<ref>`. Zaten planlıysa
541
- * `already_scheduled`, abonelik yoksa `no_subscription` (değişiklik yok). Bilinmeyen ya da
542
- * süresi geçmiş oturum fırlatır (sayfa 404 verirdi).
543
- */
544
- portalCancel(portalSessionId: string): Promise<FakePortalActionResult>;
545
- /**
546
- * Müşteri portalda "Ödemeyi yeniden dene"ye bastı (F3a): past_due/suspended abonelikte istek
547
- * kabul edilir (`ok`) ama DURUM DEĞİŞMEZ — servisteki gibi tahsilatın sonucu sonradan gelir:
548
- * `renewal(ref)` aynı başarısız siparişi başarılı sayar (`subscription.reactivated`),
549
- * `renewal(ref, {fail: true})` yine başarısız. Abonelik başına 10 dakikada bir (`retry_too_soon`;
550
- * saat `advance` ile ilerler); aktif abonelikte `nothing_to_retry`. Bilinmeyen ya da süresi
551
- * geçmiş oturum fırlatır.
552
- */
553
- portalRetryPayment(portalSessionId: string): Promise<FakePortalActionResult>;
554
- /** Saati ilerletir; her zamanlanmış iş kendi anında koşar. Süresiz çağrı yalnızca vadesi gelenleri koşar. */
555
- advance(duration?: {
556
- days?: number;
557
- hours?: number;
558
- minutes?: number;
559
- }): Promise<void>;
560
- /** `network`: fetch `TypeError("fetch failed")` ile reddeder; `503`: `database_unavailable` (tekrar denenebilir). */
561
- outage(on: boolean, options?: {
562
- mode?: "network" | "503";
563
- }): void;
564
- /** Hesabın GÜNCEL durumuyla `type` event'ini alıcıya gönderir (outbox'a yazılmaz, filtre uygulanmaz). */
565
- deliver(type: EventType, options: FakeDeliverOptions): Promise<FakeDelivery[]>;
566
- /** Bekleyen (teslim edilmemiş) outbox event'lerini sırayla alıcıya gönderir. */
567
- flush(): Promise<FakeDelivery[]>;
568
- /**
569
- * Operator redelivery (the service's pod CLI `redeliver-event <product> <eventId>`): the event's
570
- * delivery is requeued with attempts reset, the next `flush()` sends the same id and body again.
571
- * Throws for an unknown event id. There is no product HTTP API for this.
572
- */
573
- redeliver(eventId: string): void;
574
- };
575
- type FakeSteward = {
576
- readonly baseUrl: string;
577
- readonly apiKey: string;
578
- readonly adminApiKey: string;
579
- readonly fetch: typeof fetch;
580
- readonly steward: Steward;
581
- readonly requests: readonly FakeRequest[];
582
- readonly simulate: FakeSimulate;
583
- /**
584
- * Webhook alıcısını bağlar ya da değiştirir (`webhook.handler` yerine): sahte steward ürün
585
- * uygulamasından önce kurulur, uygulama `fake.steward`/`fake.fetch` ile oluşturulup sonra bağlanır.
586
- * `webhook` seçeneği (sır, filtre) verilmemişse fırlatır.
587
- */
588
- connect(handler: FakeWebhookHandler): void;
589
- /** Published events in publish order (the outbox; legacy types carry the full state too). */
590
- events(ref?: string): readonly BillingEvent[];
591
- /** Sahte saat. */
592
- now(): Date;
593
- };
594
- export declare function createFakeSteward(options?: FakeStewardOptions): FakeSteward;
595
- //#endregion
596
- //#region src/testing/signed-event.d.ts
597
- type SignedEventOverrides<T extends EventType = EventType> = {
598
- id?: string;
599
- apiVersion?: string;
600
- createdAt?: string;
601
- product?: string;
602
- accountRef?: string;
603
- data?: {
604
- /** Fixture'ın hesabına sığ birleşir; tam `AccountState` verilebilir (F1+ sunucu eski tiplere de koyar). */
605
- account?: Partial<AccountState>;
606
- detail?: Partial<EventDetail<T>>;
607
- };
608
- };
609
- type SignedEventOptions = {
610
- /** İmza sırları (`yeni,eski` rotasyonu için dizi). Verilmezse `STEWARD_WEBHOOK_SECRET`. */
611
- secret?: string | readonly string[];
612
- /** Unix saniye; varsayılan şimdi. */
613
- timestamp?: number;
614
- };
615
- type SignedEvent<T extends EventType = EventType> = {
616
- event: BillingEventOf<T>;
617
- /** Ham gövde (imzalanan metin). */
618
- body: string;
619
- /** İmza başlıkları + `content-type`. */
620
- headers: Record<string, string>;
621
- /** Alıcıya verilecek `POST` isteği (her çağrıda yeni `Request`). */
622
- request(url?: string): Request;
623
- };
624
- export declare function signedEvent<T extends EventType>(type: T, overrides?: SignedEventOverrides<T>, options?: SignedEventOptions): SignedEvent<T>;
625
- //#endregion
626
- export type { FakeDeliverOptions, FakeDelivery, FakeDunningPolicy, FakeHostedCheckoutResult, FakePortalActionResult, FakeRequest, FakeSimulate, FakeSteward, FakeStewardOptions, FakeWebhookHandler, FakeWebhookOptions, SignedEvent, SignedEventOptions, SignedEventOverrides };