@feelflow/ffid-sdk 2.18.0 → 2.19.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.
@@ -22,6 +22,42 @@ interface FFIDCacheConfig {
22
22
  ttl: number;
23
23
  }
24
24
 
25
+ /**
26
+ * Subscription access-control types (Chain of Pacts / Issue #2443).
27
+ *
28
+ * Defines `EffectiveSubscriptionStatus` — the semantic status surfaced by
29
+ * `/api/v1/subscriptions/ext/check` for external services that need a single
30
+ * value to drive access-control decisions. Mirrors the server-side type in
31
+ * `src/lib/common/subscription-helpers.ts` so the FFID backend, SDK, and
32
+ * consuming services agree on the same vocabulary.
33
+ */
34
+ /**
35
+ * Semantic subscription status used for access-control decisions by external
36
+ * services.
37
+ *
38
+ * Unlike the raw DB `FFIDSubscriptionStatus` (which keeps the Stripe-aligned
39
+ * status machine, e.g. `past_due` / `incomplete` / `incomplete_expired`), this
40
+ * narrowed union flattens dunning-window vs. hard-block cases so callers can
41
+ * branch on a single value:
42
+ *
43
+ * - `active` — normal paying subscription; grant full access.
44
+ * - `past_due_grace` — payment failed but FFID is still retrying. Service
45
+ * SHOULD keep access and surface a recovery banner.
46
+ * - `blocked` — payment dunning exhausted (`past_due` over grace,
47
+ * `unpaid`, `incomplete_expired`, `paused`, `incomplete`). Deny access.
48
+ * - `canceled` — contract ended (voluntary or auto-cancel). Deny access;
49
+ * check the accompanying `reactivatable` flag before showing a restart CTA.
50
+ * - `trial_expired` — `status = 'trialing'` but the trial end is in the past.
51
+ * DB row is still `trialing`; deny access and prompt for a paid plan.
52
+ * - `expired` — `status = 'active'` but `current_period_end` is in the past.
53
+ * This is the FFID-internal runtime-expired case (see
54
+ * `getEffectiveSubscriptionStatus` on the server). Deny access.
55
+ *
56
+ * @see /api/v1/subscriptions/ext/check
57
+ * @see docs/03-implementation/EXPIRED_CONTRACT_HANDLING.md
58
+ */
59
+ type EffectiveSubscriptionStatus = 'active' | 'past_due_grace' | 'blocked' | 'canceled' | 'trial_expired' | 'expired';
60
+
25
61
  /**
26
62
  * FFID SDK Type Definitions
27
63
  *
@@ -284,10 +320,59 @@ interface FFIDSubscriptionContextValue {
284
320
  isTrialExpired: boolean;
285
321
  /** Whether subscription is canceled */
286
322
  isCanceled: boolean;
323
+ /**
324
+ * Semantic access-control status for the current subscription.
325
+ *
326
+ * Always computed locally from the session response via
327
+ * `computeEffectiveStatusFromSession` (status + currentPeriodEnd + trialEnd).
328
+ * The session endpoint does not currently surface an authoritative
329
+ * effectiveStatus, so this is a best-effort approximation suitable for UI
330
+ * decisions that tolerate ~1 request worth of staleness.
331
+ *
332
+ * For authoritative decisions (e.g., paywall gates on billing-critical UI,
333
+ * grace-window banners that depend on `gracePeriodEndsAt`, or reactivation
334
+ * CTAs that depend on `reactivatable`), call the server-side
335
+ * `/api/v1/subscriptions/ext/check` endpoint directly — it returns a richer
336
+ * payload (`effectiveStatus`, `gracePeriodEndsAt`, `reactivatable`) computed
337
+ * against the live DB.
338
+ *
339
+ * `null` when there is no subscription for the current service.
340
+ *
341
+ * @see {@link EffectiveSubscriptionStatus}
342
+ */
343
+ effectiveStatus: EffectiveSubscriptionStatus | null;
344
+ /**
345
+ * Whether the subscription is in an access-blocking terminal state
346
+ * (`blocked` | `expired` | `canceled` | `trial_expired`).
347
+ */
348
+ isBlocked: boolean;
349
+ /**
350
+ * Whether the subscription is inside the payment-failure grace window
351
+ * (`past_due_grace`). Access is still granted by `hasAccess`, but UIs
352
+ * should surface a recovery banner.
353
+ */
354
+ isGrace: boolean;
287
355
  /** Check if user has specific plan */
288
356
  hasPlan: (plans: string | string[]) => boolean;
289
- /** Check if user has access (active or trialing subscription) */
357
+ /**
358
+ * Whether the user currently has access.
359
+ *
360
+ * Post Chain-of-Pacts (Issue #2444): `true` when
361
+ * `effectiveStatus === 'active' || effectiveStatus === 'past_due_grace'`.
362
+ * Legacy consumers that need the pre-2444 semantics
363
+ * (`status === 'active' || status === 'trialing'`) can use
364
+ * `hasAccessLegacy()`.
365
+ */
290
366
  hasAccess: () => boolean;
367
+ /**
368
+ * Pre-2444 `hasAccess` semantics: `true` when the raw DB status is
369
+ * `active` or `trialing` (and, for trialing, the trial is not runtime-
370
+ * expired). Kept as a backwards-compatibility escape hatch so services
371
+ * that have not yet migrated to the effective-status model keep working.
372
+ *
373
+ * @deprecated Prefer `hasAccess()` or branch on `effectiveStatus` directly.
374
+ */
375
+ hasAccessLegacy: () => boolean;
291
376
  }
292
377
  /**
293
378
  * Logger interface for SDK debug output
@@ -1301,4 +1386,4 @@ interface FFIDInquiryFormPlaceholderContext {
1301
1386
  }
1302
1387
  declare function FFIDInquiryForm({ mode, prefill, organizations, preselectedOrganizationId, categories, termsVersion, privacyVersion, termsHref, privacyHref, turnstileToken, turnstileSlot, onSubmit, onChange, separateLegalCheckboxes, messagePlaceholder, requireCategorySelection, unstyled, classNames, locale, className, }: FFIDInquiryFormProps): react_jsx_runtime.JSX.Element;
1303
1388
 
1304
- export { type FFIDInquiryFormSubmitData as $, type FFIDSubscription as A, type FFIDSubscriptionContextValue as B, type FFIDAnnouncementsClientConfig as C, type FFIDAnnouncementsApiResponse as D, type AnnouncementListResponse as E, type FFIDSubscriptionStatus as F, type FFIDAnnouncementsLogger as G, type Announcement as H, type AnnouncementStatus as I, type AnnouncementType as J, FFIDAnnouncementBadge as K, type ListAnnouncementsOptions as L, FFIDAnnouncementList as M, type FFIDAnnouncementsError as N, type FFIDAnnouncementsErrorCode as O, type FFIDAnnouncementsServerResponse as P, type FFIDCacheConfig as Q, type FFIDContextValue as R, type FFIDInquiryCategory as S, type FFIDInquiryCategorySite2026 as T, FFIDInquiryForm as U, type FFIDInquiryFormCategoryItem as V, type FFIDInquiryFormClassNames as W, type FFIDInquiryFormOrganization as X, type FFIDInquiryFormPlaceholderContext as Y, type FFIDInquiryFormPrefill as Z, type FFIDInquiryFormProps as _, type FFIDConfig as a, type FFIDInquiryFormSubmitResult as a0, type FFIDJwtClaims as a1, FFIDLoginButton as a2, type FFIDMemberStatus as a3, type FFIDOAuthTokenResponse as a4, type FFIDOAuthUserInfoMemberRole as a5, type FFIDOAuthUserInfoSubscription as a6, type FFIDOrganizationMember as a7, FFIDOrganizationSwitcher as a8, type FFIDRedirectErrorCode as a9, type FFIDSeatModel as aa, FFIDSubscriptionBadge as ab, type FFIDTokenIntrospectionResponse as ac, FFIDUserMenu as ad, FFID_INQUIRY_CATEGORIES as ae, FFID_INQUIRY_CATEGORIES_SITE_2026 as af, type UseFFIDAnnouncementsOptions as ag, type UseFFIDAnnouncementsReturn as ah, isFFIDInquiryCategorySite2026 as ai, useFFIDAnnouncements as aj, type FFIDAnnouncementBadgeClassNames as ak, type FFIDAnnouncementBadgeProps as al, type FFIDAnnouncementListClassNames as am, type FFIDAnnouncementListProps as an, type FFIDLoginButtonProps as ao, type FFIDOrganizationSwitcherClassNames as ap, type FFIDOrganizationSwitcherProps as aq, type FFIDSubscriptionBadgeClassNames as ar, type FFIDSubscriptionBadgeProps as as, type FFIDUserMenuClassNames as at, type FFIDUserMenuProps as au, type FFIDApiResponse as b, type FFIDSessionResponse as c, type FFIDRedirectResult as d, type FFIDError as e, type FFIDSubscriptionCheckResponse as f, type FFIDListMembersResponse as g, type FFIDMemberRole as h, type FFIDUpdateMemberRoleResponse as i, type FFIDRemoveMemberResponse as j, type FFIDProfileCallOptions as k, type FFIDUserProfile as l, type FFIDUpdateUserProfileRequest as m, type FFIDCreateCheckoutParams as n, type FFIDCheckoutSessionResponse as o, type FFIDCreatePortalParams as p, type FFIDPortalSessionResponse as q, type FFIDVerifyAccessTokenOptions as r, type FFIDOAuthUserInfo as s, type FFIDInquiryCreateParams as t, type FFIDInquiryCreateResponse as u, type FFIDAuthMode as v, type FFIDLogger as w, type FFIDCacheAdapter as x, type FFIDUser as y, type FFIDOrganization as z };
1389
+ export { type FFIDInquiryFormProps as $, type FFIDSubscription as A, type FFIDSubscriptionContextValue as B, type FFIDAnnouncementsClientConfig as C, type FFIDAnnouncementsApiResponse as D, type EffectiveSubscriptionStatus as E, type FFIDSubscriptionStatus as F, type AnnouncementListResponse as G, type FFIDAnnouncementsLogger as H, type Announcement as I, type AnnouncementStatus as J, type AnnouncementType as K, type ListAnnouncementsOptions as L, FFIDAnnouncementBadge as M, FFIDAnnouncementList as N, type FFIDAnnouncementsError as O, type FFIDAnnouncementsErrorCode as P, type FFIDAnnouncementsServerResponse as Q, type FFIDCacheConfig as R, type FFIDContextValue as S, type FFIDInquiryCategory as T, type FFIDInquiryCategorySite2026 as U, FFIDInquiryForm as V, type FFIDInquiryFormCategoryItem as W, type FFIDInquiryFormClassNames as X, type FFIDInquiryFormOrganization as Y, type FFIDInquiryFormPlaceholderContext as Z, type FFIDInquiryFormPrefill as _, type FFIDConfig as a, type FFIDInquiryFormSubmitData as a0, type FFIDInquiryFormSubmitResult as a1, type FFIDJwtClaims as a2, FFIDLoginButton as a3, type FFIDMemberStatus as a4, type FFIDOAuthTokenResponse as a5, type FFIDOAuthUserInfoMemberRole as a6, type FFIDOAuthUserInfoSubscription as a7, type FFIDOrganizationMember as a8, FFIDOrganizationSwitcher as a9, type FFIDRedirectErrorCode as aa, type FFIDSeatModel as ab, FFIDSubscriptionBadge as ac, type FFIDTokenIntrospectionResponse as ad, FFIDUserMenu as ae, FFID_INQUIRY_CATEGORIES as af, FFID_INQUIRY_CATEGORIES_SITE_2026 as ag, type UseFFIDAnnouncementsOptions as ah, type UseFFIDAnnouncementsReturn as ai, isFFIDInquiryCategorySite2026 as aj, useFFIDAnnouncements as ak, type FFIDAnnouncementBadgeClassNames as al, type FFIDAnnouncementBadgeProps as am, type FFIDAnnouncementListClassNames as an, type FFIDAnnouncementListProps as ao, type FFIDLoginButtonProps as ap, type FFIDOrganizationSwitcherClassNames as aq, type FFIDOrganizationSwitcherProps as ar, type FFIDSubscriptionBadgeClassNames as as, type FFIDSubscriptionBadgeProps as at, type FFIDUserMenuClassNames as au, type FFIDUserMenuProps as av, type FFIDApiResponse as b, type FFIDSessionResponse as c, type FFIDRedirectResult as d, type FFIDError as e, type FFIDSubscriptionCheckResponse as f, type FFIDListMembersResponse as g, type FFIDMemberRole as h, type FFIDUpdateMemberRoleResponse as i, type FFIDRemoveMemberResponse as j, type FFIDProfileCallOptions as k, type FFIDUserProfile as l, type FFIDUpdateUserProfileRequest as m, type FFIDCreateCheckoutParams as n, type FFIDCheckoutSessionResponse as o, type FFIDCreatePortalParams as p, type FFIDPortalSessionResponse as q, type FFIDVerifyAccessTokenOptions as r, type FFIDOAuthUserInfo as s, type FFIDInquiryCreateParams as t, type FFIDInquiryCreateResponse as u, type FFIDAuthMode as v, type FFIDLogger as w, type FFIDCacheAdapter as x, type FFIDUser as y, type FFIDOrganization as z };
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkEK2W67BW_cjs = require('./chunk-EK2W67BW.cjs');
3
+ var chunkBBXUZS4U_cjs = require('./chunk-BBXUZS4U.cjs');
4
4
  var react = require('react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
 
@@ -44,9 +44,38 @@ function createKVCacheAdapter(kv) {
44
44
  }
45
45
  };
46
46
  }
47
+ function resolveRedirectUrl(redirectTo, status) {
48
+ return typeof redirectTo === "function" ? redirectTo(status) : redirectTo;
49
+ }
50
+ function defaultRedirect(url) {
51
+ if (typeof window === "undefined") return;
52
+ window.location.href = url;
53
+ }
54
+ function useRequireActiveSubscription(options) {
55
+ const { redirectTo, allowGrace = true, onRedirect } = options;
56
+ const { isLoading, error } = chunkBBXUZS4U_cjs.useFFIDContext();
57
+ const { effectiveStatus, isBlocked, isGrace } = chunkBBXUZS4U_cjs.useSubscription();
58
+ const hasFetchError = error !== null && effectiveStatus === null;
59
+ const shouldRedirect = !isLoading && !hasFetchError && (isBlocked || !allowGrace && isGrace || effectiveStatus === null);
60
+ react.useEffect(() => {
61
+ if (!shouldRedirect) return;
62
+ const triggeringStatus = effectiveStatus ?? "blocked";
63
+ const url = resolveRedirectUrl(redirectTo, triggeringStatus);
64
+ if (onRedirect) {
65
+ onRedirect(url);
66
+ } else {
67
+ defaultRedirect(url);
68
+ }
69
+ }, [shouldRedirect, effectiveStatus]);
70
+ return {
71
+ loading: isLoading,
72
+ effectiveStatus,
73
+ error
74
+ };
75
+ }
47
76
  function withFFIDAuth(Component, options = {}) {
48
77
  const WrappedComponent = (props) => {
49
- const { isLoading, isAuthenticated, login } = chunkEK2W67BW_cjs.useFFIDContext();
78
+ const { isLoading, isAuthenticated, login } = chunkBBXUZS4U_cjs.useFFIDContext();
50
79
  const hasRedirected = react.useRef(false);
51
80
  react.useEffect(() => {
52
81
  if (!isLoading && !isAuthenticated && options.redirectToLogin && !hasRedirected.current) {
@@ -74,109 +103,114 @@ var FFID_NEWSLETTER_TYPES = ["inquiry_followup", "general"];
74
103
 
75
104
  Object.defineProperty(exports, "DEFAULT_API_BASE_URL", {
76
105
  enumerable: true,
77
- get: function () { return chunkEK2W67BW_cjs.DEFAULT_API_BASE_URL; }
106
+ get: function () { return chunkBBXUZS4U_cjs.DEFAULT_API_BASE_URL; }
78
107
  });
79
108
  Object.defineProperty(exports, "FFIDAnnouncementBadge", {
80
109
  enumerable: true,
81
- get: function () { return chunkEK2W67BW_cjs.FFIDAnnouncementBadge; }
110
+ get: function () { return chunkBBXUZS4U_cjs.FFIDAnnouncementBadge; }
82
111
  });
83
112
  Object.defineProperty(exports, "FFIDAnnouncementList", {
84
113
  enumerable: true,
85
- get: function () { return chunkEK2W67BW_cjs.FFIDAnnouncementList; }
114
+ get: function () { return chunkBBXUZS4U_cjs.FFIDAnnouncementList; }
86
115
  });
87
116
  Object.defineProperty(exports, "FFIDInquiryForm", {
88
117
  enumerable: true,
89
- get: function () { return chunkEK2W67BW_cjs.FFIDInquiryForm; }
118
+ get: function () { return chunkBBXUZS4U_cjs.FFIDInquiryForm; }
90
119
  });
91
120
  Object.defineProperty(exports, "FFIDLoginButton", {
92
121
  enumerable: true,
93
- get: function () { return chunkEK2W67BW_cjs.FFIDLoginButton; }
122
+ get: function () { return chunkBBXUZS4U_cjs.FFIDLoginButton; }
94
123
  });
95
124
  Object.defineProperty(exports, "FFIDOrganizationSwitcher", {
96
125
  enumerable: true,
97
- get: function () { return chunkEK2W67BW_cjs.FFIDOrganizationSwitcher; }
126
+ get: function () { return chunkBBXUZS4U_cjs.FFIDOrganizationSwitcher; }
98
127
  });
99
128
  Object.defineProperty(exports, "FFIDProvider", {
100
129
  enumerable: true,
101
- get: function () { return chunkEK2W67BW_cjs.FFIDProvider; }
130
+ get: function () { return chunkBBXUZS4U_cjs.FFIDProvider; }
102
131
  });
103
132
  Object.defineProperty(exports, "FFIDSDKError", {
104
133
  enumerable: true,
105
- get: function () { return chunkEK2W67BW_cjs.FFIDSDKError; }
134
+ get: function () { return chunkBBXUZS4U_cjs.FFIDSDKError; }
106
135
  });
107
136
  Object.defineProperty(exports, "FFIDSubscriptionBadge", {
108
137
  enumerable: true,
109
- get: function () { return chunkEK2W67BW_cjs.FFIDSubscriptionBadge; }
138
+ get: function () { return chunkBBXUZS4U_cjs.FFIDSubscriptionBadge; }
110
139
  });
111
140
  Object.defineProperty(exports, "FFIDUserMenu", {
112
141
  enumerable: true,
113
- get: function () { return chunkEK2W67BW_cjs.FFIDUserMenu; }
142
+ get: function () { return chunkBBXUZS4U_cjs.FFIDUserMenu; }
114
143
  });
115
144
  Object.defineProperty(exports, "FFID_ANNOUNCEMENTS_ERROR_CODES", {
116
145
  enumerable: true,
117
- get: function () { return chunkEK2W67BW_cjs.FFID_ANNOUNCEMENTS_ERROR_CODES; }
146
+ get: function () { return chunkBBXUZS4U_cjs.FFID_ANNOUNCEMENTS_ERROR_CODES; }
118
147
  });
119
148
  Object.defineProperty(exports, "FFID_INQUIRY_CATEGORIES", {
120
149
  enumerable: true,
121
- get: function () { return chunkEK2W67BW_cjs.FFID_INQUIRY_CATEGORIES; }
150
+ get: function () { return chunkBBXUZS4U_cjs.FFID_INQUIRY_CATEGORIES; }
122
151
  });
123
152
  Object.defineProperty(exports, "FFID_INQUIRY_CATEGORIES_SITE_2026", {
124
153
  enumerable: true,
125
- get: function () { return chunkEK2W67BW_cjs.FFID_INQUIRY_CATEGORIES_SITE_2026; }
154
+ get: function () { return chunkBBXUZS4U_cjs.FFID_INQUIRY_CATEGORIES_SITE_2026; }
155
+ });
156
+ Object.defineProperty(exports, "computeEffectiveStatusFromSession", {
157
+ enumerable: true,
158
+ get: function () { return chunkBBXUZS4U_cjs.computeEffectiveStatusFromSession; }
126
159
  });
127
160
  Object.defineProperty(exports, "createFFIDAnnouncementsClient", {
128
161
  enumerable: true,
129
- get: function () { return chunkEK2W67BW_cjs.createFFIDAnnouncementsClient; }
162
+ get: function () { return chunkBBXUZS4U_cjs.createFFIDAnnouncementsClient; }
130
163
  });
131
164
  Object.defineProperty(exports, "createFFIDClient", {
132
165
  enumerable: true,
133
- get: function () { return chunkEK2W67BW_cjs.createFFIDClient; }
166
+ get: function () { return chunkBBXUZS4U_cjs.createFFIDClient; }
134
167
  });
135
168
  Object.defineProperty(exports, "createTokenStore", {
136
169
  enumerable: true,
137
- get: function () { return chunkEK2W67BW_cjs.createTokenStore; }
170
+ get: function () { return chunkBBXUZS4U_cjs.createTokenStore; }
138
171
  });
139
172
  Object.defineProperty(exports, "generateCodeChallenge", {
140
173
  enumerable: true,
141
- get: function () { return chunkEK2W67BW_cjs.generateCodeChallenge; }
174
+ get: function () { return chunkBBXUZS4U_cjs.generateCodeChallenge; }
142
175
  });
143
176
  Object.defineProperty(exports, "generateCodeVerifier", {
144
177
  enumerable: true,
145
- get: function () { return chunkEK2W67BW_cjs.generateCodeVerifier; }
178
+ get: function () { return chunkBBXUZS4U_cjs.generateCodeVerifier; }
146
179
  });
147
180
  Object.defineProperty(exports, "isFFIDInquiryCategorySite2026", {
148
181
  enumerable: true,
149
- get: function () { return chunkEK2W67BW_cjs.isFFIDInquiryCategorySite2026; }
182
+ get: function () { return chunkBBXUZS4U_cjs.isFFIDInquiryCategorySite2026; }
150
183
  });
151
184
  Object.defineProperty(exports, "normalizeRedirectUri", {
152
185
  enumerable: true,
153
- get: function () { return chunkEK2W67BW_cjs.normalizeRedirectUri; }
186
+ get: function () { return chunkBBXUZS4U_cjs.normalizeRedirectUri; }
154
187
  });
155
188
  Object.defineProperty(exports, "retrieveCodeVerifier", {
156
189
  enumerable: true,
157
- get: function () { return chunkEK2W67BW_cjs.retrieveCodeVerifier; }
190
+ get: function () { return chunkBBXUZS4U_cjs.retrieveCodeVerifier; }
158
191
  });
159
192
  Object.defineProperty(exports, "storeCodeVerifier", {
160
193
  enumerable: true,
161
- get: function () { return chunkEK2W67BW_cjs.storeCodeVerifier; }
194
+ get: function () { return chunkBBXUZS4U_cjs.storeCodeVerifier; }
162
195
  });
163
196
  Object.defineProperty(exports, "useFFID", {
164
197
  enumerable: true,
165
- get: function () { return chunkEK2W67BW_cjs.useFFID; }
198
+ get: function () { return chunkBBXUZS4U_cjs.useFFID; }
166
199
  });
167
200
  Object.defineProperty(exports, "useFFIDAnnouncements", {
168
201
  enumerable: true,
169
- get: function () { return chunkEK2W67BW_cjs.useFFIDAnnouncements; }
202
+ get: function () { return chunkBBXUZS4U_cjs.useFFIDAnnouncements; }
170
203
  });
171
204
  Object.defineProperty(exports, "useSubscription", {
172
205
  enumerable: true,
173
- get: function () { return chunkEK2W67BW_cjs.useSubscription; }
206
+ get: function () { return chunkBBXUZS4U_cjs.useSubscription; }
174
207
  });
175
208
  Object.defineProperty(exports, "withSubscription", {
176
209
  enumerable: true,
177
- get: function () { return chunkEK2W67BW_cjs.withSubscription; }
210
+ get: function () { return chunkBBXUZS4U_cjs.withSubscription; }
178
211
  });
179
212
  exports.FFID_NEWSLETTER_TYPES = FFID_NEWSLETTER_TYPES;
180
213
  exports.createKVCacheAdapter = createKVCacheAdapter;
181
214
  exports.createMemoryCacheAdapter = createMemoryCacheAdapter;
215
+ exports.useRequireActiveSubscription = useRequireActiveSubscription;
182
216
  exports.withFFIDAuth = withFFIDAuth;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FFIDSubscriptionStatus, a as FFIDConfig, b as FFIDApiResponse, c as FFIDSessionResponse, d as FFIDRedirectResult, e as FFIDError, f as FFIDSubscriptionCheckResponse, g as FFIDListMembersResponse, h as FFIDMemberRole, i as FFIDUpdateMemberRoleResponse, j as FFIDRemoveMemberResponse, k as FFIDProfileCallOptions, l as FFIDUserProfile, m as FFIDUpdateUserProfileRequest, n as FFIDCreateCheckoutParams, o as FFIDCheckoutSessionResponse, p as FFIDCreatePortalParams, q as FFIDPortalSessionResponse, r as FFIDVerifyAccessTokenOptions, s as FFIDOAuthUserInfo, t as FFIDInquiryCreateParams, u as FFIDInquiryCreateResponse, v as FFIDAuthMode, w as FFIDLogger, x as FFIDCacheAdapter, y as FFIDUser, z as FFIDOrganization, A as FFIDSubscription, B as FFIDSubscriptionContextValue, C as FFIDAnnouncementsClientConfig, L as ListAnnouncementsOptions, D as FFIDAnnouncementsApiResponse, E as AnnouncementListResponse, G as FFIDAnnouncementsLogger } from './index--S6rLHjr.cjs';
2
- export { H as Announcement, I as AnnouncementStatus, J as AnnouncementType, K as FFIDAnnouncementBadge, M as FFIDAnnouncementList, N as FFIDAnnouncementsError, O as FFIDAnnouncementsErrorCode, P as FFIDAnnouncementsServerResponse, Q as FFIDCacheConfig, R as FFIDContextValue, S as FFIDInquiryCategory, T as FFIDInquiryCategorySite2026, U as FFIDInquiryForm, V as FFIDInquiryFormCategoryItem, W as FFIDInquiryFormClassNames, X as FFIDInquiryFormOrganization, Y as FFIDInquiryFormPlaceholderContext, Z as FFIDInquiryFormPrefill, _ as FFIDInquiryFormProps, $ as FFIDInquiryFormSubmitData, a0 as FFIDInquiryFormSubmitResult, a1 as FFIDJwtClaims, a2 as FFIDLoginButton, a3 as FFIDMemberStatus, a4 as FFIDOAuthTokenResponse, a5 as FFIDOAuthUserInfoMemberRole, a6 as FFIDOAuthUserInfoSubscription, a7 as FFIDOrganizationMember, a8 as FFIDOrganizationSwitcher, a9 as FFIDRedirectErrorCode, aa as FFIDSeatModel, ab as FFIDSubscriptionBadge, ac as FFIDTokenIntrospectionResponse, ad as FFIDUserMenu, ae as FFID_INQUIRY_CATEGORIES, af as FFID_INQUIRY_CATEGORIES_SITE_2026, ag as UseFFIDAnnouncementsOptions, ah as UseFFIDAnnouncementsReturn, ai as isFFIDInquiryCategorySite2026, aj as useFFIDAnnouncements } from './index--S6rLHjr.cjs';
1
+ import { F as FFIDSubscriptionStatus, a as FFIDConfig, b as FFIDApiResponse, c as FFIDSessionResponse, d as FFIDRedirectResult, e as FFIDError, f as FFIDSubscriptionCheckResponse, g as FFIDListMembersResponse, h as FFIDMemberRole, i as FFIDUpdateMemberRoleResponse, j as FFIDRemoveMemberResponse, k as FFIDProfileCallOptions, l as FFIDUserProfile, m as FFIDUpdateUserProfileRequest, n as FFIDCreateCheckoutParams, o as FFIDCheckoutSessionResponse, p as FFIDCreatePortalParams, q as FFIDPortalSessionResponse, r as FFIDVerifyAccessTokenOptions, s as FFIDOAuthUserInfo, t as FFIDInquiryCreateParams, u as FFIDInquiryCreateResponse, v as FFIDAuthMode, w as FFIDLogger, x as FFIDCacheAdapter, y as FFIDUser, z as FFIDOrganization, A as FFIDSubscription, B as FFIDSubscriptionContextValue, E as EffectiveSubscriptionStatus, C as FFIDAnnouncementsClientConfig, L as ListAnnouncementsOptions, D as FFIDAnnouncementsApiResponse, G as AnnouncementListResponse, H as FFIDAnnouncementsLogger } from './index-0D2vYSLq.cjs';
2
+ export { I as Announcement, J as AnnouncementStatus, K as AnnouncementType, M as FFIDAnnouncementBadge, N as FFIDAnnouncementList, O as FFIDAnnouncementsError, P as FFIDAnnouncementsErrorCode, Q as FFIDAnnouncementsServerResponse, R as FFIDCacheConfig, S as FFIDContextValue, T as FFIDInquiryCategory, U as FFIDInquiryCategorySite2026, V as FFIDInquiryForm, W as FFIDInquiryFormCategoryItem, X as FFIDInquiryFormClassNames, Y as FFIDInquiryFormOrganization, Z as FFIDInquiryFormPlaceholderContext, _ as FFIDInquiryFormPrefill, $ as FFIDInquiryFormProps, a0 as FFIDInquiryFormSubmitData, a1 as FFIDInquiryFormSubmitResult, a2 as FFIDJwtClaims, a3 as FFIDLoginButton, a4 as FFIDMemberStatus, a5 as FFIDOAuthTokenResponse, a6 as FFIDOAuthUserInfoMemberRole, a7 as FFIDOAuthUserInfoSubscription, a8 as FFIDOrganizationMember, a9 as FFIDOrganizationSwitcher, aa as FFIDRedirectErrorCode, ab as FFIDSeatModel, ac as FFIDSubscriptionBadge, ad as FFIDTokenIntrospectionResponse, ae as FFIDUserMenu, af as FFID_INQUIRY_CATEGORIES, ag as FFID_INQUIRY_CATEGORIES_SITE_2026, ah as UseFFIDAnnouncementsOptions, ai as UseFFIDAnnouncementsReturn, aj as isFFIDInquiryCategorySite2026, ak as useFFIDAnnouncements } from './index-0D2vYSLq.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode, ComponentType, FC } from 'react';
5
5
 
@@ -698,36 +698,47 @@ declare function useFFID(): UseFFIDReturn;
698
698
  /**
699
699
  * useSubscription Hook
700
700
  *
701
- * Access subscription/contract information for the current service
701
+ * Access subscription/contract information for the current service.
702
+ *
703
+ * Post Chain-of-Pacts (Issue #2444) the hook exposes a semantic
704
+ * `effectiveStatus` alongside the raw booleans so callers can branch on a
705
+ * single access-control value instead of re-deriving `past_due_grace` vs.
706
+ * `blocked` in every component. See
707
+ * `docs/03-implementation/EXPIRED_CONTRACT_HANDLING.md` for the full recipe.
702
708
  *
703
709
  * @example
704
710
  * ```tsx
705
711
  * import { useSubscription } from '@feelflow/ffid-sdk'
706
712
  *
707
713
  * function PremiumFeature() {
708
- * const { isActive, hasPlan, planCode } = useSubscription()
714
+ * const { effectiveStatus, hasAccess, isGrace, hasPlan } = useSubscription()
709
715
  *
710
- * if (!isActive) {
711
- * return <div>契約が必要です</div>
716
+ * if (!hasAccess()) {
717
+ * return <div>契約が必要です(状態: {effectiveStatus})</div>
712
718
  * }
713
719
  *
714
720
  * if (!hasPlan(['pro', 'enterprise'])) {
715
721
  * return <div>プロプラン以上が必要です</div>
716
722
  * }
717
723
  *
718
- * return <div>Premium Content</div>
724
+ * return (
725
+ * <>
726
+ * {isGrace && <PaymentFailedBanner />}
727
+ * <PremiumContent />
728
+ * </>
729
+ * )
719
730
  * }
720
731
  * ```
721
732
  */
722
733
 
723
734
  /**
724
- * Hook to access subscription information
735
+ * Hook to access subscription information.
725
736
  *
726
- * Must be used within FFIDProvider
737
+ * Must be used within `FFIDProvider`.
727
738
  */
728
739
  declare function useSubscription(): FFIDSubscriptionContextValue;
729
740
  /**
730
- * HOC to require subscription for a component
741
+ * HOC to require subscription for a component.
731
742
  *
732
743
  * @example
733
744
  * ```tsx
@@ -749,6 +760,89 @@ interface WithSubscriptionOptions {
749
760
  }
750
761
  declare function withSubscription<P extends object>(Component: ComponentType<P>, options?: WithSubscriptionOptions): FC<P>;
751
762
 
763
+ /**
764
+ * Options accepted by {@link useRequireActiveSubscription}.
765
+ */
766
+ interface UseRequireActiveSubscriptionOptions {
767
+ /**
768
+ * Destination to redirect to when the subscription is blocked.
769
+ *
770
+ * - `string` — used verbatim.
771
+ * - `(status) => string` — invoked with the triggering
772
+ * {@link EffectiveSubscriptionStatus} so callers can route
773
+ * `canceled` to a different landing page than `blocked`, etc.
774
+ */
775
+ redirectTo: string | ((status: EffectiveSubscriptionStatus) => string);
776
+ /**
777
+ * Whether to treat `past_due_grace` as "still allowed".
778
+ * Defaults to `true` — matches the canonical FFID behaviour of showing
779
+ * a warning banner while Stripe retries the invoice. Flip to `false` to
780
+ * treat any non-`active` state as a hard block.
781
+ */
782
+ allowGrace?: boolean;
783
+ /**
784
+ * Side effect that performs the actual navigation. Receives the resolved
785
+ * URL (after running `redirectTo` against the effective status) and is
786
+ * only ever called in the browser. When omitted the hook falls back to
787
+ * `window.location.href = url` — convenient for pages that do not use a
788
+ * router.
789
+ */
790
+ onRedirect?: (url: string) => void;
791
+ }
792
+ /**
793
+ * Return value of {@link useRequireActiveSubscription}.
794
+ */
795
+ interface UseRequireActiveSubscriptionReturn {
796
+ /**
797
+ * `true` while the FFID session is still being fetched. Consumers should
798
+ * render a loading state until this turns `false` to avoid rendering
799
+ * protected UI behind the upcoming redirect.
800
+ */
801
+ loading: boolean;
802
+ /**
803
+ * The effective subscription status that drove the guard decision.
804
+ * `null` when there is no subscription for the current service (the hook
805
+ * will then trigger a redirect on the first non-loading render).
806
+ */
807
+ effectiveStatus: EffectiveSubscriptionStatus | null;
808
+ /**
809
+ * Surfaces the FFID context error (session fetch failure, token exchange
810
+ * error, etc.) so callers can render a retry surface instead of redirecting
811
+ * through the "contract required" flow. When `error` is non-null **and**
812
+ * `effectiveStatus === null`, the hook intentionally skips the redirect
813
+ * side effect — the subscription-less state is indistinguishable from a
814
+ * transient fetch failure, so routing the user to a hard paywall would
815
+ * punish an intermittent network blip. Callers that want to force a
816
+ * redirect anyway can invoke `onRedirect` manually after inspecting
817
+ * `error`.
818
+ */
819
+ error: FFIDError | null;
820
+ }
821
+ /**
822
+ * Guard a React tree against expired / blocked / cancelled subscriptions.
823
+ *
824
+ * The hook does nothing while the FFID provider is still loading, then —
825
+ * on the next render — evaluates `effectiveStatus` and fires the configured
826
+ * redirect when the subscription is in a blocking state. Returning
827
+ * `{ loading, effectiveStatus, error }` lets the caller render a skeleton /
828
+ * null placeholder during the transition rather than flashing protected
829
+ * content, and surface a retry affordance when the FFID fetch itself failed.
830
+ *
831
+ * **Error surface (S-H3)**: when the FFID context is in an error state AND
832
+ * there is no subscription (`effectiveStatus === null`), the hook
833
+ * intentionally **does not redirect**. A network blip should not send the
834
+ * user to the "contract required" page — the consumer is expected to
835
+ * inspect `error` and render a retry UI, or call `onRedirect` manually if
836
+ * a forced redirect is still appropriate.
837
+ *
838
+ * The redirect effect runs at most once per resolved status (tracked via
839
+ * React's dependency array) so consumers do not need to memoise
840
+ * `redirectTo` / `onRedirect` for correctness. Subsequent status changes
841
+ * (e.g. the user reactivates their contract in another tab and the session
842
+ * refreshes to `active`) naturally cancel the pending redirect.
843
+ */
844
+ declare function useRequireActiveSubscription(options: UseRequireActiveSubscriptionOptions): UseRequireActiveSubscriptionReturn;
845
+
752
846
  /**
753
847
  * withFFIDAuth HOC
754
848
  *
@@ -811,6 +905,82 @@ interface WithFFIDAuthOptions {
811
905
  */
812
906
  declare function withFFIDAuth<P extends object>(Component: ComponentType<P>, options?: WithFFIDAuthOptions): FC<P>;
813
907
 
908
+ /**
909
+ * Local fallback for `EffectiveSubscriptionStatus`.
910
+ *
911
+ * The canonical value is produced by the FFID backend on
912
+ * `/api/v1/subscriptions/ext/check`. This helper exists to cover cases where
913
+ * the SDK only has the fields carried by the OAuth session response
914
+ * (`status`, `currentPeriodEnd`, `trialEnd`) — for example in `useSubscription`
915
+ * which reads from the React context, not from `/ext/check`.
916
+ *
917
+ * The mapping intentionally mirrors `getEffectiveSubscriptionStatus` /
918
+ * `EffectiveSubscriptionStatus` in `src/lib/common/subscription-helpers.ts`.
919
+ * When the server ships the authoritative `effectiveStatus`, callers should
920
+ * prefer it over this local approximation.
921
+ *
922
+ * Limitations (documented so callers can reason about accuracy):
923
+ *
924
+ * - **`past_due` is resolved via a 7-day grace window** anchored on
925
+ * `pastDueSince` (when supplied) or `currentPeriodEnd` (best-effort
926
+ * fallback — Stripe flips `past_due` at/around period end). Within the
927
+ * window the status is `past_due_grace`; past the window it flips to
928
+ * `blocked`. When both timestamps are missing (or unparseable) the
929
+ * function fails closed to `blocked`. The grace window length is
930
+ * duplicated from the FFID backend constant of the same name — see
931
+ * {@link PAST_DUE_GRACE_PERIOD_DAYS} for the sync invariant.
932
+ * - **`paused` / `incomplete` are mapped to `active` (fail-open).** Matches
933
+ * the FFID backend `computeEffectiveStatus` (`src/lib/common/subscription-
934
+ * helpers.ts`) which keeps access live for these transient intents — the
935
+ * server has richer context (Stripe webhook order, seat assignment state)
936
+ * so it fails open, and the SDK aligns to avoid the consumer seeing a
937
+ * different verdict than `/ext/check`.
938
+ * - **`pending_invoice` is mapped to `active`.** This is a transient state
939
+ * between invoice finalisation and payment, and FFID keeps access live for
940
+ * the organisation during that window.
941
+ */
942
+
943
+ /**
944
+ * Inputs required to approximate `EffectiveSubscriptionStatus` from session
945
+ * data alone. Kept as a small record so unit tests do not need to build full
946
+ * `FFIDSubscription` objects.
947
+ */
948
+ interface ComputeEffectiveStatusInput {
949
+ /** Raw DB status as reported by FFID. */
950
+ status: FFIDSubscriptionStatus;
951
+ /** ISO 8601 timestamp of the current billing period end, or `null` for seatless / free plans. */
952
+ currentPeriodEnd: string | null;
953
+ /** ISO 8601 timestamp of the trial end, or `null` if not on a trial. */
954
+ trialEnd: string | null;
955
+ /**
956
+ * ISO 8601 timestamp of when the subscription first entered `past_due`.
957
+ *
958
+ * Carried alongside the session response when available (currently not
959
+ * emitted — see TODO in `useSubscription` that tracks the session API
960
+ * extension). When absent, the compute helper falls back to
961
+ * `currentPeriodEnd` as a best-effort proxy (Stripe flips `past_due` at /
962
+ * near period end, so the proxy is within ~1 dunning retry cycle). When
963
+ * both timestamps are missing or unparseable the helper fails closed to
964
+ * `blocked`.
965
+ */
966
+ pastDueSince?: string | null | undefined;
967
+ }
968
+ /**
969
+ * Compute an `EffectiveSubscriptionStatus` from the fields available in the
970
+ * session response. Designed as a pure function so it can be reused by
971
+ * `useSubscription` and by any caller that needs a best-effort access-control
972
+ * decision without waiting for an `/ext/check` round-trip.
973
+ *
974
+ * Callers SHOULD prefer the `effectiveStatus` returned by the FFID server
975
+ * (`/api/v1/subscriptions/ext/check`) when available — it has access to grace
976
+ * window information (`graceUntil`) that the SDK cannot see.
977
+ *
978
+ * @param input - Session-level subscription fields.
979
+ * @param nowMs - Override for "now", injected for deterministic tests.
980
+ * Defaults to `Date.now()`.
981
+ */
982
+ declare function computeEffectiveStatusFromSession(input: ComputeEffectiveStatusInput, nowMs?: number): EffectiveSubscriptionStatus;
983
+
814
984
  /**
815
985
  * FFID Announcements API Client
816
986
  *
@@ -937,4 +1107,4 @@ declare function createInquiryMethods(deps: InquiryMethodsDeps): {
937
1107
  };
938
1108
  type FFIDInquiryClient = ReturnType<typeof createInquiryMethods>;
939
1109
 
940
- export { AnnouncementListResponse, type ContractWizardFlowType, type ContractWizardResubscribeOptions, type ContractWizardSubscribeOptions, type ContractWizardSubscriptionOptions, DEFAULT_API_BASE_URL, FFIDAnnouncementsApiResponse, type FFIDAnnouncementsClient, FFIDAnnouncementsClientConfig, FFIDAnnouncementsLogger, FFIDApiResponse, type FFIDBillingInterval, FFIDCacheAdapter, type FFIDCancelPendingDowngradeResponse, type FFIDCancelSubscriptionParams, type FFIDCancelSubscriptionResponse, type FFIDChangePlanParams, type FFIDChangePlanResponse, FFIDCheckoutSessionResponse, type FFIDClient, FFIDConfig, FFIDCreateCheckoutParams, FFIDCreatePortalParams, FFIDError, type FFIDInquiryClient, FFIDInquiryCreateParams, FFIDInquiryCreateResponse, FFIDListMembersResponse, type FFIDListPlansResponse, FFIDLogger, FFIDMemberRole, type FFIDNewsletterClient, type FFIDNewsletterConfirmParams, type FFIDNewsletterConfirmResponse, type FFIDNewsletterSubscribeParams, type FFIDNewsletterSubscribeResponse, type FFIDNewsletterType, type FFIDNewsletterUnsubscribeParams, type FFIDNewsletterUnsubscribeResponse, FFIDOAuthUserInfo, FFIDOrganization, type FFIDOtpSendResponse, type FFIDOtpVerifyResponse, type FFIDPasswordResetConfirmResponse, type FFIDPasswordResetResponse, type FFIDPasswordResetVerifyResponse, type FFIDPlanChangeLineItem, type FFIDPlanChangePreview, type FFIDPlanChangePreviewResponse, type FFIDPlanInfo, FFIDPortalSessionResponse, type FFIDPreviewPlanChangeParams, type FFIDPreviewSeatChangeParams, FFIDProfileCallOptions, FFIDProvider, type FFIDProviderProps, FFIDRedirectResult, FFIDRemoveMemberResponse, type FFIDResetSessionResponse, FFIDSDKError, type FFIDSeatChangeLineItem, type FFIDSeatChangePreview, type FFIDSeatChangePreviewResponse, type FFIDServiceInfo, FFIDSessionResponse, type FFIDSubscribeParams, type FFIDSubscribeResponse, FFIDSubscription, FFIDSubscriptionCheckResponse, FFIDSubscriptionContextValue, type FFIDSubscriptionDetail, FFIDSubscriptionStatus, type FFIDSubscriptionSummary, type FFIDSupportedCurrency, FFIDUpdateMemberRoleResponse, FFIDUpdateUserProfileRequest, FFIDUser, FFIDUserProfile, FFIDVerifyAccessTokenOptions, FFID_ANNOUNCEMENTS_ERROR_CODES, FFID_NEWSLETTER_TYPES, type KVNamespaceLike, ListAnnouncementsOptions, type NormalizeRedirectUriResult, type RedirectToAuthorizeOptions, type TokenData, type TokenStore, type UseFFIDReturn, type WithFFIDAuthOptions, type WithSubscriptionOptions, createFFIDAnnouncementsClient, createFFIDClient, createKVCacheAdapter, createMemoryCacheAdapter, createTokenStore, generateCodeChallenge, generateCodeVerifier, normalizeRedirectUri, retrieveCodeVerifier, storeCodeVerifier, useFFID, useSubscription, withFFIDAuth, withSubscription };
1110
+ export { AnnouncementListResponse, type ComputeEffectiveStatusInput, type ContractWizardFlowType, type ContractWizardResubscribeOptions, type ContractWizardSubscribeOptions, type ContractWizardSubscriptionOptions, DEFAULT_API_BASE_URL, EffectiveSubscriptionStatus, FFIDAnnouncementsApiResponse, type FFIDAnnouncementsClient, FFIDAnnouncementsClientConfig, FFIDAnnouncementsLogger, FFIDApiResponse, type FFIDBillingInterval, FFIDCacheAdapter, type FFIDCancelPendingDowngradeResponse, type FFIDCancelSubscriptionParams, type FFIDCancelSubscriptionResponse, type FFIDChangePlanParams, type FFIDChangePlanResponse, FFIDCheckoutSessionResponse, type FFIDClient, FFIDConfig, FFIDCreateCheckoutParams, FFIDCreatePortalParams, FFIDError, type FFIDInquiryClient, FFIDInquiryCreateParams, FFIDInquiryCreateResponse, FFIDListMembersResponse, type FFIDListPlansResponse, FFIDLogger, FFIDMemberRole, type FFIDNewsletterClient, type FFIDNewsletterConfirmParams, type FFIDNewsletterConfirmResponse, type FFIDNewsletterSubscribeParams, type FFIDNewsletterSubscribeResponse, type FFIDNewsletterType, type FFIDNewsletterUnsubscribeParams, type FFIDNewsletterUnsubscribeResponse, FFIDOAuthUserInfo, FFIDOrganization, type FFIDOtpSendResponse, type FFIDOtpVerifyResponse, type FFIDPasswordResetConfirmResponse, type FFIDPasswordResetResponse, type FFIDPasswordResetVerifyResponse, type FFIDPlanChangeLineItem, type FFIDPlanChangePreview, type FFIDPlanChangePreviewResponse, type FFIDPlanInfo, FFIDPortalSessionResponse, type FFIDPreviewPlanChangeParams, type FFIDPreviewSeatChangeParams, FFIDProfileCallOptions, FFIDProvider, type FFIDProviderProps, FFIDRedirectResult, FFIDRemoveMemberResponse, type FFIDResetSessionResponse, FFIDSDKError, type FFIDSeatChangeLineItem, type FFIDSeatChangePreview, type FFIDSeatChangePreviewResponse, type FFIDServiceInfo, FFIDSessionResponse, type FFIDSubscribeParams, type FFIDSubscribeResponse, FFIDSubscription, FFIDSubscriptionCheckResponse, FFIDSubscriptionContextValue, type FFIDSubscriptionDetail, FFIDSubscriptionStatus, type FFIDSubscriptionSummary, type FFIDSupportedCurrency, FFIDUpdateMemberRoleResponse, FFIDUpdateUserProfileRequest, FFIDUser, FFIDUserProfile, FFIDVerifyAccessTokenOptions, FFID_ANNOUNCEMENTS_ERROR_CODES, FFID_NEWSLETTER_TYPES, type KVNamespaceLike, ListAnnouncementsOptions, type NormalizeRedirectUriResult, type RedirectToAuthorizeOptions, type TokenData, type TokenStore, type UseFFIDReturn, type UseRequireActiveSubscriptionOptions, type UseRequireActiveSubscriptionReturn, type WithFFIDAuthOptions, type WithSubscriptionOptions, computeEffectiveStatusFromSession, createFFIDAnnouncementsClient, createFFIDClient, createKVCacheAdapter, createMemoryCacheAdapter, createTokenStore, generateCodeChallenge, generateCodeVerifier, normalizeRedirectUri, retrieveCodeVerifier, storeCodeVerifier, useFFID, useRequireActiveSubscription, useSubscription, withFFIDAuth, withSubscription };