@feelflow/ffid-sdk 9.0.0 → 10.0.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.
@@ -1370,7 +1370,7 @@ var FFID_ORGANIZATION_PROFILE_ERROR_CODES = {
1370
1370
  };
1371
1371
 
1372
1372
  // src/client/version-check.ts
1373
- var SDK_VERSION = "9.0.0";
1373
+ var SDK_VERSION = "10.0.0";
1374
1374
  var SDK_USER_AGENT = `FFID-SDK/${SDK_VERSION} (TypeScript)`;
1375
1375
  var SDK_VERSION_HEADER = "X-FFID-SDK-Version";
1376
1376
  function sdkHeaders() {
@@ -1726,8 +1726,11 @@ function createProvisioningMethods(deps) {
1726
1726
  }
1727
1727
 
1728
1728
  // src/client/seat-methods.ts
1729
+ function seatSummaryEndpoint(subscriptionId) {
1730
+ return `/api/v1/subscriptions/ext/${encodeURIComponent(subscriptionId)}/seats`;
1731
+ }
1729
1732
  function seatsEndpoint(subscriptionId) {
1730
- return `/api/v1/subscriptions/ext/${encodeURIComponent(subscriptionId)}/seats/assignments`;
1733
+ return `${seatSummaryEndpoint(subscriptionId)}/assignments`;
1731
1734
  }
1732
1735
  function createSeatMethods(deps) {
1733
1736
  const { fetchWithAuth, createError } = deps;
@@ -1737,6 +1740,12 @@ function createSeatMethods(deps) {
1737
1740
  }
1738
1741
  return fetchWithAuth(seatsEndpoint(params.subscriptionId));
1739
1742
  }
1743
+ async function getSeats(subscriptionId) {
1744
+ if (!subscriptionId || !subscriptionId.trim()) {
1745
+ return { error: createError("VALIDATION_ERROR", "subscriptionId \u306F\u5FC5\u9808\u3067\u3059") };
1746
+ }
1747
+ return fetchWithAuth(seatSummaryEndpoint(subscriptionId));
1748
+ }
1740
1749
  async function assignSeats(params) {
1741
1750
  if (!params.subscriptionId) {
1742
1751
  return { error: createError("VALIDATION_ERROR", "subscriptionId \u306F\u5FC5\u9808\u3067\u3059") };
@@ -1761,7 +1770,7 @@ function createSeatMethods(deps) {
1761
1770
  { method: "DELETE" }
1762
1771
  );
1763
1772
  }
1764
- return { listSeatAssignments, assignSeats, unassignSeat };
1773
+ return { listSeatAssignments, getSeats, assignSeats, unassignSeat };
1765
1774
  }
1766
1775
 
1767
1776
  // src/client/profile-methods.ts
@@ -3488,6 +3497,222 @@ function createInquiryMethods(deps) {
3488
3497
  return { create };
3489
3498
  }
3490
3499
 
3500
+ // src/types/credits.ts
3501
+ var FFID_CREDITS_CONSUME_MIN_AMOUNT = 1;
3502
+ var FFID_CREDITS_CONSUME_MAX_AMOUNT = 1e6;
3503
+ var FFID_CREDITS_METADATA_MAX_BYTES = 4096;
3504
+ var FFID_CREDITS_HISTORY_MIN_LIMIT = 1;
3505
+ var FFID_CREDITS_HISTORY_MAX_LIMIT = 100;
3506
+ var FFID_CREDIT_PACK_MIN_QUANTITY = 1;
3507
+ var FFID_CREDIT_PACK_MAX_QUANTITY = 10;
3508
+ var FFID_CREDITS_IDEMPOTENCY_KEY_PATTERN = /^[A-Za-z0-9._:-]{8,128}$/;
3509
+ var FFID_CREDITS_FEATURE_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
3510
+ var FFID_CREDIT_HISTORY_TYPES = ["grant", "consumption", "revocation"];
3511
+
3512
+ // src/client/credits-methods.ts
3513
+ var EXT_SUBSCRIPTIONS_PATH = "/api/v1/subscriptions/ext";
3514
+ var CREDIT_PACKS_ENDPOINT = `${EXT_SUBSCRIPTIONS_PATH}/credits/packs`;
3515
+ var CREDIT_PACK_CHECKOUT_ENDPOINT = `${CREDIT_PACKS_ENDPOINT}/checkout`;
3516
+ var PORTAL_SUBSCRIPTION_PATH = "/subscriptions";
3517
+ var BUY_CREDITS_QUERY = { key: "purchase", value: "credits" };
3518
+ var ORG_QUERY_KEY = "org";
3519
+ var FFID_CONTRACT_ID_PREFIX = "ffid:";
3520
+ var STRIPE_SUBSCRIPTION_ID_PREFIX = "sub_";
3521
+ var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3522
+ var VALIDATION_ERROR = "VALIDATION_ERROR";
3523
+ var FORBIDDEN = "FORBIDDEN";
3524
+ var utf8Encoder = new TextEncoder();
3525
+ function creditsEndpoint(subscriptionId, action) {
3526
+ return `${EXT_SUBSCRIPTIONS_PATH}/${encodeURIComponent(subscriptionId)}/credits/${action}`;
3527
+ }
3528
+ function isPlainObject2(value) {
3529
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3530
+ }
3531
+ function isIntegerInRange(value, min, max) {
3532
+ return typeof value === "number" && Number.isInteger(value) && value >= min && value <= max;
3533
+ }
3534
+ function createCreditsMethods(deps) {
3535
+ const { fetchWithAuth, createError, authMode, baseUrl, serviceCode, logger } = deps;
3536
+ function validationError(field, message) {
3537
+ return { error: { ...createError(VALIDATION_ERROR, message), details: { field } } };
3538
+ }
3539
+ function forbidden(reason, message) {
3540
+ return { error: { ...createError(FORBIDDEN, message), details: { reason } } };
3541
+ }
3542
+ function missingSubscriptionId(subscriptionId) {
3543
+ return subscriptionId && subscriptionId.trim() ? null : validationError("subscriptionId", "subscriptionId \u306F\u5FC5\u9808\u3067\u3059");
3544
+ }
3545
+ async function getBalance(subscriptionId) {
3546
+ const invalid = missingSubscriptionId(subscriptionId);
3547
+ if (invalid) return invalid;
3548
+ return fetchWithAuth(creditsEndpoint(subscriptionId, "balance"));
3549
+ }
3550
+ async function listHistory(subscriptionId, options = {}) {
3551
+ const invalid = missingSubscriptionId(subscriptionId);
3552
+ if (invalid) return invalid;
3553
+ const query = new URLSearchParams();
3554
+ if (options.cursor !== void 0) query.set("cursor", options.cursor);
3555
+ if (options.limit !== void 0) {
3556
+ if (!isIntegerInRange(options.limit, FFID_CREDITS_HISTORY_MIN_LIMIT, FFID_CREDITS_HISTORY_MAX_LIMIT)) {
3557
+ return validationError(
3558
+ "limit",
3559
+ `limit \u306F ${FFID_CREDITS_HISTORY_MIN_LIMIT}\u301C${FFID_CREDITS_HISTORY_MAX_LIMIT} \u306E\u6574\u6570\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`
3560
+ );
3561
+ }
3562
+ query.set("limit", String(options.limit));
3563
+ }
3564
+ if (options.type !== void 0) {
3565
+ if (!FFID_CREDIT_HISTORY_TYPES.includes(options.type)) {
3566
+ return validationError("type", `type \u306F ${FFID_CREDIT_HISTORY_TYPES.join(" / ")} \u306E\u3044\u305A\u308C\u304B\u3067\u3059`);
3567
+ }
3568
+ query.set("type", options.type);
3569
+ }
3570
+ const qs = query.toString();
3571
+ return fetchWithAuth(
3572
+ `${creditsEndpoint(subscriptionId, "history")}${qs ? `?${qs}` : ""}`
3573
+ );
3574
+ }
3575
+ async function listPacks(packServiceCode) {
3576
+ const resolved = packServiceCode ?? (authMode === "service-key" ? void 0 : serviceCode);
3577
+ if (resolved !== void 0 && !resolved.trim()) {
3578
+ return validationError("serviceCode", "serviceCode \u3092\u6307\u5B9A\u3059\u308B\u5834\u5408\u3001\u7A7A\u6587\u5B57\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093");
3579
+ }
3580
+ const qs = resolved === void 0 ? "" : `?${new URLSearchParams({ serviceCode: resolved }).toString()}`;
3581
+ return fetchWithAuth(`${CREDIT_PACKS_ENDPOINT}${qs}`);
3582
+ }
3583
+ async function createPackCheckout(params) {
3584
+ if (authMode !== "token") {
3585
+ return forbidden(
3586
+ "bearer_required",
3587
+ "createPackCheckout \u306F token \u30E2\u30FC\u30C9\uFF08Bearer\uFF09\u3067\u306E\u307F\u5229\u7528\u3067\u304D\u307E\u3059\u3002\u8CFC\u5165\u8005\u306E\u8A18\u9332\u306B\u5B9F\u30E6\u30FC\u30B6\u30FC\u304C\u5FC5\u8981\u306A\u305F\u3081\u3067\u3059"
3588
+ );
3589
+ }
3590
+ const invalid = missingSubscriptionId(params.subscriptionId);
3591
+ if (invalid) return invalid;
3592
+ for (const field of ["packCode", "successUrl", "cancelUrl"]) {
3593
+ if (!params[field] || !params[field].trim()) {
3594
+ return validationError(field, `${field} \u306F\u5FC5\u9808\u3067\u3059`);
3595
+ }
3596
+ }
3597
+ if (params.quantity !== void 0 && !isIntegerInRange(params.quantity, FFID_CREDIT_PACK_MIN_QUANTITY, FFID_CREDIT_PACK_MAX_QUANTITY)) {
3598
+ return validationError(
3599
+ "quantity",
3600
+ `quantity \u306F ${FFID_CREDIT_PACK_MIN_QUANTITY}\u301C${FFID_CREDIT_PACK_MAX_QUANTITY} \u306E\u6574\u6570\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`
3601
+ );
3602
+ }
3603
+ const body = {
3604
+ subscriptionId: params.subscriptionId,
3605
+ packCode: params.packCode,
3606
+ successUrl: params.successUrl,
3607
+ cancelUrl: params.cancelUrl
3608
+ };
3609
+ if (params.quantity !== void 0) body.quantity = params.quantity;
3610
+ return fetchWithAuth(CREDIT_PACK_CHECKOUT_ENDPOINT, {
3611
+ method: "POST",
3612
+ body: JSON.stringify(body)
3613
+ });
3614
+ }
3615
+ function validateConsume(params) {
3616
+ const invalid = missingSubscriptionId(params.subscriptionId);
3617
+ if (invalid) return invalid;
3618
+ if (!isIntegerInRange(params.amount, FFID_CREDITS_CONSUME_MIN_AMOUNT, FFID_CREDITS_CONSUME_MAX_AMOUNT)) {
3619
+ return validationError(
3620
+ "amount",
3621
+ `amount \u306F ${FFID_CREDITS_CONSUME_MIN_AMOUNT}\u301C${FFID_CREDITS_CONSUME_MAX_AMOUNT} \u306E\u6574\u6570\u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044`
3622
+ );
3623
+ }
3624
+ if (typeof params.idempotencyKey !== "string" || !FFID_CREDITS_IDEMPOTENCY_KEY_PATTERN.test(params.idempotencyKey)) {
3625
+ return validationError(
3626
+ "idempotencyKey",
3627
+ "idempotencyKey \u306E\u5F62\u5F0F\u304C\u4E0D\u6B63\u3067\u3059\uFF08\u82F1\u6570\u5B57\u3068 . _ : - \u306E 8\u301C128 \u6587\u5B57\u3002\u63A8\u5968\u306F feature:requestId\uFF09"
3628
+ );
3629
+ }
3630
+ if (typeof params.feature !== "string" || !FFID_CREDITS_FEATURE_PATTERN.test(params.feature)) {
3631
+ return validationError("feature", "feature \u306E\u5F62\u5F0F\u304C\u4E0D\u6B63\u3067\u3059\uFF08\u5C0F\u6587\u5B57\u82F1\u6570\u5B57\u3067\u59CB\u307E\u308B\u3001\u5C0F\u6587\u5B57\u82F1\u6570\u5B57\u3068 . _ - \u306E 1\u301C64 \u6587\u5B57\uFF09");
3632
+ }
3633
+ if (params.metadata !== void 0) {
3634
+ if (!isPlainObject2(params.metadata)) {
3635
+ return validationError("metadata", "metadata \u306F JSON \u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059");
3636
+ }
3637
+ let serialized;
3638
+ try {
3639
+ serialized = JSON.stringify(params.metadata);
3640
+ } catch {
3641
+ return validationError("metadata", "metadata \u306F JSON \u306B\u5909\u63DB\u3067\u304D\u308B\u5024\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059\uFF08BigInt\u30FB\u5FAA\u74B0\u53C2\u7167\u306F\u4E0D\u53EF\uFF09");
3642
+ }
3643
+ if (utf8Encoder.encode(serialized).byteLength > FFID_CREDITS_METADATA_MAX_BYTES) {
3644
+ return validationError("metadata", `metadata \u306F ${FFID_CREDITS_METADATA_MAX_BYTES} \u30D0\u30A4\u30C8\u4EE5\u4E0B\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059`);
3645
+ }
3646
+ }
3647
+ if (params.userId !== void 0 && !UUID_PATTERN.test(params.userId)) {
3648
+ return validationError("userId", "userId \u306F\u6709\u52B9\u306AUUID\u5F62\u5F0F\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059");
3649
+ }
3650
+ return null;
3651
+ }
3652
+ async function consume(params) {
3653
+ if (authMode !== "service-key") {
3654
+ return forbidden(
3655
+ "api_key_required",
3656
+ "credits.consume \u306F service-key \u8A8D\u8A3C\uFF08X-Service-Api-Key\uFF09\u3067\u306E\u307F\u5229\u7528\u3067\u304D\u307E\u3059\u3002\u6D88\u8CBB\u306E\u5831\u544A\u306F\u30B5\u30FC\u30D3\u30B9\u306E\u30D0\u30C3\u30AF\u30A8\u30F3\u30C9\u304B\u3089\u884C\u3063\u3066\u304F\u3060\u3055\u3044"
3657
+ );
3658
+ }
3659
+ const invalid = validateConsume(params);
3660
+ if (invalid) return invalid;
3661
+ const body = {
3662
+ amount: params.amount,
3663
+ idempotencyKey: params.idempotencyKey,
3664
+ feature: params.feature
3665
+ };
3666
+ if (params.metadata !== void 0) body.metadata = params.metadata;
3667
+ if (params.userId !== void 0) body.userId = params.userId;
3668
+ return fetchWithAuth(creditsEndpoint(params.subscriptionId, "consume"), {
3669
+ method: "POST",
3670
+ body: JSON.stringify(body)
3671
+ });
3672
+ }
3673
+ function getBuyCreditsUrl(params) {
3674
+ const raw = params.subscriptionId?.trim() ?? "";
3675
+ if (raw.startsWith(STRIPE_SUBSCRIPTION_ID_PREFIX)) {
3676
+ return validationError(
3677
+ "subscriptionId",
3678
+ "getBuyCreditsUrl \u306B\u306F\u5951\u7D04\u306E UUID\uFF08\u307E\u305F\u306F ffid:<uuid>\uFF09\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002Stripe \u306E sub_... \u306F\u4F7F\u3048\u307E\u305B\u3093"
3679
+ );
3680
+ }
3681
+ const uuid = raw.startsWith(FFID_CONTRACT_ID_PREFIX) ? raw.slice(FFID_CONTRACT_ID_PREFIX.length) : raw;
3682
+ if (!UUID_PATTERN.test(uuid)) {
3683
+ return validationError("subscriptionId", "subscriptionId \u306F\u5951\u7D04\u306E UUID\uFF08\u307E\u305F\u306F ffid:<uuid>\uFF09\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059");
3684
+ }
3685
+ const query = new URLSearchParams({ [BUY_CREDITS_QUERY.key]: BUY_CREDITS_QUERY.value });
3686
+ if (params.orgId !== void 0 && params.orgId.trim()) {
3687
+ query.set(ORG_QUERY_KEY, params.orgId);
3688
+ }
3689
+ return { data: `${baseUrl}${PORTAL_SUBSCRIPTION_PATH}/${encodeURIComponent(uuid)}?${query.toString()}` };
3690
+ }
3691
+ function redirectToBuyCredits(params) {
3692
+ const result = getBuyCreditsUrl(params);
3693
+ if (result.error) {
3694
+ logger.warn("redirectToBuyCredits:", result.error.message);
3695
+ return { success: false, error: result.error.message };
3696
+ }
3697
+ if (typeof window === "undefined") {
3698
+ logger.warn("SSR \u74B0\u5883\u3067\u306F\u30EA\u30C0\u30A4\u30EC\u30AF\u30C8\u3067\u304D\u307E\u305B\u3093");
3699
+ return { success: false, error: "SSR \u74B0\u5883\u3067\u306F\u30EA\u30C0\u30A4\u30EC\u30AF\u30C8\u3067\u304D\u307E\u305B\u3093" };
3700
+ }
3701
+ logger.debug("Redirecting to buy credits:", result.data);
3702
+ window.location.href = result.data;
3703
+ return { success: true };
3704
+ }
3705
+ return {
3706
+ getBalance,
3707
+ listHistory,
3708
+ listPacks,
3709
+ createPackCheckout,
3710
+ consume,
3711
+ getBuyCreditsUrl,
3712
+ redirectToBuyCredits
3713
+ };
3714
+ }
3715
+
3491
3716
  // src/subscriptions/userinfo-helpers.ts
3492
3717
  var ACCESS_GRANTING_EFFECTIVE_STATUSES = [
3493
3718
  "active",
@@ -3546,7 +3771,12 @@ function toServiceAccessDecision(response, allowGrace) {
3546
3771
  planCode: response.planCode,
3547
3772
  currentPeriodEnd: response.currentPeriodEnd,
3548
3773
  gracePeriodEndsAt: response.gracePeriodEndsAt ?? null,
3549
- reactivatable: response.reactivatable ?? false
3774
+ reactivatable: response.reactivatable ?? false,
3775
+ // Informational pass-through (10.0.0). Deliberately not part of hasAccess /
3776
+ // denialReason: credits and the member limit never gate access (CREDITS_API §1-5).
3777
+ ...response.pricingModel !== void 0 ? { pricingModel: response.pricingModel } : {},
3778
+ ...response.credits !== void 0 ? { credits: response.credits } : {},
3779
+ ...response.memberLimitReached !== void 0 ? { memberLimitReached: response.memberLimitReached } : {}
3550
3780
  };
3551
3781
  }
3552
3782
  function failClosedServiceAccessDecision(params, error) {
@@ -3908,7 +4138,7 @@ function createFFIDClient(config) {
3908
4138
  fetchWithAuth,
3909
4139
  createError
3910
4140
  });
3911
- const { listSeatAssignments, assignSeats, unassignSeat } = createSeatMethods({
4141
+ const { listSeatAssignments, getSeats, assignSeats, unassignSeat } = createSeatMethods({
3912
4142
  fetchWithAuth,
3913
4143
  createError
3914
4144
  });
@@ -4015,6 +4245,14 @@ function createFFIDClient(config) {
4015
4245
  fetchWithAuth,
4016
4246
  createError
4017
4247
  });
4248
+ const credits = createCreditsMethods({
4249
+ fetchWithAuth,
4250
+ createError,
4251
+ authMode,
4252
+ baseUrl,
4253
+ serviceCode: config.serviceCode,
4254
+ logger
4255
+ });
4018
4256
  const verifyAccessToken = createVerifyAccessToken({
4019
4257
  authMode,
4020
4258
  baseUrl,
@@ -4070,6 +4308,7 @@ function createFFIDClient(config) {
4070
4308
  getInvoice,
4071
4309
  retryPayment,
4072
4310
  listSeatAssignments,
4311
+ getSeats,
4073
4312
  assignSeats,
4074
4313
  unassignSeat,
4075
4314
  listPlans,
@@ -4080,13 +4319,16 @@ function createFFIDClient(config) {
4080
4319
  cancelSubscription,
4081
4320
  cancelPendingDowngrade,
4082
4321
  previewPlanChange,
4322
+ /** @deprecated 10.0.0: per_seat (praxis) only; removed in 11.0.0 */
4083
4323
  previewSeatChange,
4084
4324
  verifyAccessToken,
4085
4325
  getSubscribeUrl,
4086
4326
  redirectToSubscribe,
4087
4327
  getChangePlanUrl,
4088
4328
  redirectToChangePlan,
4329
+ /** @deprecated 10.0.0: per_seat (praxis) only; removed in 11.0.0 */
4089
4330
  getChangeSeatsUrl,
4331
+ /** @deprecated 10.0.0: per_seat (praxis) only; removed in 11.0.0 */
4090
4332
  redirectToChangeSeats,
4091
4333
  getRecoverPaymentUrl,
4092
4334
  redirectToRecoverPayment,
@@ -4102,6 +4344,8 @@ function createFFIDClient(config) {
4102
4344
  newsletter,
4103
4345
  /** Inquiry methods (create) */
4104
4346
  inquiry,
4347
+ /** Credits methods for flat plans (consume / balance / history / packs) */
4348
+ credits,
4105
4349
  /** Token store (token mode only) */
4106
4350
  tokenStore,
4107
4351
  /**
@@ -1,4 +1,4 @@
1
- import { r as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-6aLs9Fqc.cjs';
1
+ import { r as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-CumygXXz.cjs';
2
2
  import '../../types-Cjb9J0rL.cjs';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { r as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-B0cORHac.js';
1
+ import { r as FFIDClient, e as FFIDOAuthUserInfo } from '../../ffid-client-5uxXRgIO.js';
2
2
  import '../../types-Cjb9J0rL.js';
3
3
 
4
4
  /**
@@ -39,6 +39,74 @@ declare class FFIDWebhookPayloadError extends FFIDWebhookError {
39
39
  constructor(message?: string);
40
40
  }
41
41
 
42
+ /**
43
+ * `credits.*` webhook payloads (SDK 10.0.0, FFID CREDITS_API §8).
44
+ *
45
+ * Separate file to keep `types.ts` small. Mirrors the FFID server's
46
+ * `src/lib/webhooks/credits-payloads.ts`; the FFID repository type-checks the two
47
+ * against each other (`sdk-credits-payloads.sync.test.ts`).
48
+ */
49
+ /**
50
+ * Fields every `credits.*` payload carries (10.0.0, CREDITS_API §8).
51
+ *
52
+ * `credits.*` events are broadcast to every endpoint subscribed to the event type,
53
+ * so compare `serviceCode` with your own service code before acting. It is absent
54
+ * only when FFID could not resolve it — do not read absence as "not for this service".
55
+ */
56
+ interface FFIDCreditsEventBase {
57
+ subscriptionId: string;
58
+ organizationId: string;
59
+ /** Time the event happened (ISO 8601) */
60
+ occurredAt: string;
61
+ serviceCode?: string;
62
+ }
63
+ /**
64
+ * `credits.granted` — a monthly / manual / pack grant was created. Sent once per
65
+ * grant (`grantId`). A pack purchase also sends `credits.pack_purchased`.
66
+ */
67
+ interface FFIDCreditsGrantedPayload extends FFIDCreditsEventBase {
68
+ grantId: string;
69
+ kind: 'monthly' | 'manual' | 'pack';
70
+ amount: number;
71
+ expiresAt: string;
72
+ /** Only when `kind === 'monthly'` */
73
+ periodStart?: string;
74
+ /** Only when `kind === 'monthly'` */
75
+ periodEnd?: string;
76
+ /** Balance read after the grant — a reference value; the balance API is authoritative */
77
+ balanceAfter: number;
78
+ }
79
+ /** `credits.low` — the balance fell below the low threshold (once per period) */
80
+ interface FFIDCreditsLowPayload extends FFIDCreditsEventBase {
81
+ available: number;
82
+ monthlyCredits: number;
83
+ thresholdPercent: number;
84
+ /** End of the current period; null only when FFID could not read it */
85
+ periodEnd: string | null;
86
+ }
87
+ /** `credits.exhausted` — the balance reached 0 (once per period) */
88
+ interface FFIDCreditsExhaustedPayload extends FFIDCreditsEventBase {
89
+ available: number;
90
+ monthlyCredits: number;
91
+ /** End of the current period; null only when FFID could not read it */
92
+ periodEnd: string | null;
93
+ }
94
+ /** `credits.pack_purchased` — a credit pack purchase completed and its credits were granted */
95
+ interface FFIDCreditsPackPurchasedPayload extends FFIDCreditsEventBase {
96
+ operationId: string;
97
+ grantId: string;
98
+ packCode: string;
99
+ /** Credits granted in total (pack credits × `quantity`) */
100
+ credits: number;
101
+ quantity: number;
102
+ /** Amount paid (tax-inclusive, smallest currency unit) */
103
+ amount: number;
104
+ currency: string;
105
+ expiresAt: string;
106
+ /** User who bought the pack */
107
+ purchasedBy: string;
108
+ }
109
+
42
110
  /**
43
111
  * FFID Webhook SDK Type Definitions
44
112
  *
@@ -47,7 +115,7 @@ declare class FFIDWebhookPayloadError extends FFIDWebhookError {
47
115
  */
48
116
 
49
117
  /** All supported webhook event types */
50
- type FFIDWebhookEventType = 'subscription.created' | 'subscription.reactivated' | 'subscription.updated' | 'subscription.canceled' | 'subscription.downgrade_scheduled' | 'subscription.downgrade_applied' | 'subscription.downgrade_canceled' | 'subscription.trial_ending' | 'subscription.payment_failed' | 'user.created' | 'user.updated' | 'user.deleted' | 'user.deletion_requested' | 'organization.created' | 'organization.updated' | 'organization.member.added' | 'organization.member.removed' | 'organization.member.role_changed' | 'legal.document.updated' | 'legal.agreement.required' | 'system.maintenance.scheduled' | 'system.maintenance.started' | 'system.maintenance.completed' | 'announcement.published' | 'test.ping';
118
+ type FFIDWebhookEventType = 'subscription.created' | 'subscription.reactivated' | 'subscription.updated' | 'subscription.canceled' | 'subscription.downgrade_scheduled' | 'subscription.downgrade_applied' | 'subscription.downgrade_canceled' | 'subscription.trial_ending' | 'subscription.payment_failed' | 'user.created' | 'user.updated' | 'user.deleted' | 'user.deletion_requested' | 'organization.created' | 'organization.updated' | 'organization.member.added' | 'organization.member.removed' | 'organization.member.role_changed' | 'legal.document.updated' | 'legal.agreement.required' | 'system.maintenance.scheduled' | 'system.maintenance.started' | 'system.maintenance.completed' | 'announcement.published' | 'credits.granted' | 'credits.low' | 'credits.exhausted' | 'credits.pack_purchased' | 'test.ping';
51
119
  interface FFIDSubscriptionCreatedPayload {
52
120
  subscriptionId: string;
53
121
  organizationId?: string;
@@ -453,6 +521,10 @@ interface FFIDWebhookEventMap {
453
521
  'system.maintenance.started': FFIDSystemMaintenancePayload;
454
522
  'system.maintenance.completed': FFIDSystemMaintenancePayload;
455
523
  'announcement.published': FFIDAnnouncementPublishedPayload;
524
+ 'credits.granted': FFIDCreditsGrantedPayload;
525
+ 'credits.low': FFIDCreditsLowPayload;
526
+ 'credits.exhausted': FFIDCreditsExhaustedPayload;
527
+ 'credits.pack_purchased': FFIDCreditsPackPurchasedPayload;
456
528
  'test.ping': FFIDTestPingPayload;
457
529
  }
458
530
  /** A webhook event envelope with typed payload */
@@ -578,4 +650,4 @@ declare function createFFIDWebhookHandler(config: FFIDWebhookHandlerConfig): {
578
650
  /** Type of the FFID Webhook handler */
579
651
  type FFIDWebhookHandler = ReturnType<typeof createFFIDWebhookHandler>;
580
652
 
581
- export { DEFAULT_TOLERANCE_SECONDS, type FFIDLegalAgreementRequiredPayload, type FFIDLegalDocumentUpdatedPayload, type FFIDOrganizationCreatedPayload, type FFIDOrganizationMemberAddedPayload, type FFIDOrganizationMemberRemovedPayload, type FFIDOrganizationMemberRoleChangedPayload, type FFIDOrganizationUpdatedPayload, type FFIDSubscriptionCanceledPayload, type FFIDSubscriptionCreatedPayload, type FFIDSubscriptionDowngradeAppliedPayload, type FFIDSubscriptionDowngradeCanceledPayload, type FFIDSubscriptionDowngradeScheduledPayload, type FFIDSubscriptionPaymentFailedPayload, type FFIDSubscriptionReactivatedPayload, type FFIDSubscriptionTrialEndingPayload, type FFIDSubscriptionUpdatedPayload, type FFIDSystemMaintenancePayload, type FFIDTestPingPayload, type FFIDUserCreatedPayload, type FFIDUserDeletedPayload, type FFIDUserDeletionRequestedPayload, type FFIDUserUpdatedPayload, FFIDWebhookError, type FFIDWebhookEvent, type FFIDWebhookEventHandler, type FFIDWebhookEventMap, type FFIDWebhookEventType, type FFIDWebhookHandler, type FFIDWebhookHandlerConfig, type FFIDWebhookLogger, FFIDWebhookPayloadError, FFIDWebhookSignatureError, FFIDWebhookTimestampError, FFID_WEBHOOK_EVENT_ID_HEADER, FFID_WEBHOOK_SIGNATURE_HEADER, FFID_WEBHOOK_SIGNATURE_VERSION, FFID_WEBHOOK_TIMESTAMP_HEADER, computeSignature, createFFIDWebhookHandler, parseSignatureHeader, verifyWebhookSignature };
653
+ export { DEFAULT_TOLERANCE_SECONDS, type FFIDAnnouncementPublishedPayload, type FFIDCreditsExhaustedPayload, type FFIDCreditsGrantedPayload, type FFIDCreditsLowPayload, type FFIDCreditsPackPurchasedPayload, type FFIDLegalAgreementRequiredPayload, type FFIDLegalDocumentUpdatedPayload, type FFIDOrganizationCreatedPayload, type FFIDOrganizationMemberAddedPayload, type FFIDOrganizationMemberRemovedPayload, type FFIDOrganizationMemberRoleChangedPayload, type FFIDOrganizationUpdatedPayload, type FFIDSubscriptionCanceledPayload, type FFIDSubscriptionCreatedPayload, type FFIDSubscriptionDowngradeAppliedPayload, type FFIDSubscriptionDowngradeCanceledPayload, type FFIDSubscriptionDowngradeScheduledPayload, type FFIDSubscriptionPaymentFailedPayload, type FFIDSubscriptionReactivatedPayload, type FFIDSubscriptionTrialEndingPayload, type FFIDSubscriptionUpdatedPayload, type FFIDSystemMaintenancePayload, type FFIDTestPingPayload, type FFIDUserCreatedPayload, type FFIDUserDeletedPayload, type FFIDUserDeletionRequestedPayload, type FFIDUserUpdatedPayload, FFIDWebhookError, type FFIDWebhookEvent, type FFIDWebhookEventHandler, type FFIDWebhookEventMap, type FFIDWebhookEventType, type FFIDWebhookHandler, type FFIDWebhookHandlerConfig, type FFIDWebhookLogger, FFIDWebhookPayloadError, FFIDWebhookSignatureError, FFIDWebhookTimestampError, FFID_WEBHOOK_EVENT_ID_HEADER, FFID_WEBHOOK_SIGNATURE_HEADER, FFID_WEBHOOK_SIGNATURE_VERSION, FFID_WEBHOOK_TIMESTAMP_HEADER, computeSignature, createFFIDWebhookHandler, parseSignatureHeader, verifyWebhookSignature };
@@ -39,6 +39,74 @@ declare class FFIDWebhookPayloadError extends FFIDWebhookError {
39
39
  constructor(message?: string);
40
40
  }
41
41
 
42
+ /**
43
+ * `credits.*` webhook payloads (SDK 10.0.0, FFID CREDITS_API §8).
44
+ *
45
+ * Separate file to keep `types.ts` small. Mirrors the FFID server's
46
+ * `src/lib/webhooks/credits-payloads.ts`; the FFID repository type-checks the two
47
+ * against each other (`sdk-credits-payloads.sync.test.ts`).
48
+ */
49
+ /**
50
+ * Fields every `credits.*` payload carries (10.0.0, CREDITS_API §8).
51
+ *
52
+ * `credits.*` events are broadcast to every endpoint subscribed to the event type,
53
+ * so compare `serviceCode` with your own service code before acting. It is absent
54
+ * only when FFID could not resolve it — do not read absence as "not for this service".
55
+ */
56
+ interface FFIDCreditsEventBase {
57
+ subscriptionId: string;
58
+ organizationId: string;
59
+ /** Time the event happened (ISO 8601) */
60
+ occurredAt: string;
61
+ serviceCode?: string;
62
+ }
63
+ /**
64
+ * `credits.granted` — a monthly / manual / pack grant was created. Sent once per
65
+ * grant (`grantId`). A pack purchase also sends `credits.pack_purchased`.
66
+ */
67
+ interface FFIDCreditsGrantedPayload extends FFIDCreditsEventBase {
68
+ grantId: string;
69
+ kind: 'monthly' | 'manual' | 'pack';
70
+ amount: number;
71
+ expiresAt: string;
72
+ /** Only when `kind === 'monthly'` */
73
+ periodStart?: string;
74
+ /** Only when `kind === 'monthly'` */
75
+ periodEnd?: string;
76
+ /** Balance read after the grant — a reference value; the balance API is authoritative */
77
+ balanceAfter: number;
78
+ }
79
+ /** `credits.low` — the balance fell below the low threshold (once per period) */
80
+ interface FFIDCreditsLowPayload extends FFIDCreditsEventBase {
81
+ available: number;
82
+ monthlyCredits: number;
83
+ thresholdPercent: number;
84
+ /** End of the current period; null only when FFID could not read it */
85
+ periodEnd: string | null;
86
+ }
87
+ /** `credits.exhausted` — the balance reached 0 (once per period) */
88
+ interface FFIDCreditsExhaustedPayload extends FFIDCreditsEventBase {
89
+ available: number;
90
+ monthlyCredits: number;
91
+ /** End of the current period; null only when FFID could not read it */
92
+ periodEnd: string | null;
93
+ }
94
+ /** `credits.pack_purchased` — a credit pack purchase completed and its credits were granted */
95
+ interface FFIDCreditsPackPurchasedPayload extends FFIDCreditsEventBase {
96
+ operationId: string;
97
+ grantId: string;
98
+ packCode: string;
99
+ /** Credits granted in total (pack credits × `quantity`) */
100
+ credits: number;
101
+ quantity: number;
102
+ /** Amount paid (tax-inclusive, smallest currency unit) */
103
+ amount: number;
104
+ currency: string;
105
+ expiresAt: string;
106
+ /** User who bought the pack */
107
+ purchasedBy: string;
108
+ }
109
+
42
110
  /**
43
111
  * FFID Webhook SDK Type Definitions
44
112
  *
@@ -47,7 +115,7 @@ declare class FFIDWebhookPayloadError extends FFIDWebhookError {
47
115
  */
48
116
 
49
117
  /** All supported webhook event types */
50
- type FFIDWebhookEventType = 'subscription.created' | 'subscription.reactivated' | 'subscription.updated' | 'subscription.canceled' | 'subscription.downgrade_scheduled' | 'subscription.downgrade_applied' | 'subscription.downgrade_canceled' | 'subscription.trial_ending' | 'subscription.payment_failed' | 'user.created' | 'user.updated' | 'user.deleted' | 'user.deletion_requested' | 'organization.created' | 'organization.updated' | 'organization.member.added' | 'organization.member.removed' | 'organization.member.role_changed' | 'legal.document.updated' | 'legal.agreement.required' | 'system.maintenance.scheduled' | 'system.maintenance.started' | 'system.maintenance.completed' | 'announcement.published' | 'test.ping';
118
+ type FFIDWebhookEventType = 'subscription.created' | 'subscription.reactivated' | 'subscription.updated' | 'subscription.canceled' | 'subscription.downgrade_scheduled' | 'subscription.downgrade_applied' | 'subscription.downgrade_canceled' | 'subscription.trial_ending' | 'subscription.payment_failed' | 'user.created' | 'user.updated' | 'user.deleted' | 'user.deletion_requested' | 'organization.created' | 'organization.updated' | 'organization.member.added' | 'organization.member.removed' | 'organization.member.role_changed' | 'legal.document.updated' | 'legal.agreement.required' | 'system.maintenance.scheduled' | 'system.maintenance.started' | 'system.maintenance.completed' | 'announcement.published' | 'credits.granted' | 'credits.low' | 'credits.exhausted' | 'credits.pack_purchased' | 'test.ping';
51
119
  interface FFIDSubscriptionCreatedPayload {
52
120
  subscriptionId: string;
53
121
  organizationId?: string;
@@ -453,6 +521,10 @@ interface FFIDWebhookEventMap {
453
521
  'system.maintenance.started': FFIDSystemMaintenancePayload;
454
522
  'system.maintenance.completed': FFIDSystemMaintenancePayload;
455
523
  'announcement.published': FFIDAnnouncementPublishedPayload;
524
+ 'credits.granted': FFIDCreditsGrantedPayload;
525
+ 'credits.low': FFIDCreditsLowPayload;
526
+ 'credits.exhausted': FFIDCreditsExhaustedPayload;
527
+ 'credits.pack_purchased': FFIDCreditsPackPurchasedPayload;
456
528
  'test.ping': FFIDTestPingPayload;
457
529
  }
458
530
  /** A webhook event envelope with typed payload */
@@ -578,4 +650,4 @@ declare function createFFIDWebhookHandler(config: FFIDWebhookHandlerConfig): {
578
650
  /** Type of the FFID Webhook handler */
579
651
  type FFIDWebhookHandler = ReturnType<typeof createFFIDWebhookHandler>;
580
652
 
581
- export { DEFAULT_TOLERANCE_SECONDS, type FFIDLegalAgreementRequiredPayload, type FFIDLegalDocumentUpdatedPayload, type FFIDOrganizationCreatedPayload, type FFIDOrganizationMemberAddedPayload, type FFIDOrganizationMemberRemovedPayload, type FFIDOrganizationMemberRoleChangedPayload, type FFIDOrganizationUpdatedPayload, type FFIDSubscriptionCanceledPayload, type FFIDSubscriptionCreatedPayload, type FFIDSubscriptionDowngradeAppliedPayload, type FFIDSubscriptionDowngradeCanceledPayload, type FFIDSubscriptionDowngradeScheduledPayload, type FFIDSubscriptionPaymentFailedPayload, type FFIDSubscriptionReactivatedPayload, type FFIDSubscriptionTrialEndingPayload, type FFIDSubscriptionUpdatedPayload, type FFIDSystemMaintenancePayload, type FFIDTestPingPayload, type FFIDUserCreatedPayload, type FFIDUserDeletedPayload, type FFIDUserDeletionRequestedPayload, type FFIDUserUpdatedPayload, FFIDWebhookError, type FFIDWebhookEvent, type FFIDWebhookEventHandler, type FFIDWebhookEventMap, type FFIDWebhookEventType, type FFIDWebhookHandler, type FFIDWebhookHandlerConfig, type FFIDWebhookLogger, FFIDWebhookPayloadError, FFIDWebhookSignatureError, FFIDWebhookTimestampError, FFID_WEBHOOK_EVENT_ID_HEADER, FFID_WEBHOOK_SIGNATURE_HEADER, FFID_WEBHOOK_SIGNATURE_VERSION, FFID_WEBHOOK_TIMESTAMP_HEADER, computeSignature, createFFIDWebhookHandler, parseSignatureHeader, verifyWebhookSignature };
653
+ export { DEFAULT_TOLERANCE_SECONDS, type FFIDAnnouncementPublishedPayload, type FFIDCreditsExhaustedPayload, type FFIDCreditsGrantedPayload, type FFIDCreditsLowPayload, type FFIDCreditsPackPurchasedPayload, type FFIDLegalAgreementRequiredPayload, type FFIDLegalDocumentUpdatedPayload, type FFIDOrganizationCreatedPayload, type FFIDOrganizationMemberAddedPayload, type FFIDOrganizationMemberRemovedPayload, type FFIDOrganizationMemberRoleChangedPayload, type FFIDOrganizationUpdatedPayload, type FFIDSubscriptionCanceledPayload, type FFIDSubscriptionCreatedPayload, type FFIDSubscriptionDowngradeAppliedPayload, type FFIDSubscriptionDowngradeCanceledPayload, type FFIDSubscriptionDowngradeScheduledPayload, type FFIDSubscriptionPaymentFailedPayload, type FFIDSubscriptionReactivatedPayload, type FFIDSubscriptionTrialEndingPayload, type FFIDSubscriptionUpdatedPayload, type FFIDSystemMaintenancePayload, type FFIDTestPingPayload, type FFIDUserCreatedPayload, type FFIDUserDeletedPayload, type FFIDUserDeletionRequestedPayload, type FFIDUserUpdatedPayload, FFIDWebhookError, type FFIDWebhookEvent, type FFIDWebhookEventHandler, type FFIDWebhookEventMap, type FFIDWebhookEventType, type FFIDWebhookHandler, type FFIDWebhookHandlerConfig, type FFIDWebhookLogger, FFIDWebhookPayloadError, FFIDWebhookSignatureError, FFIDWebhookTimestampError, FFID_WEBHOOK_EVENT_ID_HEADER, FFID_WEBHOOK_SIGNATURE_HEADER, FFID_WEBHOOK_SIGNATURE_VERSION, FFID_WEBHOOK_TIMESTAMP_HEADER, computeSignature, createFFIDWebhookHandler, parseSignatureHeader, verifyWebhookSignature };