@stewardhq/sdk 0.5.0 → 0.7.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.
- package/LICENSE +201 -0
- package/README.md +247 -200
- package/dist/_chunks/errors.js +1 -1
- package/dist/_chunks/events.d.ts +133 -122
- package/dist/_chunks/events.js +45 -7
- package/dist/_chunks/index.d.ts +1308 -594
- package/dist/_chunks/locale.d.ts +42 -3
- package/dist/_chunks/src.js +379 -26
- package/dist/_chunks/validators.d.ts +2 -2
- package/dist/_chunks/webhook-core.d.ts +2 -2
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +3 -3
- package/dist/index.d.ts +24 -24
- package/dist/index.js +66 -5
- package/dist/server.d.ts +32 -20
- package/dist/server.js +7 -3
- package/package.json +14 -8
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { $ as
|
|
1
|
+
import { $ as emailLocaleOf, $t as MeteredPriceSchema, A as SubscriptionStatusSchema, An as hasControlCharacters, At as METER_FILTER_MAX_CONDITIONS, B as EmailSenderSchema, Bn as EntitlementsSchema, Bt as MeterCreditEntryKindSchema, C as AccountSchema, Cn as EventNameSchema, Ct as DEFAULT_METER_LOW_AT, D as BillingProfileKindSchema, Dn as IngestEventSchema, Dt as METER_AGGREGATION_KINDS, E as AccountUpsertInputSchema, En as INGEST_REJECT_CODES, Et as MAX_METER_UNITS, F as EMAIL_LOCALES, Fn as CodeSchema, Ft as MeterAggregationSchema, G as InvoicePaymentDueEmailSchema, Gn as INVOICE_PAYMENT_STATUSES, Gt as MeterLabelSchema, H as EmailSettingsSchema, Hn as ErrorResponseSchema, Ht as MeterCreditPropertiesSchema, I as EMAIL_PAYLOAD_SCHEMAS, In as CurrencySchema, It as MeterChargeLineSchema, J as NotificationEmailsSchema, Jn as InvoiceBillingReasonSchema, Jt as MeterPeriodSchema, K as MAX_NOTIFICATION_EMAILS, Kn as IdSchema, Kt as MeterLowAtSchema, L as EMAIL_TEMPLATES, Ln as DateTimeSchema, Lt as MeterChargeListSchema, M as BILLING_PATH_PLACEHOLDERS, Mn as API_VERSION, Mt as METER_FILTER_OPERATORS, N as BankTransferInstructionsEmailSchema, Nn as ActorRefSchema, Nt as METER_PERIOD_STATUSES, O as BillingProfileSchema, On as IngestRejectCodeSchema, Ot as METER_CHARGE_STATUSES, P as BillingPathSchema, Pn as AmountMinorSchema, Pt as METER_STANDINGS, Q as billingPageUrl, Qt as MeteredPriceDefSchema, R as EMAIL_TEMPLATE_BY_EVENT, Rn as ERROR_CATEGORIES, Rt as MeterChargeSchema, S as AccountScheduledChangeSchema, Sn as EventMetadataValueSchema, St as CreditGrantInputSchema, T as AccountSubscriptionStateSchema, Tn as EventsIngestResultSchema, Tt as MAX_METERED_PRICE_PER_UNITS, U as EmailTemplateSchema, Un as ExternalRefSchema, Ut as MeterDefSchema, V as EmailSettingsPatchSchema, Vn as ErrorCategorySchema, Vt as MeterCreditEntrySchema, W as EmailTemplateSettingsSchema, Wn as INVOICE_BILLING_REASONS, Wt as MeterFilterSchema, X as PriceChangeNoticeMeteredRateSchema, Xn as MetadataSchema, Xt as MeterStandingSchema, Y as PriceChangeNoticeEmailSchema, Yn as InvoicePaymentStatusSchema, Yt as MeterPeriodStatusSchema, Z as applyEmailSettingsPatch, Zt as MeterUnitsSchema, _ as AccountMeterStateSchema, _n as EVENT_TIMESTAMP_MAX_AGE_DAYS, _t as isFeatureFlagBenefit, a as EVENT_TYPES, an as fromMicroUnits, at as uniqueEmails, b as AccountOpenInvoiceSchema, bn as EventMetadataKeySchema, bt as AccountMetersSchema, c as LEGACY_EVENT_TYPES, cn as parseMicroUnits, ct as BenefitDefSchema, d as isEventType, dn as EVENTS_INGEST_MAX_BYTES, dt as BenefitTypeSchema, en as canonicalMeterFilter, et as emailRecipients, f as ACCOUNT_INCLUDES, fn as EVENTS_INGEST_MAX_EVENTS, ft as CatalogBenefitSchema, g as AccountLocaleSchema, gn as EVENT_NAME_MAX_LENGTH, gt as featureValueMatchesType, h as AccountDunningStateSchema, hn as EVENT_METADATA_STRING_MAX_LENGTH, ht as MeterCreditBenefitDefSchema, i as EVENT_DETAIL_SCHEMAS, in as UNIT_DECIMALS, it as liveSubscriptionOf, j as SubscriptionSummarySchema, jn as isEventTimestampInRange, jt as METER_FILTER_MAX_DEPTH, k as EntitlementSnapshotSchema, kn as IngestRejectionSchema, kt as METER_CREDIT_ENTRY_KINDS, l as PING_EVENT_TYPE, ln as plainDecimalOf, lt as BenefitDescriptionSchema, m as AccountDeleteResponseSchema, mn as EVENT_METADATA_MAX_PAIRS, mt as FeatureFlagPropertiesSchema, n as ApiVersionSchema, nn as InvalidUnitValueError, nt as emailTemplateSettings, o as EventIdSchema, on as isMicroPrecise, ot as AccountBenefitSchema, p as AccessStateSchema, pn as EVENT_METADATA_KEY_MAX_LENGTH, pt as FeatureFlagBenefitDefSchema, q as NoticedMeteredRateSchema, qn as IntervalSchema, qt as MeterPeriodListSchema, r as BillingEventSchema, rn as MICRO_UNITS_PER_UNIT, rt as isEmailRelevant, s as FULL_STATE_EVENT_TYPES, sn as microToDecimalString, st as BENEFIT_TYPES, t as AnyBillingEventSchema, tn as meterFilterClauseOf, tt as emailTemplateOf, u as PingSchema, un as toMicroUnits, ut as BenefitSourceSchema, v as AccountMetersStateSchema, vn as EVENT_TIMESTAMP_MAX_SKEW_MINUTES, vt as isMeterCreditBenefit, w as AccountStateSchema, wn as EventsIngestInputSchema, wt as DecimalUnitsStringSchema, x as AccountProfileStateSchema, xn as EventMetadataSchema, xt as CatalogMeterSchema, y as AccountOpenCheckoutSchema, yn as EventExternalIdSchema, yt as AccountMeterSchema, z as EmailExtraTextSchema, zn as EntitlementValueSchema, zt as MeterChargeStatusSchema } from "./_chunks/events.js";
|
|
2
|
+
import { $ as periodBoundsOf, $n as EventsSettingsSchema, $t as ApiKeySchema, A as WebhookEndpointCreateInputSchema, An as INDIVIDUAL_IDENTITY_PLACEHOLDER, Ar as METERED_PRICE_TAX_MISMATCH, At as InvoiceStatusSchema, B as PlanSetInputSchema, Bn as BillingSettingsSchema, Bt as GrantSchema, C as emailReadinessOf, Cn as CheckoutConsentInputSchema, Cr as CatalogSyncResultSchema, Ct as STEWARD_CAPABILITIES, D as EventTypeSchema, Dn as CheckoutSessionSchema, Dr as MAX_CATALOG_METERED_PRICES, Dt as InvoicePaymentSessionCreateInputSchema, E as DEFAULT_ENDPOINT_EVENT_TYPES, En as CheckoutSessionCreatedSchema, Er as MAX_CATALOG_BENEFITS, Et as InvoiceLineSchema, F as WebhookLastDeliverySchema, Fn as checkoutRedirectUrl, Ft as ManualInvoiceLineInputSchema, G as addUtcMonths, Gn as DEFAULT_EVENT_RETENTION_DAYS, Gt as SubscriptionSchema, H as PlanSetResponseSchema, Hn as BrandingSchema, Ht as PaymentSchema, I as WebhookSecretSchema, In as BankTransferPaymentDaysSchema, It as manualInvoiceTotals, J as matchesFilter, Jn as DEFAULT_MIN_INVOICE_MINOR, Jt as PortalSessionSchema, K as consumptionOf, Kn as DEFAULT_LATE_GRACE_MINUTES, Kt as PORTAL_SESSION_ERRORS, L as generateWebhookSecret, Ln as BankTransferSettingsPatchSchema, Lt as splitInclusiveTax, M as WebhookEndpointRotateInputSchema, Mn as PAYMENT_METHODS, Mr as PriceDefSchema, Mt as InvoiceWaiveInputSchema, N as WebhookEndpointSchema, Nn as PaymentMethodSchema, Nr as PriceSchema, Nt as MANUAL_INVOICE_MAX_AMOUNT_MINOR, O as WEBHOOK_ENDPOINT_STATUSES, On as CheckoutStatusSchema, Or as MAX_CATALOG_METERS, Ot as InvoicePaymentSessionSchema, P as WebhookEndpointStatusSchema, Pn as ProviderPayloadSchema, Pt as ManualInvoiceInputSchema, Q as overageOf, Qn as EventsSettingsPatchSchema, Qt as ApiKeyPrefixSchema, R as webhookEndpointUrlProblem, Rn as BankTransferSettingsSchema, Rt as CancelSubscriptionInputSchema, S as buildDoctorReport, Sn as CHECKOUT_ERRORS, Sr as CatalogSyncInputSchema, St as MeResponseSchema, T as hostedReadinessOf, Tn as CheckoutSessionCreateInputSchema, Tr as FeatureTypeSchema, Tt as InvoiceIssueInputSchema, U as PlanSetWarningSchema, Un as DEFAULT_BANK_TRANSFER_PAYMENT_DAYS, Ut as StatsSchema, V as PlanSetModeSchema, Vn as BrandingPatchSchema, Vt as MAX_GRANT_BENEFITS, W as ResyncResultSchema, Wn as DEFAULT_CHECKOUT_TTL_MINUTES, Wt as SubscriptionChangeInputSchema, X as meterCreditsOf, Xn as DEFAULT_PORTAL_TTL_MINUTES, Xt as ApiKeyCreateInputSchema, Y as meterChargeTotals, Yn as DEFAULT_PAYMENT_DUE_DAYS, Yt as API_KEY_SCOPES, Z as overageCapReached, Zn as EventRetentionDaysSchema, Zt as ApiKeyListSchema, _ as DoctorReportSchema, _n as RepriceItemSchema, _r as meteringSettingsOf, _t as HEADER_SDK, a as DOCTOR_REQUIRED_LEGAL_LINKS, an as BankTransferListStatusSchema, ar as PaymentDueDaysSchema, at as isKnownErrorCode, b as DoctorUnsellablePriceSchema, bn as BankTransferRecordInputSchema, br as CatalogPlanSchema, bt as InvoiceWaiveResponseSchema, c as DoctorApiKeySchema, cn as DunningPolicySchema, cr as ReturnOriginSchema, ct as CancelSubscriptionResponseSchema, d as DoctorEmailsSchema, dn as MeterClosePeriodsInputSchema, dr as TtlMinutesSchema, dt as CreditGrantResponseSchema, en as ApiKeyScopeSchema, er as LateGraceMinutesSchema, et as rateOverage, f as DoctorEndpointSchema, fn as MeterClosePeriodsResultSchema, fr as WebUrlSchema, ft as GrantCreateResponseSchema, g as DoctorProviderSchema, gn as RepriceInputSchema, gr as isReturnUrlAllowed, gt as HEADER_REQUEST_ID, h as DoctorOverageSchema, hn as RedeliveredEventSchema, hr as eventsSettingsOf, ht as HEADER_IDEMPOTENCY_KEY, i as DOCTOR_REQUIRED_BRANDING, in as BankTransferListSchema, ir as MeteringSettingsSchema, it as errorCodeSpec, j as WebhookEndpointListSchema, jn as MAX_CHECKOUT_CONSENT_DOCS, jr as PlanDefSchema, jt as InvoiceVoidInputSchema, k as WEBHOOK_SECRET_PREFIX, kn as ConsentSchema, kr as MAX_PLAN_BENEFITS, kt as InvoiceSchema, l as DoctorBillingSchema, ln as MAX_API_KEY_TTL_DAYS, lr as SETTINGS_LOCALES, lt as ChangeSubscriptionResponseSchema, m as DoctorHostedSchema, mn as MeterRecomputeResultSchema, mr as billingSettingsOf, mt as HEADER_API_VERSION, n as DOCTOR_PENDING_BACKLOG_MS, nn as BANK_TRANSFER_LIST_STATUSES, nr as MeterChargeModeSchema, nt as standingOf, o as DOCTOR_ROLLUP_LAG_WARN_SECONDS, on as CreditAdjustmentInputSchema, or as ProductSettingsPatchSchema, ot as AccountDetailSchema, p as DoctorEventsSchema, pn as MeterRecomputeInputSchema, pr as applySettingsPatch, pt as HEADER_ACTOR_REF, q as contributionOf, qn as DEFAULT_METER_CHARGE_MODE, qt as PortalSessionCreateInputSchema, r as DOCTOR_PROVIDER_ENVIRONMENTS, rn as BankTransferListItemSchema, rr as MeteringSettingsPatchSchema, rt as ERROR_CODES, s as DOCTOR_SEVERITIES, sn as DUNNING_ACTIONS, sr as ProductSettingsSchema, st as AccountUpsertResponseSchema, t as DOCTOR_KEY_EXPIRY_WARN_DAYS, tn as ApiKeyTokenSchema, tr as METER_CHARGE_MODES, tt as rolloverOf, u as DoctorCatalogSchema, un as MAX_NOTICE_DAYS, ur as SettingsLocaleSchema, ut as CheckoutSessionResponseSchema, v as DoctorSettingsSchema, vn as RepriceResultSchema, vr as returnOriginsOf, vt as InvoiceIssueResponseSchema, w as endpointDiagnosisOf, wn as CheckoutPrefillSchema, wr as FeatureDefSchema, wt as UncancelSubscriptionResponseSchema, x as DoctorWarningSchema, xn as BankTransferRecordedSchema, xr as CatalogSchema, xt as ManualInvoiceResponseSchema, y as DoctorSeveritySchema, yn as generateApiKeyToken, yr as AccountsRefreshResultSchema, yt as InvoiceVoidResponseSchema, z as PLAN_SET_MODES, zn as BillingSettingsPatchSchema, zt as GrantCreateInputSchema } from "./_chunks/src.js";
|
|
3
3
|
import { a as LIVE_SUBSCRIPTION_STATUSES, c as isLiveSubscriptionStatus, i as FEATURE_FLAG_BENEFIT_TYPE, l as resolveBenefits, n as isValidTckn, o as OVERRIDE_BENEFIT_SOURCE, r as isValidVkn, s as isGrantActive, t as isE164, u as resolveEntitlements } from "./_chunks/validators.js";
|
|
4
4
|
import { a as StewardNetworkError, i as StewardError, n as StewardConfigError, r as StewardContractError, t as StewardApiError } from "./_chunks/errors.js";
|
|
5
5
|
//#region ../contract/src/client.ts
|
|
@@ -247,7 +247,21 @@ function createBillingClient(options) {
|
|
|
247
247
|
listWebhookEndpoints: () => call(WebhookEndpointListSchema, "GET", "/v1/admin/webhook-endpoints"),
|
|
248
248
|
createWebhookEndpoint: (input, opts) => call(WebhookEndpointSchema, "POST", "/v1/admin/webhook-endpoints", input, opts),
|
|
249
249
|
rotateWebhookEndpointSecret: (id, input, opts) => call(WebhookEndpointSchema, "POST", `/v1/admin/webhook-endpoints/${ref(id)}/rotate`, input, opts),
|
|
250
|
-
deactivateWebhookEndpoint: (id, opts) => call(WebhookEndpointSchema, "POST", `/v1/admin/webhook-endpoints/${ref(id)}/deactivate`, void 0, opts)
|
|
250
|
+
deactivateWebhookEndpoint: (id, opts) => call(WebhookEndpointSchema, "POST", `/v1/admin/webhook-endpoints/${ref(id)}/deactivate`, void 0, opts),
|
|
251
|
+
listApiKeys: () => call(ApiKeyListSchema, "GET", "/v1/admin/api-keys"),
|
|
252
|
+
createApiKey: (input, opts) => call(ApiKeySchema, "POST", "/v1/admin/api-keys", input, opts),
|
|
253
|
+
/** 409 `api_key_self_revoke` for the key making the call. */
|
|
254
|
+
revokeApiKey: (prefix, opts) => call(ApiKeySchema, "POST", `/v1/admin/api-keys/${ref(prefix)}/revoke`, void 0, opts),
|
|
255
|
+
getDunningPolicy: () => call(DunningPolicySchema, "GET", "/v1/admin/dunning-policy"),
|
|
256
|
+
setDunningPolicy: (policy, opts) => call(DunningPolicySchema, "PUT", "/v1/admin/dunning-policy", policy, opts),
|
|
257
|
+
redeliverEvent: (eventId, opts) => call(RedeliveredEventSchema, "POST", `/v1/admin/events/${ref(eventId)}/redeliver`, void 0, opts),
|
|
258
|
+
repriceSubscriptions: (input, opts) => call(RepriceResultSchema, "POST", "/v1/admin/subscriptions/reprice", input, opts),
|
|
259
|
+
recomputeMeters: (accountRef, input = {}, opts) => call(MeterRecomputeResultSchema, "POST", `/v1/admin/accounts/${ref(accountRef)}/meters/recompute`, input, opts),
|
|
260
|
+
closeMeterPeriods: (accountRef, input = {}, opts) => call(MeterClosePeriodsResultSchema, "POST", `/v1/admin/accounts/${ref(accountRef)}/meters/close-periods`, input, opts),
|
|
261
|
+
/** Signed units: negative = `adjustment` (admin only); positive = `manual_grant`. */
|
|
262
|
+
adjustCredits: (accountRef, input, opts) => call(CreditGrantResponseSchema, "POST", `/v1/admin/accounts/${ref(accountRef)}/credits`, input, opts),
|
|
263
|
+
listBankTransfers: (status = "pending") => call(BankTransferListSchema, "GET", `/v1/admin/bank-transfers?status=${status}`),
|
|
264
|
+
recordBankTransfer: (input, opts) => call(BankTransferRecordedSchema, "POST", "/v1/admin/bank-transfers", input, opts)
|
|
251
265
|
};
|
|
252
266
|
}
|
|
253
267
|
//#endregion
|
|
@@ -306,7 +320,7 @@ async function withRetries(request, policy, send) {
|
|
|
306
320
|
}
|
|
307
321
|
//#endregion
|
|
308
322
|
//#region src/steward.ts
|
|
309
|
-
const SDK_HEADER = `@stewardhq/sdk/0.
|
|
323
|
+
const SDK_HEADER = `@stewardhq/sdk/0.7.0`;
|
|
310
324
|
const defaultEnv = () => globalThis.process?.env ?? {};
|
|
311
325
|
function isHttpUrl(value) {
|
|
312
326
|
try {
|
|
@@ -626,6 +640,53 @@ function createSteward(options = {}) {
|
|
|
626
640
|
const { client } = requireAdmin();
|
|
627
641
|
return run("POST", call, (c) => client.deactivateWebhookEndpoint(id, c));
|
|
628
642
|
}
|
|
643
|
+
},
|
|
644
|
+
apiKeys: {
|
|
645
|
+
list: async () => read(() => requireAdmin().client.listApiKeys()),
|
|
646
|
+
create: async (input, call) => {
|
|
647
|
+
const { client } = requireAdmin();
|
|
648
|
+
return run("POST", call, (c) => client.createApiKey(input, c));
|
|
649
|
+
},
|
|
650
|
+
revoke: async (prefix, call) => {
|
|
651
|
+
const { client } = requireAdmin();
|
|
652
|
+
return run("POST", call, (c) => client.revokeApiKey(prefix, c));
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
dunning: {
|
|
656
|
+
get: async () => read(() => requireAdmin().client.getDunningPolicy()),
|
|
657
|
+
set: async (policy, call) => {
|
|
658
|
+
const { client } = requireAdmin();
|
|
659
|
+
return run("PUT", call, (c) => client.setDunningPolicy(policy, c));
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
events: { redeliver: async (eventId, call) => {
|
|
663
|
+
const { client } = requireAdmin();
|
|
664
|
+
return run("POST", call, (c) => client.redeliverEvent(eventId, c));
|
|
665
|
+
} },
|
|
666
|
+
subscriptions: { reprice: async (input, call) => {
|
|
667
|
+
const { client } = requireAdmin();
|
|
668
|
+
return run("POST", call, (c) => client.repriceSubscriptions(input, c));
|
|
669
|
+
} },
|
|
670
|
+
meters: {
|
|
671
|
+
recompute: async (accountRef, input = {}, call) => {
|
|
672
|
+
const { client } = requireAdmin();
|
|
673
|
+
return run("POST", call, (c) => client.recomputeMeters(accountRef, input, c));
|
|
674
|
+
},
|
|
675
|
+
closePeriods: async (accountRef, input = {}, call) => {
|
|
676
|
+
const { client } = requireAdmin();
|
|
677
|
+
return run("POST", call, (c) => client.closeMeterPeriods(accountRef, input, c));
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
credits: { adjust: async (accountRef, input, call) => {
|
|
681
|
+
const { client } = requireAdmin();
|
|
682
|
+
return run("POST", call, (c) => client.adjustCredits(accountRef, input, c));
|
|
683
|
+
} },
|
|
684
|
+
bankTransfers: {
|
|
685
|
+
list: async (status = "pending") => read(() => requireAdmin().client.listBankTransfers(status)),
|
|
686
|
+
record: async (input, call) => {
|
|
687
|
+
const { client } = requireAdmin();
|
|
688
|
+
return run("POST", call, (c) => client.recordBankTransfer(input, c));
|
|
689
|
+
}
|
|
629
690
|
}
|
|
630
691
|
}
|
|
631
692
|
};
|
|
@@ -2151,4 +2212,4 @@ function Meters(options) {
|
|
|
2151
2212
|
};
|
|
2152
2213
|
}
|
|
2153
2214
|
//#endregion
|
|
2154
|
-
export { ACCOUNT_INCLUDES, API_VERSION, AccessStateSchema, AccountBenefitSchema, AccountDeleteResponseSchema, AccountDetailSchema, AccountDunningStateSchema, AccountLocaleSchema, AccountMeterSchema, AccountMeterStateSchema, AccountMetersSchema, AccountMetersStateSchema, AccountOpenCheckoutSchema, AccountOpenInvoiceSchema, AccountProfileStateSchema, AccountScheduledChangeSchema, AccountSchema, AccountStateSchema, AccountSubscriptionStateSchema, AccountUpsertInputSchema, AccountUpsertResponseSchema, AccountsRefreshResultSchema, ActorRefSchema, AmountMinorSchema, AnyBillingEventSchema, ApiVersionSchema, BENEFIT_TYPES, BILLING_PATH_PLACEHOLDERS, BenefitDefSchema, BenefitDescriptionSchema, BenefitSourceSchema, BenefitTypeSchema, BillingEventSchema, BillingPathSchema, BillingProfileKindSchema, BillingProfileSchema, BillingSettingsPatchSchema, BillingSettingsSchema, BrandingPatchSchema, BrandingSchema, CHECKOUT_ERRORS, CancelSubscriptionInputSchema, CancelSubscriptionResponseSchema, CatalogBenefitSchema, CatalogMeterSchema, CatalogPlanSchema, CatalogSchema, CatalogSyncInputSchema, CatalogSyncResultSchema, ChangeSubscriptionResponseSchema, CheckoutConsentInputSchema, CheckoutPrefillSchema, CheckoutSessionCreateInputSchema, CheckoutSessionCreatedSchema, CheckoutSessionResponseSchema, CheckoutSessionSchema, CheckoutStatusSchema, CodeSchema, ConsentSchema, CreditGrantInputSchema, CreditGrantResponseSchema, CurrencySchema, DEFAULT_CHECKOUT_TTL_MINUTES, DEFAULT_ENDPOINT_EVENT_TYPES, DEFAULT_EVENT_RETENTION_DAYS, DEFAULT_LATE_GRACE_MINUTES, DEFAULT_METER_CHARGE_MODE, DEFAULT_METER_LOW_AT, DEFAULT_MIN_INVOICE_MINOR, DEFAULT_PAYMENT_DUE_DAYS, DEFAULT_PORTAL_TTL_MINUTES, DOCTOR_PENDING_BACKLOG_MS, DOCTOR_PROVIDER_ENVIRONMENTS, DOCTOR_REQUIRED_BRANDING, DOCTOR_REQUIRED_LEGAL_LINKS, DOCTOR_ROLLUP_LAG_WARN_SECONDS, DOCTOR_SEVERITIES, DateTimeSchema, DecimalUnitsStringSchema, DoctorBillingSchema, DoctorCatalogSchema, DoctorEmailsSchema, DoctorEndpointSchema, DoctorEventsSchema, DoctorHostedSchema, DoctorOverageSchema, DoctorProviderSchema, DoctorReportSchema, DoctorSettingsSchema, DoctorSeveritySchema, DoctorUnsellablePriceSchema, DoctorWarningSchema, EMAIL_LOCALES, EMAIL_PAYLOAD_SCHEMAS, EMAIL_TEMPLATES, EMAIL_TEMPLATE_BY_EVENT, ERROR_CATEGORIES, ERROR_CODES, EVENTS_INGEST_MAX_BYTES, EVENTS_INGEST_MAX_EVENTS, EVENTS_RECENT_MS, EVENT_DETAIL_SCHEMAS, EVENT_METADATA_KEY_MAX_LENGTH, EVENT_METADATA_MAX_PAIRS, EVENT_METADATA_STRING_MAX_LENGTH, EVENT_NAME_MAX_LENGTH, EVENT_TIMESTAMP_MAX_AGE_DAYS, EVENT_TIMESTAMP_MAX_SKEW_MINUTES, EVENT_TYPES, EmailExtraTextSchema, EmailSenderSchema, EmailSettingsPatchSchema, EmailSettingsSchema, EmailTemplateSchema, EmailTemplateSettingsSchema, EntitlementSnapshotSchema, EntitlementValueSchema, EntitlementsSchema, ErrorCategorySchema, ErrorResponseSchema, EventExternalIdSchema, EventIdSchema, EventMetadataKeySchema, EventMetadataSchema, EventMetadataValueSchema, EventNameSchema, EventRetentionDaysSchema, EventTypeSchema, Events, EventsIngestInputSchema, EventsIngestResultSchema, EventsSettingsPatchSchema, EventsSettingsSchema, ExternalRefSchema, FEATURE_FLAG_BENEFIT_TYPE, FULL_STATE_EVENT_TYPES, FeatureDefSchema, FeatureFlagBenefitDefSchema, FeatureFlagPropertiesSchema, FeatureTypeSchema, GrantCreateInputSchema, GrantCreateResponseSchema, GrantSchema, HEADER_ACTOR_REF, HEADER_API_VERSION, HEADER_IDEMPOTENCY_KEY, HEADER_REQUEST_ID, HEADER_SDK, INDIVIDUAL_IDENTITY_PLACEHOLDER, INGEST_REJECT_CODES, INVOICE_BILLING_REASONS, INVOICE_PAYMENT_STATUSES, IdSchema, IngestEventSchema, IngestRejectCodeSchema, IngestRejectionSchema, IntervalSchema, InvalidUnitValueError, InvoiceBillingReasonSchema, InvoiceIssueInputSchema, InvoiceIssueResponseSchema, InvoiceLineSchema, InvoicePaymentDueEmailSchema, InvoicePaymentSessionCreateInputSchema, InvoicePaymentSessionSchema, InvoicePaymentStatusSchema, InvoiceSchema, InvoiceStatusSchema, InvoiceVoidInputSchema, InvoiceVoidResponseSchema, InvoiceWaiveInputSchema, InvoiceWaiveResponseSchema, LEGACY_EVENT_TYPES, LIVE_SUBSCRIPTION_STATUSES, LateGraceMinutesSchema, MANUAL_INVOICE_MAX_AMOUNT_MINOR, MAX_CATALOG_BENEFITS, MAX_CATALOG_METERED_PRICES, MAX_CATALOG_METERS, MAX_CHECKOUT_CONSENT_DOCS, MAX_GRANT_BENEFITS, MAX_METERED_PRICE_PER_UNITS, MAX_METER_UNITS, MAX_NOTIFICATION_EMAILS, MAX_PLAN_BENEFITS, METERED_PRICE_TAX_MISMATCH, METER_AGGREGATION_KINDS, METER_CHARGE_MODES, METER_CHARGE_STATUSES, METER_CREDIT_ENTRY_KINDS, METER_FILTER_MAX_CONDITIONS, METER_FILTER_MAX_DEPTH, METER_FILTER_OPERATORS, METER_PERIOD_STATUSES, METER_STANDINGS, MICRO_UNITS_PER_UNIT, ManualInvoiceInputSchema, ManualInvoiceLineInputSchema, ManualInvoiceResponseSchema, MeResponseSchema, MetadataSchema, MeterAggregationSchema, MeterChargeLineSchema, MeterChargeListSchema, MeterChargeModeSchema, MeterChargeSchema, MeterChargeStatusSchema, MeterCreditBenefitDefSchema, MeterCreditEntryKindSchema, MeterCreditEntrySchema, MeterCreditPropertiesSchema, MeterDefSchema, MeterFilterSchema, MeterLabelSchema, MeterLowAtSchema, MeterPeriodListSchema, MeterPeriodSchema, MeterPeriodStatusSchema, MeterStandingSchema, MeterUnitsSchema, MeteredPriceDefSchema, MeteredPriceSchema, MeteringSettingsPatchSchema, MeteringSettingsSchema, Meters, NoticedMeteredRateSchema, NotificationEmailsSchema, OVERRIDE_BENEFIT_SOURCE, PING_EVENT_TYPE, PLAN_SET_MODES, PORTAL_SESSION_ERRORS, PaymentDueDaysSchema, PaymentSchema, PingSchema, PlanDefSchema, PlanSetInputSchema, PlanSetModeSchema, PlanSetResponseSchema, PlanSetWarningSchema, PortalSessionCreateInputSchema, PortalSessionSchema, PriceChangeNoticeEmailSchema, PriceChangeNoticeMeteredRateSchema, PriceDefSchema, PriceSchema, ProductSettingsPatchSchema, ProductSettingsSchema, ProviderPayloadSchema, ResyncResultSchema, ReturnOriginSchema, SETTINGS_LOCALES, STEWARD_CAPABILITIES, SettingsLocaleSchema, StatsSchema, StewardApiError, StewardConfigError, StewardContractError, StewardError, StewardNetworkError, SubscriptionChangeInputSchema, SubscriptionSchema, SubscriptionStatusSchema, SubscriptionSummarySchema, TtlMinutesSchema, UNIT_DECIMALS, UncancelSubscriptionResponseSchema, WEBHOOK_ENDPOINT_STATUSES, WEBHOOK_SECRET_PREFIX, WebUrlSchema, WebhookEndpointCreateInputSchema, WebhookEndpointListSchema, WebhookEndpointRotateInputSchema, WebhookEndpointSchema, WebhookEndpointStatusSchema, WebhookLastDeliverySchema, WebhookSecretSchema, addUtcMonths, applyEmailSettingsPatch, applySettingsPatch, billingPageUrl, billingSettingsOf, buildDoctorReport, canonicalMeterFilter, checkoutRedirectUrl, consumptionOf, contributionOf, count, createSteward, defineCatalog, emailLocaleOf, emailReadinessOf, emailRecipients, emailTemplateOf, emailTemplateSettings, endpointDiagnosisOf, errorCodeSpec, eventsSettingsOf, featureFlag, featureValueMatchesType, flag, fromMicroUnits, generateWebhookSecret, hasControlCharacters, hostedReadinessOf, httpStatusFor, isE164, isEmailRelevant, isEventTimestampInRange, isEventType, isFeatureFlagBenefit, isGrantActive, isKnownErrorCode, isLiveSubscriptionStatus, isMeterCreditBenefit, isMicroPrecise, isReturnUrlAllowed, isValidTckn, isValidVkn, limit, liveSubscriptionOf, manualInvoiceTotals, matchesFilter, max, meter, meterChargeTotals, meterCredit, meterCreditsOf, meterFilterClauseOf, meteringSettingsOf, microToDecimalString, overageCapReached, overageOf, parseMicroUnits, periodBoundsOf, plainDecimalOf, rateOverage, resolveBenefits, resolveEntitlements, returnOriginsOf, rolloverOf, splitInclusiveTax, standingOf, stateCache, sum, text, toMicroUnits, unique, uniqueEmails, webhookEndpointUrlProblem };
|
|
2215
|
+
export { ACCOUNT_INCLUDES, API_KEY_SCOPES, API_VERSION, AccessStateSchema, AccountBenefitSchema, AccountDeleteResponseSchema, AccountDetailSchema, AccountDunningStateSchema, AccountLocaleSchema, AccountMeterSchema, AccountMeterStateSchema, AccountMetersSchema, AccountMetersStateSchema, AccountOpenCheckoutSchema, AccountOpenInvoiceSchema, AccountProfileStateSchema, AccountScheduledChangeSchema, AccountSchema, AccountStateSchema, AccountSubscriptionStateSchema, AccountUpsertInputSchema, AccountUpsertResponseSchema, AccountsRefreshResultSchema, ActorRefSchema, AmountMinorSchema, AnyBillingEventSchema, ApiKeyCreateInputSchema, ApiKeyListSchema, ApiKeyPrefixSchema, ApiKeySchema, ApiKeyScopeSchema, ApiKeyTokenSchema, ApiVersionSchema, BANK_TRANSFER_LIST_STATUSES, BENEFIT_TYPES, BILLING_PATH_PLACEHOLDERS, BankTransferInstructionsEmailSchema, BankTransferListItemSchema, BankTransferListSchema, BankTransferListStatusSchema, BankTransferPaymentDaysSchema, BankTransferRecordInputSchema, BankTransferRecordedSchema, BankTransferSettingsPatchSchema, BankTransferSettingsSchema, BenefitDefSchema, BenefitDescriptionSchema, BenefitSourceSchema, BenefitTypeSchema, BillingEventSchema, BillingPathSchema, BillingProfileKindSchema, BillingProfileSchema, BillingSettingsPatchSchema, BillingSettingsSchema, BrandingPatchSchema, BrandingSchema, CHECKOUT_ERRORS, CancelSubscriptionInputSchema, CancelSubscriptionResponseSchema, CatalogBenefitSchema, CatalogMeterSchema, CatalogPlanSchema, CatalogSchema, CatalogSyncInputSchema, CatalogSyncResultSchema, ChangeSubscriptionResponseSchema, CheckoutConsentInputSchema, CheckoutPrefillSchema, CheckoutSessionCreateInputSchema, CheckoutSessionCreatedSchema, CheckoutSessionResponseSchema, CheckoutSessionSchema, CheckoutStatusSchema, CodeSchema, ConsentSchema, CreditAdjustmentInputSchema, CreditGrantInputSchema, CreditGrantResponseSchema, CurrencySchema, DEFAULT_BANK_TRANSFER_PAYMENT_DAYS, DEFAULT_CHECKOUT_TTL_MINUTES, DEFAULT_ENDPOINT_EVENT_TYPES, DEFAULT_EVENT_RETENTION_DAYS, DEFAULT_LATE_GRACE_MINUTES, DEFAULT_METER_CHARGE_MODE, DEFAULT_METER_LOW_AT, DEFAULT_MIN_INVOICE_MINOR, DEFAULT_PAYMENT_DUE_DAYS, DEFAULT_PORTAL_TTL_MINUTES, DOCTOR_KEY_EXPIRY_WARN_DAYS, DOCTOR_PENDING_BACKLOG_MS, DOCTOR_PROVIDER_ENVIRONMENTS, DOCTOR_REQUIRED_BRANDING, DOCTOR_REQUIRED_LEGAL_LINKS, DOCTOR_ROLLUP_LAG_WARN_SECONDS, DOCTOR_SEVERITIES, DUNNING_ACTIONS, DateTimeSchema, DecimalUnitsStringSchema, DoctorApiKeySchema, DoctorBillingSchema, DoctorCatalogSchema, DoctorEmailsSchema, DoctorEndpointSchema, DoctorEventsSchema, DoctorHostedSchema, DoctorOverageSchema, DoctorProviderSchema, DoctorReportSchema, DoctorSettingsSchema, DoctorSeveritySchema, DoctorUnsellablePriceSchema, DoctorWarningSchema, DunningPolicySchema, EMAIL_LOCALES, EMAIL_PAYLOAD_SCHEMAS, EMAIL_TEMPLATES, EMAIL_TEMPLATE_BY_EVENT, ERROR_CATEGORIES, ERROR_CODES, EVENTS_INGEST_MAX_BYTES, EVENTS_INGEST_MAX_EVENTS, EVENTS_RECENT_MS, EVENT_DETAIL_SCHEMAS, EVENT_METADATA_KEY_MAX_LENGTH, EVENT_METADATA_MAX_PAIRS, EVENT_METADATA_STRING_MAX_LENGTH, EVENT_NAME_MAX_LENGTH, EVENT_TIMESTAMP_MAX_AGE_DAYS, EVENT_TIMESTAMP_MAX_SKEW_MINUTES, EVENT_TYPES, EmailExtraTextSchema, EmailSenderSchema, EmailSettingsPatchSchema, EmailSettingsSchema, EmailTemplateSchema, EmailTemplateSettingsSchema, EntitlementSnapshotSchema, EntitlementValueSchema, EntitlementsSchema, ErrorCategorySchema, ErrorResponseSchema, EventExternalIdSchema, EventIdSchema, EventMetadataKeySchema, EventMetadataSchema, EventMetadataValueSchema, EventNameSchema, EventRetentionDaysSchema, EventTypeSchema, Events, EventsIngestInputSchema, EventsIngestResultSchema, EventsSettingsPatchSchema, EventsSettingsSchema, ExternalRefSchema, FEATURE_FLAG_BENEFIT_TYPE, FULL_STATE_EVENT_TYPES, FeatureDefSchema, FeatureFlagBenefitDefSchema, FeatureFlagPropertiesSchema, FeatureTypeSchema, GrantCreateInputSchema, GrantCreateResponseSchema, GrantSchema, HEADER_ACTOR_REF, HEADER_API_VERSION, HEADER_IDEMPOTENCY_KEY, HEADER_REQUEST_ID, HEADER_SDK, INDIVIDUAL_IDENTITY_PLACEHOLDER, INGEST_REJECT_CODES, INVOICE_BILLING_REASONS, INVOICE_PAYMENT_STATUSES, IdSchema, IngestEventSchema, IngestRejectCodeSchema, IngestRejectionSchema, IntervalSchema, InvalidUnitValueError, InvoiceBillingReasonSchema, InvoiceIssueInputSchema, InvoiceIssueResponseSchema, InvoiceLineSchema, InvoicePaymentDueEmailSchema, InvoicePaymentSessionCreateInputSchema, InvoicePaymentSessionSchema, InvoicePaymentStatusSchema, InvoiceSchema, InvoiceStatusSchema, InvoiceVoidInputSchema, InvoiceVoidResponseSchema, InvoiceWaiveInputSchema, InvoiceWaiveResponseSchema, LEGACY_EVENT_TYPES, LIVE_SUBSCRIPTION_STATUSES, LateGraceMinutesSchema, MANUAL_INVOICE_MAX_AMOUNT_MINOR, MAX_API_KEY_TTL_DAYS, MAX_CATALOG_BENEFITS, MAX_CATALOG_METERED_PRICES, MAX_CATALOG_METERS, MAX_CHECKOUT_CONSENT_DOCS, MAX_GRANT_BENEFITS, MAX_METERED_PRICE_PER_UNITS, MAX_METER_UNITS, MAX_NOTICE_DAYS, MAX_NOTIFICATION_EMAILS, MAX_PLAN_BENEFITS, METERED_PRICE_TAX_MISMATCH, METER_AGGREGATION_KINDS, METER_CHARGE_MODES, METER_CHARGE_STATUSES, METER_CREDIT_ENTRY_KINDS, METER_FILTER_MAX_CONDITIONS, METER_FILTER_MAX_DEPTH, METER_FILTER_OPERATORS, METER_PERIOD_STATUSES, METER_STANDINGS, MICRO_UNITS_PER_UNIT, ManualInvoiceInputSchema, ManualInvoiceLineInputSchema, ManualInvoiceResponseSchema, MeResponseSchema, MetadataSchema, MeterAggregationSchema, MeterChargeLineSchema, MeterChargeListSchema, MeterChargeModeSchema, MeterChargeSchema, MeterChargeStatusSchema, MeterClosePeriodsInputSchema, MeterClosePeriodsResultSchema, MeterCreditBenefitDefSchema, MeterCreditEntryKindSchema, MeterCreditEntrySchema, MeterCreditPropertiesSchema, MeterDefSchema, MeterFilterSchema, MeterLabelSchema, MeterLowAtSchema, MeterPeriodListSchema, MeterPeriodSchema, MeterPeriodStatusSchema, MeterRecomputeInputSchema, MeterRecomputeResultSchema, MeterStandingSchema, MeterUnitsSchema, MeteredPriceDefSchema, MeteredPriceSchema, MeteringSettingsPatchSchema, MeteringSettingsSchema, Meters, NoticedMeteredRateSchema, NotificationEmailsSchema, OVERRIDE_BENEFIT_SOURCE, PAYMENT_METHODS, PING_EVENT_TYPE, PLAN_SET_MODES, PORTAL_SESSION_ERRORS, PaymentDueDaysSchema, PaymentMethodSchema, PaymentSchema, PingSchema, PlanDefSchema, PlanSetInputSchema, PlanSetModeSchema, PlanSetResponseSchema, PlanSetWarningSchema, PortalSessionCreateInputSchema, PortalSessionSchema, PriceChangeNoticeEmailSchema, PriceChangeNoticeMeteredRateSchema, PriceDefSchema, PriceSchema, ProductSettingsPatchSchema, ProductSettingsSchema, ProviderPayloadSchema, RedeliveredEventSchema, RepriceInputSchema, RepriceItemSchema, RepriceResultSchema, ResyncResultSchema, ReturnOriginSchema, SETTINGS_LOCALES, STEWARD_CAPABILITIES, SettingsLocaleSchema, StatsSchema, StewardApiError, StewardConfigError, StewardContractError, StewardError, StewardNetworkError, SubscriptionChangeInputSchema, SubscriptionSchema, SubscriptionStatusSchema, SubscriptionSummarySchema, TtlMinutesSchema, UNIT_DECIMALS, UncancelSubscriptionResponseSchema, WEBHOOK_ENDPOINT_STATUSES, WEBHOOK_SECRET_PREFIX, WebUrlSchema, WebhookEndpointCreateInputSchema, WebhookEndpointListSchema, WebhookEndpointRotateInputSchema, WebhookEndpointSchema, WebhookEndpointStatusSchema, WebhookLastDeliverySchema, WebhookSecretSchema, addUtcMonths, applyEmailSettingsPatch, applySettingsPatch, billingPageUrl, billingSettingsOf, buildDoctorReport, canonicalMeterFilter, checkoutRedirectUrl, consumptionOf, contributionOf, count, createSteward, defineCatalog, emailLocaleOf, emailReadinessOf, emailRecipients, emailTemplateOf, emailTemplateSettings, endpointDiagnosisOf, errorCodeSpec, eventsSettingsOf, featureFlag, featureValueMatchesType, flag, fromMicroUnits, generateApiKeyToken, generateWebhookSecret, hasControlCharacters, hostedReadinessOf, httpStatusFor, isE164, isEmailRelevant, isEventTimestampInRange, isEventType, isFeatureFlagBenefit, isGrantActive, isKnownErrorCode, isLiveSubscriptionStatus, isMeterCreditBenefit, isMicroPrecise, isReturnUrlAllowed, isValidTckn, isValidVkn, limit, liveSubscriptionOf, manualInvoiceTotals, matchesFilter, max, meter, meterChargeTotals, meterCredit, meterCreditsOf, meterFilterClauseOf, meteringSettingsOf, microToDecimalString, overageCapReached, overageOf, parseMicroUnits, periodBoundsOf, plainDecimalOf, rateOverage, resolveBenefits, resolveEntitlements, returnOriginsOf, rolloverOf, splitInclusiveTax, standingOf, stateCache, sum, text, toMicroUnits, unique, uniqueEmails, webhookEndpointUrlProblem };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Aa as PortalSession, Bo as CheckoutSessionCreated, Dl as Interval, Lo as CheckoutSessionCreateInput, Mo as CheckoutPrefill, Ts as AccountBenefit, Uo as CheckoutStatus, Xo as PaymentMethod, ja as PortalSessionCreateInput, xi as CheckoutSessionResponse } from "./_chunks/index.js";
|
|
2
2
|
import { O as AccountInclude, U as AccountState, Y as BillingProfile, a as BillingEvent, f as EventType, n as AnyBillingEvent, o as BillingEventOf, u as EventDetail } from "./_chunks/events.js";
|
|
3
3
|
import { r as StewardLogger, s as MutationOptions, t as StewardLocale } from "./_chunks/locale.js";
|
|
4
4
|
import { a as HeaderSource, s as VerifyRawFailure } from "./_chunks/webhook-core.js";
|
|
@@ -55,6 +55,12 @@ type CheckoutCreateInput = {
|
|
|
55
55
|
displayName?: string;
|
|
56
56
|
/** Sayfanın ön doldurması (ad, e-posta, tür); kimlik verisi değil (K21). */
|
|
57
57
|
prefill?: CheckoutPrefill;
|
|
58
|
+
/**
|
|
59
|
+
* Upgrade: the account's live subscription this purchase replaces. Do NOT cancel it before the
|
|
60
|
+
* checkout: it keeps running until the payment is recorded (card or bank transfer) and is
|
|
61
|
+
* canceled in that same transaction; an abandoned checkout leaves it untouched.
|
|
62
|
+
*/
|
|
63
|
+
replacesSubscriptionId?: string;
|
|
58
64
|
};
|
|
59
65
|
type CheckoutCreated = {
|
|
60
66
|
id: string;
|
|
@@ -64,6 +70,12 @@ type CheckoutCreated = {
|
|
|
64
70
|
type CheckoutResult = {
|
|
65
71
|
status: CheckoutStatus;
|
|
66
72
|
planCode?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Chosen on the page: `bank_transfer` with `status: "open"` means the order waits for the
|
|
75
|
+
* customer's transfer (show "payment pending" and `account.bankTransferCode` from the state).
|
|
76
|
+
* Absent before a choice and from older steward.
|
|
77
|
+
*/
|
|
78
|
+
paymentMethod?: PaymentMethod;
|
|
67
79
|
/** Yalnızca `completed`: işlem sonrası hesap durumu (önbelleğe yazıldı). */
|
|
68
80
|
account?: AccountState;
|
|
69
81
|
};
|
|
@@ -105,12 +117,12 @@ export declare function CustomerPortal(options: CustomerPortalOptions): Customer
|
|
|
105
117
|
//#endregion
|
|
106
118
|
//#region src/server/webhooks.d.ts
|
|
107
119
|
/** Neden hook'u olan tipler: `account.state_changed` dışındaki her tip (neden olarak da gelirler). */
|
|
108
|
-
type CauseEventType = Exclude<EventType,
|
|
120
|
+
type CauseEventType = Exclude<EventType, 'account.state_changed'>;
|
|
109
121
|
type Pascal<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Capitalize<Head>}${Pascal<Tail>}` : Capitalize<S>;
|
|
110
122
|
/** `subscription.payment_failed` → `onSubscriptionPaymentFailed`. */
|
|
111
123
|
type EventHookName<T extends string> = T extends `${infer Scope}.${infer Name}` ? `on${Pascal<Scope>}${Pascal<Name>}` : `on${Pascal<T>}`;
|
|
112
|
-
type WebhookHandled =
|
|
113
|
-
type WebhookErrorCode =
|
|
124
|
+
type WebhookHandled = 'received' | 'no_state' | 'ignored' | 'deleted' | 'ping';
|
|
125
|
+
type WebhookErrorCode = 'not_configured' | VerifyRawFailure | 'invalid_payload' | 'id_mismatch' | 'state_unavailable' | 'profile_unavailable' | 'hook_failed';
|
|
114
126
|
type WebhookResult = {
|
|
115
127
|
status: 200;
|
|
116
128
|
body: {
|
|
@@ -139,7 +151,7 @@ type CauseHookArgs<T extends CauseEventType, S extends HookState = HookState> =
|
|
|
139
151
|
ref: string;
|
|
140
152
|
cause: T;
|
|
141
153
|
/** Filtresiz (eski) endpoint'te o tipin event'i, yeni endpoint'te `account.state_changed`. */
|
|
142
|
-
event: BillingEventOf<T> | BillingEventOf<
|
|
154
|
+
event: BillingEventOf<T> | BillingEventOf<'account.state_changed'>;
|
|
143
155
|
/** Teslimatın tam durumu (refetch'te canlı); yalnızca `refetch: false` + snapshot taşıyan eski gövdede `null`. */
|
|
144
156
|
state: S;
|
|
145
157
|
};
|
|
@@ -148,7 +160,7 @@ type NotificationHookArgs<T extends CauseEventType, S extends HookState = HookSt
|
|
|
148
160
|
profile?: BillingProfile | null;
|
|
149
161
|
};
|
|
150
162
|
/** Benefit grant types with a dedicated hook (`onBenefitGranted` / `onBenefitRevoked` / `onBenefitCycled`). */
|
|
151
|
-
type BenefitHookEventType =
|
|
163
|
+
type BenefitHookEventType = 'benefit_grant.created' | 'benefit_grant.revoked' | 'benefit_grant.cycled';
|
|
152
164
|
type BenefitHookArgs<T extends BenefitHookEventType, S extends HookState = HookState> = {
|
|
153
165
|
ref: string;
|
|
154
166
|
cause: T;
|
|
@@ -162,19 +174,19 @@ type BenefitHookArgs<T extends BenefitHookEventType, S extends HookState = HookS
|
|
|
162
174
|
state: S;
|
|
163
175
|
};
|
|
164
176
|
/** `onBenefitCycled` (`benefit_grant.cycled`): the renewed `meter_credit` grant and its new meter period. */
|
|
165
|
-
type BenefitCycledHookArgs<S extends HookState = HookState> = BenefitHookArgs<
|
|
177
|
+
type BenefitCycledHookArgs<S extends HookState = HookState> = BenefitHookArgs<'benefit_grant.cycled', S> & {
|
|
166
178
|
periodStart: string;
|
|
167
179
|
periodEnd: string;
|
|
168
180
|
};
|
|
169
181
|
/** `onMeterThreshold` (`meter.threshold_crossed`, cause hook). */
|
|
170
|
-
type MeterThresholdHookArgs<S extends HookState = HookState> = CauseHookArgs<
|
|
182
|
+
type MeterThresholdHookArgs<S extends HookState = HookState> = CauseHookArgs<'meter.threshold_crossed', S> & {
|
|
171
183
|
/** The event's detail when the event itself was delivered; `null` for an `account.state_changed` caused by it. */
|
|
172
|
-
threshold: EventDetail<
|
|
184
|
+
threshold: EventDetail<'meter.threshold_crossed'> | null;
|
|
173
185
|
};
|
|
174
186
|
/** `onMeterPeriodClosed` (`meter.period_closed`, cause hook). */
|
|
175
|
-
type MeterPeriodClosedHookArgs<S extends HookState = HookState> = CauseHookArgs<
|
|
187
|
+
type MeterPeriodClosedHookArgs<S extends HookState = HookState> = CauseHookArgs<'meter.period_closed', S> & {
|
|
176
188
|
/** The event's detail when the event itself was delivered; `null` for an `account.state_changed` caused by it. */
|
|
177
|
-
period: EventDetail<
|
|
189
|
+
period: EventDetail<'meter.period_closed'> | null;
|
|
178
190
|
};
|
|
179
191
|
type UnknownEventArgs<S extends HookState = HookState> = {
|
|
180
192
|
ref: string;
|
|
@@ -189,7 +201,7 @@ type AfterArgs<S extends HookState = HookState> = {
|
|
|
189
201
|
event: BillingEvent | AnyBillingEvent;
|
|
190
202
|
state: S;
|
|
191
203
|
/** Refetch açıkken `received` ya da (hesap silme teslimatı, F4e) `deleted`; `no_state` yalnızca `state: null` ile. */
|
|
192
|
-
handled: null extends S ? Exclude<WebhookHandled,
|
|
204
|
+
handled: null extends S ? Exclude<WebhookHandled, 'ping' | 'ignored'> : 'received' | 'deleted';
|
|
193
205
|
};
|
|
194
206
|
/** Dönüş değeri beklenir (`await`) ama kullanılmaz: sorgu/kuyruk promise'ı doğrudan dönebilir. */
|
|
195
207
|
type Hook<A> = (args: A) => unknown;
|
|
@@ -215,7 +227,7 @@ type WebhooksCache = {
|
|
|
215
227
|
invalidate?(ref: string): unknown;
|
|
216
228
|
};
|
|
217
229
|
type CauseHooks<S extends HookState> = { [T in CauseEventType as EventHookName<T>]?: Hook<CauseHookArgs<T, S>>; };
|
|
218
|
-
type WebhooksOptions<S extends HookState = HookState> = Omit<CauseHooks<S>,
|
|
230
|
+
type WebhooksOptions<S extends HookState = HookState> = Omit<CauseHooks<S>, 'onMeterPeriodClosed'> & {
|
|
219
231
|
/** `meter.period_closed` (cause hook); `period` is the event's detail when the event itself was delivered. */
|
|
220
232
|
onMeterPeriodClosed?: Hook<MeterPeriodClosedHookArgs<S>>;
|
|
221
233
|
/** A meter's standing changed (`meter.threshold_crossed`, cause hook); after `onMeterThresholdCrossed`. */
|
|
@@ -238,13 +250,13 @@ type WebhooksOptions<S extends HookState = HookState> = Omit<CauseHooks<S>, "onM
|
|
|
238
250
|
includeProfile?: boolean;
|
|
239
251
|
/** Tam durumlu her teslimatta (tekrar dahil). `"ignore"` dönerse hesap bilinmiyor: 200, diğer hook'lar ve `after` koşmaz. */
|
|
240
252
|
onStateChanged?: Hook<StateChangedArgs>;
|
|
241
|
-
onPaymentFailed?: Hook<NotificationHookArgs<
|
|
242
|
-
onSuspended?: Hook<NotificationHookArgs<
|
|
243
|
-
onTerminated?: Hook<NotificationHookArgs<
|
|
253
|
+
onPaymentFailed?: Hook<NotificationHookArgs<'subscription.payment_failed', S>>;
|
|
254
|
+
onSuspended?: Hook<NotificationHookArgs<'subscription.suspended', S>>;
|
|
255
|
+
onTerminated?: Hook<NotificationHookArgs<'subscription.terminated', S>>;
|
|
244
256
|
/** A benefit was granted (`benefit_grant.created`; the endpoint must list the type). After `onBenefitGrantCreated`. */
|
|
245
|
-
onBenefitGranted?: Hook<BenefitHookArgs<
|
|
257
|
+
onBenefitGranted?: Hook<BenefitHookArgs<'benefit_grant.created', S>>;
|
|
246
258
|
/** A benefit was revoked (`benefit_grant.revoked`; the endpoint must list the type). After `onBenefitGrantRevoked`. */
|
|
247
|
-
onBenefitRevoked?: Hook<BenefitHookArgs<
|
|
259
|
+
onBenefitRevoked?: Hook<BenefitHookArgs<'benefit_grant.revoked', S>>;
|
|
248
260
|
onUnknownEvent?: Hook<UnknownEventArgs<S>>;
|
|
249
261
|
/** Diğer hook'lardan sonra, her teslimatta (tekrar dahil; `"ignore"` hariç); ör. ağlara yayılma. */
|
|
250
262
|
after?: Hook<AfterArgs<S>>;
|
|
@@ -254,7 +266,7 @@ type WebhooksOptions<S extends HookState = HookState> = Omit<CauseHooks<S>, "onM
|
|
|
254
266
|
* `refetch` ve `steward` alanlarının tiplerinden hook durumu: `refetch: true` ya da (`refetch`
|
|
255
267
|
* verilmemiş ve `steward` verilmiş) → `AccountState`; aksi (ya da tip belirsizse) `AccountState | null`.
|
|
256
268
|
*/
|
|
257
|
-
type WebhooksHookState<R, St> = [R] extends [true] ? AccountState : [R] extends [undefined] ?
|
|
269
|
+
type WebhooksHookState<R, St> = [R] extends [true] ? AccountState : [R] extends [undefined] ? [undefined] extends [St] ? HookState : AccountState : HookState;
|
|
258
270
|
/** `Request`'in kullanılan kısmı (Hono `c.req.raw`, Next `req`, undici `Request`). */
|
|
259
271
|
type WebhookRequest = {
|
|
260
272
|
readonly headers: Headers;
|
|
@@ -266,7 +278,7 @@ type WebhooksHandler = {
|
|
|
266
278
|
/** Düz fonksiyon: ham gövde + başlıklar → `{status, body}` (ürün kendi yanıtını kurar). */
|
|
267
279
|
receive(rawBody: string, headers: HeaderSource): Promise<WebhookResult>;
|
|
268
280
|
};
|
|
269
|
-
export declare function Webhooks<const R extends boolean | undefined = undefined, St extends WebhooksSteward | undefined = undefined>(options: Omit<WebhooksOptions<WebhooksHookState<R, St>>,
|
|
281
|
+
export declare function Webhooks<const R extends boolean | undefined = undefined, St extends WebhooksSteward | undefined = undefined>(options: Omit<WebhooksOptions<WebhooksHookState<R, St>>, 'refetch' | 'steward'> & {
|
|
270
282
|
refetch?: R;
|
|
271
283
|
steward?: St;
|
|
272
284
|
}): WebhooksHandler;
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Kn as IdSchema, Nn as ActorRefSchema, Un as ExternalRefSchema, a as EVENT_TYPES, l as PING_EVENT_TYPE, r as BillingEventSchema, t as AnyBillingEventSchema, u as PingSchema, w as AccountStateSchema } from "./_chunks/events.js";
|
|
2
2
|
import "./_chunks/src.js";
|
|
3
3
|
import { n as StewardConfigError, r as StewardContractError, t as StewardApiError } from "./_chunks/errors.js";
|
|
4
4
|
import { i as verifyWebhookRaw } from "./_chunks/webhook.js";
|
|
@@ -59,7 +59,8 @@ function Checkout(options) {
|
|
|
59
59
|
url
|
|
60
60
|
})) } : {},
|
|
61
61
|
...input.displayName !== void 0 ? { displayName: input.displayName } : {},
|
|
62
|
-
...input.prefill !== void 0 ? { prefill: input.prefill } : {}
|
|
62
|
+
...input.prefill !== void 0 ? { prefill: input.prefill } : {},
|
|
63
|
+
...input.replacesSubscriptionId !== void 0 ? { replacesSubscriptionId: input.replacesSubscriptionId } : {}
|
|
63
64
|
};
|
|
64
65
|
const session = await steward.checkoutSessions.create(input.ref, body, { actorRef: input.actorRef });
|
|
65
66
|
if (typeof session.url !== "string" || session.url === "") throw new StewardContractError({ message: "Checkout: steward hosted checkout adresi (url) döndürmedi; steward sürümü F2b öncesi mi?" });
|
|
@@ -73,17 +74,20 @@ function Checkout(options) {
|
|
|
73
74
|
if (!IdSchema.safeParse(id).success) throw notFound();
|
|
74
75
|
const session = await steward.checkoutSessions.get(id);
|
|
75
76
|
if (session.accountRef !== ref) throw notFound();
|
|
77
|
+
const method = session.paymentMethod ? { paymentMethod: session.paymentMethod } : {};
|
|
76
78
|
if (session.status === "completed" && session.account) {
|
|
77
79
|
await cache?.prime(session.account);
|
|
78
80
|
return {
|
|
79
81
|
status: session.status,
|
|
80
82
|
planCode: session.planCode,
|
|
83
|
+
...method,
|
|
81
84
|
account: session.account
|
|
82
85
|
};
|
|
83
86
|
}
|
|
84
87
|
return {
|
|
85
88
|
status: session.status,
|
|
86
|
-
planCode: session.planCode
|
|
89
|
+
planCode: session.planCode,
|
|
90
|
+
...method
|
|
87
91
|
};
|
|
88
92
|
}
|
|
89
93
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stewardhq/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Steward SDK: contract schemas, typed API client and webhook signing.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://github.com/z9cloud/steward/tree/main/sdk#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/z9cloud/steward/issues"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
6
11
|
"repository": {
|
|
7
12
|
"type": "git",
|
|
@@ -36,7 +41,8 @@
|
|
|
36
41
|
"./package.json": "./package.json"
|
|
37
42
|
},
|
|
38
43
|
"files": [
|
|
39
|
-
"dist"
|
|
44
|
+
"dist",
|
|
45
|
+
"LICENSE"
|
|
40
46
|
],
|
|
41
47
|
"publishConfig": {
|
|
42
48
|
"access": "public",
|
|
@@ -46,12 +52,12 @@
|
|
|
46
52
|
"zod": "^4.0.0"
|
|
47
53
|
},
|
|
48
54
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^24.
|
|
55
|
+
"@types/node": "^24.19.0",
|
|
50
56
|
"tsdown": "^0.23.0",
|
|
51
|
-
"typescript": "^
|
|
52
|
-
"vitest": "^5.0.
|
|
53
|
-
"workerd": "^1.
|
|
54
|
-
"@
|
|
57
|
+
"typescript": "^7.0.2",
|
|
58
|
+
"vitest": "^5.0.2",
|
|
59
|
+
"workerd": "^1.20260928.1",
|
|
60
|
+
"@stewardhq/contract": "0.6.0"
|
|
55
61
|
},
|
|
56
62
|
"scripts": {
|
|
57
63
|
"build": "tsdown && node scripts/check-dist.mjs",
|
|
@@ -59,6 +65,6 @@
|
|
|
59
65
|
"check:workerd": "node scripts/check-workerd.mjs",
|
|
60
66
|
"test": "pnpm run build && vitest run",
|
|
61
67
|
"typecheck": "tsc --noEmit",
|
|
62
|
-
"lint": "
|
|
68
|
+
"lint": "biome check src scripts tsdown.config.ts"
|
|
63
69
|
}
|
|
64
70
|
}
|