@feelflow/ffid-sdk 1.18.0 → 1.19.1

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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FFIDConfig, a as FFIDApiResponse, b as FFIDSessionResponse, c as FFIDRedirectResult, d as FFIDError, e as FFIDSubscriptionCheckResponse, f as FFIDListMembersResponse, g as FFIDMemberRole, h as FFIDUpdateMemberRoleResponse, i as FFIDRemoveMemberResponse, j as FFIDCreateCheckoutParams, k as FFIDCheckoutSessionResponse, l as FFIDCreatePortalParams, m as FFIDPortalSessionResponse, n as FFIDVerifyAccessTokenOptions, o as FFIDOAuthUserInfo, p as FFIDAuthMode, q as FFIDLogger, r as FFIDCacheAdapter, s as FFIDUser, t as FFIDOrganization, u as FFIDSubscription, v as FFIDSubscriptionContextValue, w as FFIDAnnouncementsClientConfig, L as ListAnnouncementsOptions, x as FFIDAnnouncementsApiResponse, A as AnnouncementListResponse, y as FFIDAnnouncementsLogger } from './index-BHh-uxYS.cjs';
2
- export { z as Announcement, B as AnnouncementStatus, C as AnnouncementType, D as FFIDAnnouncementBadge, E as FFIDAnnouncementList, G as FFIDAnnouncementsError, H as FFIDAnnouncementsErrorCode, I as FFIDAnnouncementsServerResponse, J as FFIDCacheConfig, K as FFIDContextValue, M as FFIDJwtClaims, N as FFIDLoginButton, O as FFIDMemberStatus, P as FFIDOAuthTokenResponse, Q as FFIDOAuthUserInfoMemberRole, R as FFIDOAuthUserInfoSubscription, S as FFIDOrganizationMember, T as FFIDOrganizationSwitcher, U as FFIDSeatModel, V as FFIDSubscriptionBadge, W as FFIDSubscriptionStatus, X as FFIDTokenIntrospectionResponse, Y as FFIDUserMenu, Z as UseFFIDAnnouncementsOptions, _ as UseFFIDAnnouncementsReturn, $ as useFFIDAnnouncements } from './index-BHh-uxYS.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 FFIDCreateCheckoutParams, l as FFIDCheckoutSessionResponse, m as FFIDCreatePortalParams, n as FFIDPortalSessionResponse, o as FFIDVerifyAccessTokenOptions, p as FFIDOAuthUserInfo, q as FFIDAuthMode, r as FFIDLogger, s as FFIDCacheAdapter, t as FFIDUser, u as FFIDOrganization, v as FFIDSubscription, w as FFIDSubscriptionContextValue, x as FFIDAnnouncementsClientConfig, L as ListAnnouncementsOptions, y as FFIDAnnouncementsApiResponse, A as AnnouncementListResponse, z as FFIDAnnouncementsLogger } from './index-p4dJw3qR.cjs';
2
+ export { B as Announcement, C as AnnouncementStatus, D as AnnouncementType, E as FFIDAnnouncementBadge, G as FFIDAnnouncementList, H as FFIDAnnouncementsError, I as FFIDAnnouncementsErrorCode, J as FFIDAnnouncementsServerResponse, K as FFIDCacheConfig, M as FFIDContextValue, N as FFIDJwtClaims, O as FFIDLoginButton, P as FFIDMemberStatus, Q as FFIDOAuthTokenResponse, R as FFIDOAuthUserInfoMemberRole, S as FFIDOAuthUserInfoSubscription, T as FFIDOrganizationMember, U as FFIDOrganizationSwitcher, V as FFIDSeatModel, W as FFIDSubscriptionBadge, X as FFIDTokenIntrospectionResponse, Y as FFIDUserMenu, Z as UseFFIDAnnouncementsOptions, _ as UseFFIDAnnouncementsReturn, $ as useFFIDAnnouncements } from './index-p4dJw3qR.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode, ComponentType, FC } from 'react';
5
5
 
@@ -92,6 +92,193 @@ declare function storeCodeVerifier(verifier: string, logger?: PKCELogger): boole
92
92
  */
93
93
  declare function retrieveCodeVerifier(logger?: PKCELogger): string | null;
94
94
 
95
+ /** Billing interval for subscriptions */
96
+ type FFIDBillingInterval = 'monthly' | 'yearly';
97
+ /** Service information returned by plans endpoint */
98
+ interface FFIDServiceInfo {
99
+ id: string;
100
+ code: string;
101
+ name: string;
102
+ description: string | null;
103
+ isActive: boolean;
104
+ createdAt: string;
105
+ plans: FFIDPlanInfo[];
106
+ }
107
+ /** Plan information returned by plans endpoint */
108
+ interface FFIDPlanInfo {
109
+ id: string;
110
+ serviceId: string;
111
+ code: string;
112
+ name: string;
113
+ description: string | null;
114
+ minSeats: number;
115
+ maxSeats: number | null;
116
+ trialDays: number;
117
+ priceMonthly: number;
118
+ priceYearly: number | null;
119
+ currency: string;
120
+ isActive: boolean;
121
+ displayOrder: number;
122
+ customPricing: boolean;
123
+ createdAt: string;
124
+ }
125
+ /** Response from list plans endpoint */
126
+ interface FFIDListPlansResponse {
127
+ services: FFIDServiceInfo[];
128
+ count: number;
129
+ }
130
+ /** Subscription details returned by ext API (sanitized, no Stripe IDs) */
131
+ interface FFIDSubscriptionDetail {
132
+ id: string;
133
+ organizationId: string;
134
+ organizationName: string;
135
+ serviceCode: string;
136
+ serviceName: string;
137
+ planCode: string;
138
+ planName: string;
139
+ status: FFIDSubscriptionStatus;
140
+ paymentMethod: string | null;
141
+ billingInterval: FFIDBillingInterval;
142
+ quantity: number;
143
+ currentPeriodStart: string | null;
144
+ currentPeriodEnd: string | null;
145
+ trialStart: string | null;
146
+ trialEnd: string | null;
147
+ canceledAt: string | null;
148
+ cancelAtPeriodEnd: boolean;
149
+ createdAt: string;
150
+ }
151
+ /** Parameters for subscribing to a plan */
152
+ interface FFIDSubscribeParams {
153
+ /** Organization ID (UUID) */
154
+ organizationId: string;
155
+ /** Plan code (e.g., 'free', 'basic', 'pro') */
156
+ planCode: string;
157
+ /** Billing interval (default: 'monthly') */
158
+ billingInterval?: FFIDBillingInterval;
159
+ /** Number of seats (default: plan's minSeats) */
160
+ quantity?: number;
161
+ /** User ID for seat auto-assignment (only needed for service-key mode) */
162
+ userId?: string;
163
+ }
164
+ /** Sanitized subscription fields returned by subscribe/reactivate endpoints (no Stripe IDs) */
165
+ interface FFIDSubscriptionSummary {
166
+ id: string;
167
+ organizationId: string;
168
+ serviceId: string;
169
+ planId: string;
170
+ status: FFIDSubscriptionStatus;
171
+ paymentMethod: string | null;
172
+ billingInterval: FFIDBillingInterval;
173
+ quantity: number;
174
+ currentPeriodStart: string | null;
175
+ currentPeriodEnd: string | null;
176
+ trialStart: string | null;
177
+ trialEnd: string | null;
178
+ canceledAt: string | null;
179
+ cancelAtPeriodEnd: boolean;
180
+ createdAt: string;
181
+ }
182
+ /** Response from subscribe endpoint */
183
+ interface FFIDSubscribeResponse {
184
+ subscription: FFIDSubscriptionSummary;
185
+ service: {
186
+ id: string;
187
+ code: string;
188
+ name: string;
189
+ };
190
+ plan: {
191
+ id: string;
192
+ code: string;
193
+ name: string;
194
+ priceMonthly: number;
195
+ priceYearly: number | null;
196
+ trialDays: number;
197
+ };
198
+ /** True if a canceled subscription was reactivated */
199
+ reactivated?: boolean;
200
+ /** True if Stripe checkout is needed (canceled paid plan reactivation) */
201
+ needsCheckout?: boolean;
202
+ }
203
+ /** Parameters for changing plan */
204
+ interface FFIDChangePlanParams {
205
+ /** Subscription ID (UUID) */
206
+ subscriptionId: string;
207
+ /** New plan code */
208
+ planCode: string;
209
+ /** New billing interval (default: keeps current) */
210
+ billingInterval?: FFIDBillingInterval;
211
+ }
212
+ /** Response from change plan endpoint */
213
+ interface FFIDChangePlanResponse {
214
+ message: string;
215
+ subscription: {
216
+ id: string;
217
+ organizationId: string;
218
+ serviceCode: string;
219
+ planCode: string;
220
+ planName: string;
221
+ billingInterval: FFIDBillingInterval;
222
+ status: FFIDSubscriptionStatus;
223
+ isUpgrade: boolean;
224
+ };
225
+ }
226
+ /** Parameters for canceling subscription */
227
+ interface FFIDCancelSubscriptionParams {
228
+ /** Subscription ID (UUID) */
229
+ subscriptionId: string;
230
+ /** Cancellation reason code */
231
+ reason?: 'too_expensive' | 'missing_features' | 'switched_service' | 'rarely_used' | 'customer_service' | 'other';
232
+ /** Additional cancellation details */
233
+ reasonDetails?: string;
234
+ }
235
+ /** Response from cancel subscription endpoint */
236
+ interface FFIDCancelSubscriptionResponse {
237
+ message: string;
238
+ subscription: {
239
+ id: string;
240
+ organizationId: string;
241
+ status: FFIDSubscriptionStatus;
242
+ canceledAt: string | null;
243
+ };
244
+ }
245
+ /** Parameters for previewing plan change */
246
+ interface FFIDPreviewPlanChangeParams {
247
+ /** Subscription ID (UUID) */
248
+ subscriptionId: string;
249
+ /** New plan code */
250
+ planCode: string;
251
+ /** New billing interval (default: keeps current) */
252
+ billingInterval?: FFIDBillingInterval;
253
+ }
254
+ /** Plan change preview line item */
255
+ interface FFIDPlanChangeLineItem {
256
+ description: string;
257
+ amount: number;
258
+ }
259
+ /** Response from plan change preview endpoint */
260
+ interface FFIDPlanChangePreviewResponse {
261
+ preview: {
262
+ currentPlan: {
263
+ name: string;
264
+ price: number;
265
+ };
266
+ newPlan: {
267
+ name: string;
268
+ price: number;
269
+ };
270
+ billingInterval: FFIDBillingInterval;
271
+ isUpgrade: boolean;
272
+ proratedAmount: number;
273
+ nextInvoiceAmount: number;
274
+ nextInvoiceDate: string | null;
275
+ currency: string;
276
+ isEstimate: boolean;
277
+ estimateReason?: string;
278
+ lineItems: FFIDPlanChangeLineItem[];
279
+ };
280
+ }
281
+
95
282
  /** OTP / magic link methods - sendOtp / verifyOtp */
96
283
 
97
284
  /** Response from sendOtp */
@@ -151,7 +338,7 @@ declare function createFFIDClient(config: FFIDConfig): {
151
338
  exchangeCodeForTokens: (code: string, codeVerifier?: string) => Promise<FFIDApiResponse<void>>;
152
339
  refreshAccessToken: () => Promise<FFIDApiResponse<void>>;
153
340
  checkSubscription: (params: {
154
- userId: string;
341
+ userId?: string;
155
342
  organizationId: string;
156
343
  }) => Promise<FFIDApiResponse<FFIDSubscriptionCheckResponse>>;
157
344
  listMembers: (params: {
@@ -168,6 +355,12 @@ declare function createFFIDClient(config: FFIDConfig): {
168
355
  }) => Promise<FFIDApiResponse<FFIDRemoveMemberResponse>>;
169
356
  createCheckoutSession: (params: FFIDCreateCheckoutParams) => Promise<FFIDApiResponse<FFIDCheckoutSessionResponse>>;
170
357
  createPortalSession: (params: FFIDCreatePortalParams) => Promise<FFIDApiResponse<FFIDPortalSessionResponse>>;
358
+ listPlans: () => Promise<FFIDApiResponse<FFIDListPlansResponse>>;
359
+ getSubscription: (subscriptionId: string) => Promise<FFIDApiResponse<FFIDSubscriptionDetail>>;
360
+ subscribe: (params: FFIDSubscribeParams) => Promise<FFIDApiResponse<FFIDSubscribeResponse>>;
361
+ changePlan: (params: FFIDChangePlanParams) => Promise<FFIDApiResponse<FFIDChangePlanResponse>>;
362
+ cancelSubscription: (params: FFIDCancelSubscriptionParams) => Promise<FFIDApiResponse<FFIDCancelSubscriptionResponse>>;
363
+ previewPlanChange: (params: FFIDPreviewPlanChangeParams) => Promise<FFIDApiResponse<FFIDPlanChangePreviewResponse>>;
171
364
  verifyAccessToken: (accessToken: string, options?: FFIDVerifyAccessTokenOptions) => Promise<FFIDApiResponse<FFIDOAuthUserInfo>>;
172
365
  requestPasswordReset: (email: string) => Promise<FFIDApiResponse<FFIDPasswordResetResponse>>;
173
366
  verifyPasswordResetToken: (accessToken: string) => Promise<FFIDApiResponse<FFIDPasswordResetVerifyResponse>>;
@@ -448,4 +641,4 @@ declare function createFFIDAnnouncementsClient(config?: FFIDAnnouncementsClientC
448
641
  /** Type of the FFID Announcements client */
449
642
  type FFIDAnnouncementsClient = ReturnType<typeof createFFIDAnnouncementsClient>;
450
643
 
451
- export { AnnouncementListResponse, DEFAULT_API_BASE_URL, FFIDAnnouncementsApiResponse, type FFIDAnnouncementsClient, FFIDAnnouncementsClientConfig, FFIDAnnouncementsLogger, FFIDApiResponse, FFIDCacheAdapter, FFIDCheckoutSessionResponse, type FFIDClient, FFIDConfig, FFIDCreateCheckoutParams, FFIDCreatePortalParams, FFIDError, FFIDListMembersResponse, FFIDLogger, FFIDMemberRole, FFIDOAuthUserInfo, FFIDOrganization, type FFIDOtpSendResponse, type FFIDOtpVerifyResponse, type FFIDPasswordResetConfirmResponse, type FFIDPasswordResetResponse, type FFIDPasswordResetVerifyResponse, FFIDPortalSessionResponse, FFIDProvider, type FFIDProviderProps, FFIDRedirectResult, FFIDRemoveMemberResponse, type FFIDResetSessionResponse, FFIDSessionResponse, FFIDSubscription, FFIDSubscriptionCheckResponse, FFIDSubscriptionContextValue, FFIDUpdateMemberRoleResponse, FFIDUser, FFIDVerifyAccessTokenOptions, FFID_ANNOUNCEMENTS_ERROR_CODES, type KVNamespaceLike, ListAnnouncementsOptions, type RedirectToAuthorizeOptions, type TokenData, type TokenStore, type UseFFIDReturn, type WithFFIDAuthOptions, type WithSubscriptionOptions, createFFIDAnnouncementsClient, createFFIDClient, createKVCacheAdapter, createMemoryCacheAdapter, createTokenStore, generateCodeChallenge, generateCodeVerifier, retrieveCodeVerifier, storeCodeVerifier, useFFID, useSubscription, withFFIDAuth, withSubscription };
644
+ export { AnnouncementListResponse, DEFAULT_API_BASE_URL, FFIDAnnouncementsApiResponse, type FFIDAnnouncementsClient, FFIDAnnouncementsClientConfig, FFIDAnnouncementsLogger, FFIDApiResponse, type FFIDBillingInterval, FFIDCacheAdapter, type FFIDCancelSubscriptionParams, type FFIDCancelSubscriptionResponse, type FFIDChangePlanParams, type FFIDChangePlanResponse, FFIDCheckoutSessionResponse, type FFIDClient, FFIDConfig, FFIDCreateCheckoutParams, FFIDCreatePortalParams, FFIDError, FFIDListMembersResponse, type FFIDListPlansResponse, FFIDLogger, FFIDMemberRole, FFIDOAuthUserInfo, FFIDOrganization, type FFIDOtpSendResponse, type FFIDOtpVerifyResponse, type FFIDPasswordResetConfirmResponse, type FFIDPasswordResetResponse, type FFIDPasswordResetVerifyResponse, type FFIDPlanChangeLineItem, type FFIDPlanChangePreviewResponse, type FFIDPlanInfo, FFIDPortalSessionResponse, type FFIDPreviewPlanChangeParams, FFIDProvider, type FFIDProviderProps, FFIDRedirectResult, FFIDRemoveMemberResponse, type FFIDResetSessionResponse, type FFIDServiceInfo, FFIDSessionResponse, type FFIDSubscribeParams, type FFIDSubscribeResponse, FFIDSubscription, FFIDSubscriptionCheckResponse, FFIDSubscriptionContextValue, type FFIDSubscriptionDetail, FFIDSubscriptionStatus, type FFIDSubscriptionSummary, FFIDUpdateMemberRoleResponse, FFIDUser, FFIDVerifyAccessTokenOptions, FFID_ANNOUNCEMENTS_ERROR_CODES, type KVNamespaceLike, ListAnnouncementsOptions, type RedirectToAuthorizeOptions, type TokenData, type TokenStore, type UseFFIDReturn, type WithFFIDAuthOptions, type WithSubscriptionOptions, createFFIDAnnouncementsClient, createFFIDClient, createKVCacheAdapter, createMemoryCacheAdapter, createTokenStore, generateCodeChallenge, generateCodeVerifier, retrieveCodeVerifier, storeCodeVerifier, useFFID, useSubscription, withFFIDAuth, withSubscription };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FFIDConfig, a as FFIDApiResponse, b as FFIDSessionResponse, c as FFIDRedirectResult, d as FFIDError, e as FFIDSubscriptionCheckResponse, f as FFIDListMembersResponse, g as FFIDMemberRole, h as FFIDUpdateMemberRoleResponse, i as FFIDRemoveMemberResponse, j as FFIDCreateCheckoutParams, k as FFIDCheckoutSessionResponse, l as FFIDCreatePortalParams, m as FFIDPortalSessionResponse, n as FFIDVerifyAccessTokenOptions, o as FFIDOAuthUserInfo, p as FFIDAuthMode, q as FFIDLogger, r as FFIDCacheAdapter, s as FFIDUser, t as FFIDOrganization, u as FFIDSubscription, v as FFIDSubscriptionContextValue, w as FFIDAnnouncementsClientConfig, L as ListAnnouncementsOptions, x as FFIDAnnouncementsApiResponse, A as AnnouncementListResponse, y as FFIDAnnouncementsLogger } from './index-BHh-uxYS.js';
2
- export { z as Announcement, B as AnnouncementStatus, C as AnnouncementType, D as FFIDAnnouncementBadge, E as FFIDAnnouncementList, G as FFIDAnnouncementsError, H as FFIDAnnouncementsErrorCode, I as FFIDAnnouncementsServerResponse, J as FFIDCacheConfig, K as FFIDContextValue, M as FFIDJwtClaims, N as FFIDLoginButton, O as FFIDMemberStatus, P as FFIDOAuthTokenResponse, Q as FFIDOAuthUserInfoMemberRole, R as FFIDOAuthUserInfoSubscription, S as FFIDOrganizationMember, T as FFIDOrganizationSwitcher, U as FFIDSeatModel, V as FFIDSubscriptionBadge, W as FFIDSubscriptionStatus, X as FFIDTokenIntrospectionResponse, Y as FFIDUserMenu, Z as UseFFIDAnnouncementsOptions, _ as UseFFIDAnnouncementsReturn, $ as useFFIDAnnouncements } from './index-BHh-uxYS.js';
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 FFIDCreateCheckoutParams, l as FFIDCheckoutSessionResponse, m as FFIDCreatePortalParams, n as FFIDPortalSessionResponse, o as FFIDVerifyAccessTokenOptions, p as FFIDOAuthUserInfo, q as FFIDAuthMode, r as FFIDLogger, s as FFIDCacheAdapter, t as FFIDUser, u as FFIDOrganization, v as FFIDSubscription, w as FFIDSubscriptionContextValue, x as FFIDAnnouncementsClientConfig, L as ListAnnouncementsOptions, y as FFIDAnnouncementsApiResponse, A as AnnouncementListResponse, z as FFIDAnnouncementsLogger } from './index-p4dJw3qR.js';
2
+ export { B as Announcement, C as AnnouncementStatus, D as AnnouncementType, E as FFIDAnnouncementBadge, G as FFIDAnnouncementList, H as FFIDAnnouncementsError, I as FFIDAnnouncementsErrorCode, J as FFIDAnnouncementsServerResponse, K as FFIDCacheConfig, M as FFIDContextValue, N as FFIDJwtClaims, O as FFIDLoginButton, P as FFIDMemberStatus, Q as FFIDOAuthTokenResponse, R as FFIDOAuthUserInfoMemberRole, S as FFIDOAuthUserInfoSubscription, T as FFIDOrganizationMember, U as FFIDOrganizationSwitcher, V as FFIDSeatModel, W as FFIDSubscriptionBadge, X as FFIDTokenIntrospectionResponse, Y as FFIDUserMenu, Z as UseFFIDAnnouncementsOptions, _ as UseFFIDAnnouncementsReturn, $ as useFFIDAnnouncements } from './index-p4dJw3qR.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode, ComponentType, FC } from 'react';
5
5
 
@@ -92,6 +92,193 @@ declare function storeCodeVerifier(verifier: string, logger?: PKCELogger): boole
92
92
  */
93
93
  declare function retrieveCodeVerifier(logger?: PKCELogger): string | null;
94
94
 
95
+ /** Billing interval for subscriptions */
96
+ type FFIDBillingInterval = 'monthly' | 'yearly';
97
+ /** Service information returned by plans endpoint */
98
+ interface FFIDServiceInfo {
99
+ id: string;
100
+ code: string;
101
+ name: string;
102
+ description: string | null;
103
+ isActive: boolean;
104
+ createdAt: string;
105
+ plans: FFIDPlanInfo[];
106
+ }
107
+ /** Plan information returned by plans endpoint */
108
+ interface FFIDPlanInfo {
109
+ id: string;
110
+ serviceId: string;
111
+ code: string;
112
+ name: string;
113
+ description: string | null;
114
+ minSeats: number;
115
+ maxSeats: number | null;
116
+ trialDays: number;
117
+ priceMonthly: number;
118
+ priceYearly: number | null;
119
+ currency: string;
120
+ isActive: boolean;
121
+ displayOrder: number;
122
+ customPricing: boolean;
123
+ createdAt: string;
124
+ }
125
+ /** Response from list plans endpoint */
126
+ interface FFIDListPlansResponse {
127
+ services: FFIDServiceInfo[];
128
+ count: number;
129
+ }
130
+ /** Subscription details returned by ext API (sanitized, no Stripe IDs) */
131
+ interface FFIDSubscriptionDetail {
132
+ id: string;
133
+ organizationId: string;
134
+ organizationName: string;
135
+ serviceCode: string;
136
+ serviceName: string;
137
+ planCode: string;
138
+ planName: string;
139
+ status: FFIDSubscriptionStatus;
140
+ paymentMethod: string | null;
141
+ billingInterval: FFIDBillingInterval;
142
+ quantity: number;
143
+ currentPeriodStart: string | null;
144
+ currentPeriodEnd: string | null;
145
+ trialStart: string | null;
146
+ trialEnd: string | null;
147
+ canceledAt: string | null;
148
+ cancelAtPeriodEnd: boolean;
149
+ createdAt: string;
150
+ }
151
+ /** Parameters for subscribing to a plan */
152
+ interface FFIDSubscribeParams {
153
+ /** Organization ID (UUID) */
154
+ organizationId: string;
155
+ /** Plan code (e.g., 'free', 'basic', 'pro') */
156
+ planCode: string;
157
+ /** Billing interval (default: 'monthly') */
158
+ billingInterval?: FFIDBillingInterval;
159
+ /** Number of seats (default: plan's minSeats) */
160
+ quantity?: number;
161
+ /** User ID for seat auto-assignment (only needed for service-key mode) */
162
+ userId?: string;
163
+ }
164
+ /** Sanitized subscription fields returned by subscribe/reactivate endpoints (no Stripe IDs) */
165
+ interface FFIDSubscriptionSummary {
166
+ id: string;
167
+ organizationId: string;
168
+ serviceId: string;
169
+ planId: string;
170
+ status: FFIDSubscriptionStatus;
171
+ paymentMethod: string | null;
172
+ billingInterval: FFIDBillingInterval;
173
+ quantity: number;
174
+ currentPeriodStart: string | null;
175
+ currentPeriodEnd: string | null;
176
+ trialStart: string | null;
177
+ trialEnd: string | null;
178
+ canceledAt: string | null;
179
+ cancelAtPeriodEnd: boolean;
180
+ createdAt: string;
181
+ }
182
+ /** Response from subscribe endpoint */
183
+ interface FFIDSubscribeResponse {
184
+ subscription: FFIDSubscriptionSummary;
185
+ service: {
186
+ id: string;
187
+ code: string;
188
+ name: string;
189
+ };
190
+ plan: {
191
+ id: string;
192
+ code: string;
193
+ name: string;
194
+ priceMonthly: number;
195
+ priceYearly: number | null;
196
+ trialDays: number;
197
+ };
198
+ /** True if a canceled subscription was reactivated */
199
+ reactivated?: boolean;
200
+ /** True if Stripe checkout is needed (canceled paid plan reactivation) */
201
+ needsCheckout?: boolean;
202
+ }
203
+ /** Parameters for changing plan */
204
+ interface FFIDChangePlanParams {
205
+ /** Subscription ID (UUID) */
206
+ subscriptionId: string;
207
+ /** New plan code */
208
+ planCode: string;
209
+ /** New billing interval (default: keeps current) */
210
+ billingInterval?: FFIDBillingInterval;
211
+ }
212
+ /** Response from change plan endpoint */
213
+ interface FFIDChangePlanResponse {
214
+ message: string;
215
+ subscription: {
216
+ id: string;
217
+ organizationId: string;
218
+ serviceCode: string;
219
+ planCode: string;
220
+ planName: string;
221
+ billingInterval: FFIDBillingInterval;
222
+ status: FFIDSubscriptionStatus;
223
+ isUpgrade: boolean;
224
+ };
225
+ }
226
+ /** Parameters for canceling subscription */
227
+ interface FFIDCancelSubscriptionParams {
228
+ /** Subscription ID (UUID) */
229
+ subscriptionId: string;
230
+ /** Cancellation reason code */
231
+ reason?: 'too_expensive' | 'missing_features' | 'switched_service' | 'rarely_used' | 'customer_service' | 'other';
232
+ /** Additional cancellation details */
233
+ reasonDetails?: string;
234
+ }
235
+ /** Response from cancel subscription endpoint */
236
+ interface FFIDCancelSubscriptionResponse {
237
+ message: string;
238
+ subscription: {
239
+ id: string;
240
+ organizationId: string;
241
+ status: FFIDSubscriptionStatus;
242
+ canceledAt: string | null;
243
+ };
244
+ }
245
+ /** Parameters for previewing plan change */
246
+ interface FFIDPreviewPlanChangeParams {
247
+ /** Subscription ID (UUID) */
248
+ subscriptionId: string;
249
+ /** New plan code */
250
+ planCode: string;
251
+ /** New billing interval (default: keeps current) */
252
+ billingInterval?: FFIDBillingInterval;
253
+ }
254
+ /** Plan change preview line item */
255
+ interface FFIDPlanChangeLineItem {
256
+ description: string;
257
+ amount: number;
258
+ }
259
+ /** Response from plan change preview endpoint */
260
+ interface FFIDPlanChangePreviewResponse {
261
+ preview: {
262
+ currentPlan: {
263
+ name: string;
264
+ price: number;
265
+ };
266
+ newPlan: {
267
+ name: string;
268
+ price: number;
269
+ };
270
+ billingInterval: FFIDBillingInterval;
271
+ isUpgrade: boolean;
272
+ proratedAmount: number;
273
+ nextInvoiceAmount: number;
274
+ nextInvoiceDate: string | null;
275
+ currency: string;
276
+ isEstimate: boolean;
277
+ estimateReason?: string;
278
+ lineItems: FFIDPlanChangeLineItem[];
279
+ };
280
+ }
281
+
95
282
  /** OTP / magic link methods - sendOtp / verifyOtp */
96
283
 
97
284
  /** Response from sendOtp */
@@ -151,7 +338,7 @@ declare function createFFIDClient(config: FFIDConfig): {
151
338
  exchangeCodeForTokens: (code: string, codeVerifier?: string) => Promise<FFIDApiResponse<void>>;
152
339
  refreshAccessToken: () => Promise<FFIDApiResponse<void>>;
153
340
  checkSubscription: (params: {
154
- userId: string;
341
+ userId?: string;
155
342
  organizationId: string;
156
343
  }) => Promise<FFIDApiResponse<FFIDSubscriptionCheckResponse>>;
157
344
  listMembers: (params: {
@@ -168,6 +355,12 @@ declare function createFFIDClient(config: FFIDConfig): {
168
355
  }) => Promise<FFIDApiResponse<FFIDRemoveMemberResponse>>;
169
356
  createCheckoutSession: (params: FFIDCreateCheckoutParams) => Promise<FFIDApiResponse<FFIDCheckoutSessionResponse>>;
170
357
  createPortalSession: (params: FFIDCreatePortalParams) => Promise<FFIDApiResponse<FFIDPortalSessionResponse>>;
358
+ listPlans: () => Promise<FFIDApiResponse<FFIDListPlansResponse>>;
359
+ getSubscription: (subscriptionId: string) => Promise<FFIDApiResponse<FFIDSubscriptionDetail>>;
360
+ subscribe: (params: FFIDSubscribeParams) => Promise<FFIDApiResponse<FFIDSubscribeResponse>>;
361
+ changePlan: (params: FFIDChangePlanParams) => Promise<FFIDApiResponse<FFIDChangePlanResponse>>;
362
+ cancelSubscription: (params: FFIDCancelSubscriptionParams) => Promise<FFIDApiResponse<FFIDCancelSubscriptionResponse>>;
363
+ previewPlanChange: (params: FFIDPreviewPlanChangeParams) => Promise<FFIDApiResponse<FFIDPlanChangePreviewResponse>>;
171
364
  verifyAccessToken: (accessToken: string, options?: FFIDVerifyAccessTokenOptions) => Promise<FFIDApiResponse<FFIDOAuthUserInfo>>;
172
365
  requestPasswordReset: (email: string) => Promise<FFIDApiResponse<FFIDPasswordResetResponse>>;
173
366
  verifyPasswordResetToken: (accessToken: string) => Promise<FFIDApiResponse<FFIDPasswordResetVerifyResponse>>;
@@ -448,4 +641,4 @@ declare function createFFIDAnnouncementsClient(config?: FFIDAnnouncementsClientC
448
641
  /** Type of the FFID Announcements client */
449
642
  type FFIDAnnouncementsClient = ReturnType<typeof createFFIDAnnouncementsClient>;
450
643
 
451
- export { AnnouncementListResponse, DEFAULT_API_BASE_URL, FFIDAnnouncementsApiResponse, type FFIDAnnouncementsClient, FFIDAnnouncementsClientConfig, FFIDAnnouncementsLogger, FFIDApiResponse, FFIDCacheAdapter, FFIDCheckoutSessionResponse, type FFIDClient, FFIDConfig, FFIDCreateCheckoutParams, FFIDCreatePortalParams, FFIDError, FFIDListMembersResponse, FFIDLogger, FFIDMemberRole, FFIDOAuthUserInfo, FFIDOrganization, type FFIDOtpSendResponse, type FFIDOtpVerifyResponse, type FFIDPasswordResetConfirmResponse, type FFIDPasswordResetResponse, type FFIDPasswordResetVerifyResponse, FFIDPortalSessionResponse, FFIDProvider, type FFIDProviderProps, FFIDRedirectResult, FFIDRemoveMemberResponse, type FFIDResetSessionResponse, FFIDSessionResponse, FFIDSubscription, FFIDSubscriptionCheckResponse, FFIDSubscriptionContextValue, FFIDUpdateMemberRoleResponse, FFIDUser, FFIDVerifyAccessTokenOptions, FFID_ANNOUNCEMENTS_ERROR_CODES, type KVNamespaceLike, ListAnnouncementsOptions, type RedirectToAuthorizeOptions, type TokenData, type TokenStore, type UseFFIDReturn, type WithFFIDAuthOptions, type WithSubscriptionOptions, createFFIDAnnouncementsClient, createFFIDClient, createKVCacheAdapter, createMemoryCacheAdapter, createTokenStore, generateCodeChallenge, generateCodeVerifier, retrieveCodeVerifier, storeCodeVerifier, useFFID, useSubscription, withFFIDAuth, withSubscription };
644
+ export { AnnouncementListResponse, DEFAULT_API_BASE_URL, FFIDAnnouncementsApiResponse, type FFIDAnnouncementsClient, FFIDAnnouncementsClientConfig, FFIDAnnouncementsLogger, FFIDApiResponse, type FFIDBillingInterval, FFIDCacheAdapter, type FFIDCancelSubscriptionParams, type FFIDCancelSubscriptionResponse, type FFIDChangePlanParams, type FFIDChangePlanResponse, FFIDCheckoutSessionResponse, type FFIDClient, FFIDConfig, FFIDCreateCheckoutParams, FFIDCreatePortalParams, FFIDError, FFIDListMembersResponse, type FFIDListPlansResponse, FFIDLogger, FFIDMemberRole, FFIDOAuthUserInfo, FFIDOrganization, type FFIDOtpSendResponse, type FFIDOtpVerifyResponse, type FFIDPasswordResetConfirmResponse, type FFIDPasswordResetResponse, type FFIDPasswordResetVerifyResponse, type FFIDPlanChangeLineItem, type FFIDPlanChangePreviewResponse, type FFIDPlanInfo, FFIDPortalSessionResponse, type FFIDPreviewPlanChangeParams, FFIDProvider, type FFIDProviderProps, FFIDRedirectResult, FFIDRemoveMemberResponse, type FFIDResetSessionResponse, type FFIDServiceInfo, FFIDSessionResponse, type FFIDSubscribeParams, type FFIDSubscribeResponse, FFIDSubscription, FFIDSubscriptionCheckResponse, FFIDSubscriptionContextValue, type FFIDSubscriptionDetail, FFIDSubscriptionStatus, type FFIDSubscriptionSummary, FFIDUpdateMemberRoleResponse, FFIDUser, FFIDVerifyAccessTokenOptions, FFID_ANNOUNCEMENTS_ERROR_CODES, type KVNamespaceLike, ListAnnouncementsOptions, type RedirectToAuthorizeOptions, type TokenData, type TokenStore, type UseFFIDReturn, type WithFFIDAuthOptions, type WithSubscriptionOptions, createFFIDAnnouncementsClient, createFFIDClient, createKVCacheAdapter, createMemoryCacheAdapter, createTokenStore, generateCodeChallenge, generateCodeVerifier, retrieveCodeVerifier, storeCodeVerifier, useFFID, useSubscription, withFFIDAuth, withSubscription };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { useFFIDContext } from './chunk-ZJIZTYXQ.js';
2
- export { DEFAULT_API_BASE_URL, FFIDAnnouncementBadge, FFIDAnnouncementList, FFIDLoginButton, FFIDOrganizationSwitcher, FFIDProvider, FFIDSubscriptionBadge, FFIDUserMenu, FFID_ANNOUNCEMENTS_ERROR_CODES, createFFIDAnnouncementsClient, createFFIDClient, createTokenStore, generateCodeChallenge, generateCodeVerifier, retrieveCodeVerifier, storeCodeVerifier, useFFID, useFFIDAnnouncements, useSubscription, withSubscription } from './chunk-ZJIZTYXQ.js';
1
+ import { useFFIDContext } from './chunk-66HJMEHY.js';
2
+ export { DEFAULT_API_BASE_URL, FFIDAnnouncementBadge, FFIDAnnouncementList, FFIDLoginButton, FFIDOrganizationSwitcher, FFIDProvider, FFIDSubscriptionBadge, FFIDUserMenu, FFID_ANNOUNCEMENTS_ERROR_CODES, createFFIDAnnouncementsClient, createFFIDClient, createTokenStore, generateCodeChallenge, generateCodeVerifier, retrieveCodeVerifier, storeCodeVerifier, useFFID, useFFIDAnnouncements, useSubscription, withSubscription } from './chunk-66HJMEHY.js';
3
3
  import { useRef, useEffect } from 'react';
4
4
  import { jsx, Fragment } from 'react/jsx-runtime';
5
5
 
@@ -443,6 +443,106 @@ function createBillingMethods(deps) {
443
443
  return { createCheckoutSession, createPortalSession };
444
444
  }
445
445
 
446
+ // src/client/subscription-methods.ts
447
+ var EXT_PLANS_ENDPOINT = "/api/v1/subscriptions/ext/plans";
448
+ var EXT_SUBSCRIPTION_ENDPOINT = "/api/v1/subscriptions/ext";
449
+ var EXT_SUBSCRIBE_ENDPOINT = "/api/v1/subscriptions/ext/subscribe";
450
+ function createSubscriptionMethods(deps) {
451
+ const { fetchWithAuth, createError } = deps;
452
+ async function listPlans() {
453
+ return fetchWithAuth(EXT_PLANS_ENDPOINT);
454
+ }
455
+ async function getSubscription(subscriptionId) {
456
+ if (!subscriptionId) {
457
+ return {
458
+ error: createError("VALIDATION_ERROR", "subscriptionId \u306F\u5FC5\u9808\u3067\u3059")
459
+ };
460
+ }
461
+ return fetchWithAuth(
462
+ `${EXT_SUBSCRIPTION_ENDPOINT}/${encodeURIComponent(subscriptionId)}`
463
+ );
464
+ }
465
+ async function subscribe(params) {
466
+ if (!params.organizationId || !params.planCode) {
467
+ return {
468
+ error: createError("VALIDATION_ERROR", "organizationId \u3068 planCode \u306F\u5FC5\u9808\u3067\u3059")
469
+ };
470
+ }
471
+ return fetchWithAuth(
472
+ EXT_SUBSCRIBE_ENDPOINT,
473
+ {
474
+ method: "POST",
475
+ body: JSON.stringify({
476
+ organizationId: params.organizationId,
477
+ planCode: params.planCode,
478
+ ...params.billingInterval ? { billingInterval: params.billingInterval } : {},
479
+ ...params.quantity !== void 0 ? { quantity: params.quantity } : {},
480
+ ...params.userId ? { userId: params.userId } : {}
481
+ })
482
+ }
483
+ );
484
+ }
485
+ async function changePlan(params) {
486
+ if (!params.subscriptionId || !params.planCode) {
487
+ return {
488
+ error: createError("VALIDATION_ERROR", "subscriptionId \u3068 planCode \u306F\u5FC5\u9808\u3067\u3059")
489
+ };
490
+ }
491
+ return fetchWithAuth(
492
+ `${EXT_SUBSCRIPTION_ENDPOINT}/${encodeURIComponent(params.subscriptionId)}/plan`,
493
+ {
494
+ method: "PUT",
495
+ body: JSON.stringify({
496
+ planCode: params.planCode,
497
+ ...params.billingInterval ? { billingInterval: params.billingInterval } : {}
498
+ })
499
+ }
500
+ );
501
+ }
502
+ async function cancelSubscription(params) {
503
+ if (!params.subscriptionId) {
504
+ return {
505
+ error: createError("VALIDATION_ERROR", "subscriptionId \u306F\u5FC5\u9808\u3067\u3059")
506
+ };
507
+ }
508
+ const body = {};
509
+ if (params.reason) body.reason = params.reason;
510
+ if (params.reasonDetails) body.reasonDetails = params.reasonDetails;
511
+ return fetchWithAuth(
512
+ `${EXT_SUBSCRIPTION_ENDPOINT}/${encodeURIComponent(params.subscriptionId)}`,
513
+ {
514
+ method: "DELETE",
515
+ ...Object.keys(body).length > 0 ? { body: JSON.stringify(body) } : {}
516
+ }
517
+ );
518
+ }
519
+ async function previewPlanChange(params) {
520
+ if (!params.subscriptionId || !params.planCode) {
521
+ return {
522
+ error: createError("VALIDATION_ERROR", "subscriptionId \u3068 planCode \u306F\u5FC5\u9808\u3067\u3059")
523
+ };
524
+ }
525
+ return fetchWithAuth(
526
+ `${EXT_SUBSCRIPTION_ENDPOINT}/${encodeURIComponent(params.subscriptionId)}/plan/preview`,
527
+ {
528
+ method: "POST",
529
+ body: JSON.stringify({
530
+ planCode: params.planCode,
531
+ ...params.billingInterval ? { billingInterval: params.billingInterval } : {}
532
+ })
533
+ }
534
+ );
535
+ }
536
+ return {
537
+ listPlans,
538
+ getSubscription,
539
+ subscribe,
540
+ changePlan,
541
+ cancelSubscription,
542
+ previewPlanChange
543
+ };
544
+ }
545
+
446
546
  // src/client/members-methods.ts
447
547
  var EXT_MEMBERS_ENDPOINT = "/api/v1/organizations/ext/members";
448
548
  function createMembersMethods(deps) {
@@ -496,7 +596,7 @@ function createMembersMethods(deps) {
496
596
  }
497
597
 
498
598
  // src/client/version-check.ts
499
- var SDK_VERSION = "1.18.0";
599
+ var SDK_VERSION = "1.19.1";
500
600
  var SDK_USER_AGENT = `FFID-SDK/${SDK_VERSION} (TypeScript)`;
501
601
  var SDK_VERSION_HEADER = "X-FFID-SDK-Version";
502
602
  function sdkHeaders() {
@@ -1538,16 +1638,23 @@ function createFFIDClient(config) {
1538
1638
  logger
1539
1639
  });
1540
1640
  async function checkSubscription(params) {
1541
- if (!params.userId || !params.organizationId) {
1641
+ if (!params.organizationId) {
1642
+ return {
1643
+ error: createError("VALIDATION_ERROR", "organizationId \u306F\u5FC5\u9808\u3067\u3059")
1644
+ };
1645
+ }
1646
+ if (params.userId !== void 0 && !params.userId.trim()) {
1542
1647
  return {
1543
- error: createError("VALIDATION_ERROR", "userId \u3068 organizationId \u306F\u5FC5\u9808\u3067\u3059")
1648
+ error: createError("VALIDATION_ERROR", "userId \u3092\u6307\u5B9A\u3059\u308B\u5834\u5408\u3001\u7A7A\u6587\u5B57\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093")
1544
1649
  };
1545
1650
  }
1546
1651
  const query = new URLSearchParams({
1547
- userId: params.userId,
1548
1652
  organizationId: params.organizationId,
1549
1653
  serviceCode: config.serviceCode
1550
1654
  });
1655
+ if (params.userId) {
1656
+ query.set("userId", params.userId);
1657
+ }
1551
1658
  return fetchWithAuth(
1552
1659
  `${EXT_CHECK_ENDPOINT}?${query.toString()}`
1553
1660
  );
@@ -1556,6 +1663,17 @@ function createFFIDClient(config) {
1556
1663
  fetchWithAuth,
1557
1664
  createError
1558
1665
  });
1666
+ const {
1667
+ listPlans,
1668
+ getSubscription,
1669
+ subscribe,
1670
+ changePlan,
1671
+ cancelSubscription,
1672
+ previewPlanChange
1673
+ } = createSubscriptionMethods({
1674
+ fetchWithAuth,
1675
+ createError
1676
+ });
1559
1677
  const { listMembers, updateMemberRole, removeMember } = createMembersMethods({
1560
1678
  fetchWithAuth,
1561
1679
  createError,
@@ -1609,6 +1727,12 @@ function createFFIDClient(config) {
1609
1727
  removeMember,
1610
1728
  createCheckoutSession,
1611
1729
  createPortalSession,
1730
+ listPlans,
1731
+ getSubscription,
1732
+ subscribe,
1733
+ changePlan,
1734
+ cancelSubscription,
1735
+ previewPlanChange,
1612
1736
  verifyAccessToken,
1613
1737
  requestPasswordReset,
1614
1738
  verifyPasswordResetToken,