perspectapi-ts-sdk 6.0.0 → 6.0.2

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.mts CHANGED
@@ -3341,6 +3341,11 @@ interface V2OrderCreateParams {
3341
3341
  referral_code?: string;
3342
3342
  referrer_site_user_id?: string;
3343
3343
  }
3344
+ interface V2OrderFulfillmentUpdate {
3345
+ fulfillment_status: string;
3346
+ tracking_number?: string;
3347
+ notes?: string;
3348
+ }
3344
3349
  interface V2OrderCreateResult extends V2Object {
3345
3350
  object: "checkout_session";
3346
3351
  checkout_url: string | null;
@@ -3594,6 +3599,71 @@ interface V2WebhookCreateParams {
3594
3599
  }
3595
3600
  interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
3596
3601
  }
3602
+ interface V2SiteUserSubscription extends V2Object {
3603
+ object: "site_user_subscription";
3604
+ site_user_id: string;
3605
+ provider: string | null;
3606
+ provider_subscription_id: string | null;
3607
+ plan_name: string | null;
3608
+ plan_id: string | null;
3609
+ status: string;
3610
+ amount: number | null;
3611
+ currency: string | null;
3612
+ billing_interval: string | null;
3613
+ billing_interval_count: number | null;
3614
+ current_period_start: string | null;
3615
+ current_period_end: string | null;
3616
+ trial_start: string | null;
3617
+ trial_end: string | null;
3618
+ canceled_at: string | null;
3619
+ cancel_at_period_end: boolean;
3620
+ metadata: Record<string, unknown> | null;
3621
+ created_at: string | null;
3622
+ updated_at: string | null;
3623
+ }
3624
+ interface V2SubscriptionPauseParams {
3625
+ resumes_at?: number;
3626
+ }
3627
+ interface V2SubscriptionCancelParams {
3628
+ mode?: "immediate" | "period_end" | "scheduled";
3629
+ cancel_at?: string;
3630
+ }
3631
+ interface V2SubscriptionChangePlanParams {
3632
+ product_id: string;
3633
+ }
3634
+ interface V2CancelSubscriptionResult {
3635
+ object: "subscription_cancel_result";
3636
+ mode: string;
3637
+ status: string;
3638
+ cancel_at_period_end: boolean;
3639
+ effective_at: string | null;
3640
+ scheduled_cancel_at: string | null;
3641
+ message: string;
3642
+ }
3643
+ interface V2CreditTransaction extends V2Object {
3644
+ object: "credit_transaction";
3645
+ site_user_id: string;
3646
+ amount_cents: number;
3647
+ balance_after_cents: number;
3648
+ type: string;
3649
+ description: string | null;
3650
+ reference_id: string | null;
3651
+ reference_type: string | null;
3652
+ created_at: string | null;
3653
+ }
3654
+ interface V2CreditBalance {
3655
+ object: "credit_balance";
3656
+ balance_cents: number;
3657
+ transactions?: V2CreditTransaction[];
3658
+ }
3659
+ interface V2GrantCreditParams {
3660
+ amount_cents: number;
3661
+ description: string;
3662
+ }
3663
+ interface V2GrantCreditResult {
3664
+ object: "grant_credit_result";
3665
+ new_balance_cents: number;
3666
+ }
3597
3667
 
3598
3668
  /**
3599
3669
  * v2 Base Client — cursor pagination, expand support, caching, typed errors.
@@ -3742,6 +3812,8 @@ declare class OrdersV2Client extends BaseV2Client {
3742
3812
  * dance — v2 is API-key-only and requires no CSRF token.
3743
3813
  */
3744
3814
  create(siteName: string, data: V2OrderCreateParams): Promise<V2OrderCreateResult>;
3815
+ /** Update fulfillment status, tracking number, and/or notes on an order. */
3816
+ updateFulfillment(siteName: string, id: string, data: V2OrderFulfillmentUpdate): Promise<V2Order>;
3745
3817
  }
3746
3818
 
3747
3819
  /**
@@ -3912,6 +3984,54 @@ declare class WebhooksV2Client extends BaseV2Client {
3912
3984
  del(siteName: string, id: string): Promise<V2Deleted>;
3913
3985
  }
3914
3986
 
3987
+ /**
3988
+ * v2 Subscriptions Client — lifecycle operations for site user subscriptions.
3989
+ *
3990
+ * Two classes of endpoints:
3991
+ * - /me paths require a site-user JWT (call `setAuth(jwt)` first)
3992
+ * - Admin paths require an API key (call `setApiKey(key)` first)
3993
+ */
3994
+
3995
+ declare class SubscriptionsV2Client extends BaseV2Client {
3996
+ /** List all subscriptions for the authenticated user. */
3997
+ listMySubscriptions(siteName: string): Promise<V2List<V2SiteUserSubscription>>;
3998
+ /** Pause a subscription. */
3999
+ pauseSubscription(siteName: string, subId: string, params?: V2SubscriptionPauseParams): Promise<V2SiteUserSubscription>;
4000
+ /** Resume a paused subscription. */
4001
+ resumeSubscription(siteName: string, subId: string): Promise<V2SiteUserSubscription>;
4002
+ /** Cancel a subscription. */
4003
+ cancelSubscription(siteName: string, subId: string, params?: V2SubscriptionCancelParams): Promise<V2CancelSubscriptionResult>;
4004
+ /** Change the plan (price) of a subscription. */
4005
+ changeSubscriptionPlan(siteName: string, subId: string, params: V2SubscriptionChangePlanParams): Promise<V2SiteUserSubscription>;
4006
+ /** List subscriptions for a specific user (admin). */
4007
+ listUserSubscriptions(siteName: string, userId: string): Promise<V2List<V2SiteUserSubscription>>;
4008
+ /** Pause a user's subscription (admin). */
4009
+ pauseUserSubscription(siteName: string, userId: string, subId: string, params?: V2SubscriptionPauseParams): Promise<V2SiteUserSubscription>;
4010
+ /** Resume a user's paused subscription (admin). */
4011
+ resumeUserSubscription(siteName: string, userId: string, subId: string): Promise<V2SiteUserSubscription>;
4012
+ /** Cancel a user's subscription (admin). */
4013
+ cancelUserSubscription(siteName: string, userId: string, subId: string, params?: V2SubscriptionCancelParams): Promise<V2CancelSubscriptionResult>;
4014
+ }
4015
+
4016
+ /**
4017
+ * v2 Credits Client — balance queries and admin grant operations.
4018
+ *
4019
+ * Two classes of endpoints:
4020
+ * - /me paths require a site-user JWT (call `setAuth(jwt)` first)
4021
+ * - Admin paths require an API key (call `setApiKey(key)` first)
4022
+ */
4023
+
4024
+ declare class CreditsV2Client extends BaseV2Client {
4025
+ /** Get the current credit balance for the authenticated user. */
4026
+ getMyBalance(siteName: string): Promise<V2CreditBalance>;
4027
+ /** Get credit balance and transaction history for the authenticated user. */
4028
+ getMyCredits(siteName: string): Promise<V2CreditBalance>;
4029
+ /** Get the credit balance for a specific user (admin). */
4030
+ getUserBalance(siteName: string, userId: string): Promise<V2CreditBalance>;
4031
+ /** Grant credit to a specific user (admin). */
4032
+ grantCredit(siteName: string, userId: string, data: V2GrantCreditParams): Promise<V2GrantCreditResult>;
4033
+ }
4034
+
3915
4035
  /**
3916
4036
  * PerspectAPI v2 SDK Client
3917
4037
  *
@@ -3942,6 +4062,8 @@ declare class PerspectApiV2Client {
3942
4062
  readonly sites: SitesV2Client;
3943
4063
  readonly apiKeys: ApiKeysV2Client;
3944
4064
  readonly webhooks: WebhooksV2Client;
4065
+ readonly subscriptions: SubscriptionsV2Client;
4066
+ readonly credits: CreditsV2Client;
3945
4067
  constructor(config: PerspectApiV2Config);
3946
4068
  /** Update the JWT token for authenticated requests. */
3947
4069
  setAuth(jwt: string): void;
@@ -3988,21 +4110,6 @@ declare class CloudflareKVCacheAdapter implements CacheAdapter {
3988
4110
  clear(): Promise<void>;
3989
4111
  }
3990
4112
 
3991
- /**
3992
- * Simple in-memory cache adapter primarily suited for development and testing.
3993
- */
3994
-
3995
- declare class InMemoryCacheAdapter implements CacheAdapter {
3996
- private store;
3997
- get(key: string): Promise<string | undefined>;
3998
- set(key: string, value: string, options?: {
3999
- ttlSeconds?: number;
4000
- }): Promise<void>;
4001
- delete(key: string): Promise<void>;
4002
- deleteMany(keys: string[]): Promise<void>;
4003
- clear(): Promise<void>;
4004
- }
4005
-
4006
4113
  /**
4007
4114
  * No-op cache adapter that disables caching while preserving the cache contract.
4008
4115
  */
@@ -4308,4 +4415,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
4308
4415
  error: string;
4309
4416
  }>;
4310
4417
 
4311
- export { type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheConfig, CacheManager, type CancelSubscriptionRequest, type CancelSubscriptionResponse, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, CloudflareKVCacheAdapter, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateBundleCollectionRequest, type CreateBundleGroupRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateProductSkuRequest, type CreateSiteRequest, type CreateWebhookRequest, type CreditBalance, type CreditBalanceWithTransactions, type CreditTransaction, DEFAULT_IMAGE_SIZES, type GrantCreditRequest, HttpClient, type HttpMethod, type ImageTransformOptions, InMemoryCacheAdapter, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type NewsletterCampaignDetail, type NewsletterCampaignListResponse, type NewsletterCampaignSummary, type NewsletterCampaignTestSendRequest, type NewsletterCampaignTestSendResponse, NewsletterClient, type NewsletterConfirmResponse, type NewsletterExportCreateRequest, type NewsletterExportCreateResponse, type NewsletterList, type NewsletterManagementCampaign, type NewsletterManagementCampaignListResponse, NewsletterManagementClient, type NewsletterManagementList, type NewsletterManagementListMembership, type NewsletterManagementPagination, type NewsletterManagementSeries, type NewsletterManagementStatsResponse, type NewsletterManagementSubscription, type NewsletterManagementSubscriptionsListResponse, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterSubscriptionImportRowRequest, type NewsletterSubscriptionMembershipUpdateRequest, type NewsletterSubscriptionSyncRequest, type NewsletterSubscriptionSyncResponse, type NewsletterSubscriptionsBulkAction, type NewsletterSubscriptionsBulkOutcome, type NewsletterSubscriptionsBulkUpdateRequest, type NewsletterSubscriptionsBulkUpdateResponse, type NewsletterSubscriptionsImportRequest, type NewsletterSubscriptionsImportResponse, type NewsletterSubscriptionsImportRowResult, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, PerspectApiV2Client, PerspectV2Error, type Product, type ProductBundleGroup, type ProductQueryParams, type ProductSku, type ProductSkuMediaItem, type ProductSkuOption, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type SubscriptionCancellationMode, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type V2ApiKey, type V2Category, type V2CategoryCreateParams, type V2CategoryUpdateParams, type V2Collection, type V2CollectionCreateParams, type V2CollectionItem, type V2CollectionUpdateParams, type V2ContactSubmission, type V2Content, type V2ContentCreateParams, type V2ContentListParams, type V2ContentUpdateParams, type V2Deleted, type V2Error, type V2ErrorType, type V2List, type V2Media, type V2NewsletterCampaign, type V2NewsletterImportRequest, type V2NewsletterImportResult, type V2NewsletterList, type V2NewsletterListCreateParams, type V2NewsletterListUpdateParams, type V2NewsletterSubscription, type V2NewsletterSubscriptionListMembershipUpdate, type V2NewsletterSyncInput, type V2NewsletterSyncResult, type V2NewsletterTrackingResponse, type V2Object, type V2Order, type V2OrderAddress, type V2OrderCreateParams, type V2OrderCreateResult, type V2OrderLineItem, type V2OrderLineItemPriceData, type V2OrderListParams, type V2OrderTaxRequest, type V2Organization, type V2PaginationParams, type V2Product, type V2ProductCreateParams, type V2ProductListParams, type V2ProductUpdateParams, type V2Site, type V2SiteUser, type V2SiteUserListParams, type V2SiteUserMeUpdateParams, type V2SiteUserProfile, type V2SiteUserUpdateParams, type V2SiteUserWithProfile, type V2Webhook, type V2WebhookCreateParams, type V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
4418
+ export { type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheConfig, CacheManager, type CancelSubscriptionRequest, type CancelSubscriptionResponse, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, CloudflareKVCacheAdapter, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateBundleCollectionRequest, type CreateBundleGroupRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateProductSkuRequest, type CreateSiteRequest, type CreateWebhookRequest, type CreditBalance, type CreditBalanceWithTransactions, type CreditTransaction, DEFAULT_IMAGE_SIZES, type GrantCreditRequest, HttpClient, type HttpMethod, type ImageTransformOptions, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type NewsletterCampaignDetail, type NewsletterCampaignListResponse, type NewsletterCampaignSummary, type NewsletterCampaignTestSendRequest, type NewsletterCampaignTestSendResponse, NewsletterClient, type NewsletterConfirmResponse, type NewsletterExportCreateRequest, type NewsletterExportCreateResponse, type NewsletterList, type NewsletterManagementCampaign, type NewsletterManagementCampaignListResponse, NewsletterManagementClient, type NewsletterManagementList, type NewsletterManagementListMembership, type NewsletterManagementPagination, type NewsletterManagementSeries, type NewsletterManagementStatsResponse, type NewsletterManagementSubscription, type NewsletterManagementSubscriptionsListResponse, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterSubscriptionImportRowRequest, type NewsletterSubscriptionMembershipUpdateRequest, type NewsletterSubscriptionSyncRequest, type NewsletterSubscriptionSyncResponse, type NewsletterSubscriptionsBulkAction, type NewsletterSubscriptionsBulkOutcome, type NewsletterSubscriptionsBulkUpdateRequest, type NewsletterSubscriptionsBulkUpdateResponse, type NewsletterSubscriptionsImportRequest, type NewsletterSubscriptionsImportResponse, type NewsletterSubscriptionsImportRowResult, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, PerspectApiV2Client, PerspectV2Error, type Product, type ProductBundleGroup, type ProductQueryParams, type ProductSku, type ProductSkuMediaItem, type ProductSkuOption, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type SubscriptionCancellationMode, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type V2ApiKey, type V2CancelSubscriptionResult, type V2Category, type V2CategoryCreateParams, type V2CategoryUpdateParams, type V2Collection, type V2CollectionCreateParams, type V2CollectionItem, type V2CollectionUpdateParams, type V2ContactSubmission, type V2Content, type V2ContentCreateParams, type V2ContentListParams, type V2ContentUpdateParams, type V2CreditBalance, type V2CreditTransaction, type V2Deleted, type V2Error, type V2ErrorType, type V2GrantCreditParams, type V2GrantCreditResult, type V2List, type V2Media, type V2NewsletterCampaign, type V2NewsletterImportRequest, type V2NewsletterImportResult, type V2NewsletterList, type V2NewsletterListCreateParams, type V2NewsletterListUpdateParams, type V2NewsletterSubscription, type V2NewsletterSubscriptionListMembershipUpdate, type V2NewsletterSyncInput, type V2NewsletterSyncResult, type V2NewsletterTrackingResponse, type V2Object, type V2Order, type V2OrderAddress, type V2OrderCreateParams, type V2OrderCreateResult, type V2OrderFulfillmentUpdate, type V2OrderLineItem, type V2OrderLineItemPriceData, type V2OrderListParams, type V2OrderTaxRequest, type V2Organization, type V2PaginationParams, type V2Product, type V2ProductCreateParams, type V2ProductListParams, type V2ProductUpdateParams, type V2Site, type V2SiteUser, type V2SiteUserListParams, type V2SiteUserMeUpdateParams, type V2SiteUserProfile, type V2SiteUserSubscription, type V2SiteUserUpdateParams, type V2SiteUserWithProfile, type V2SubscriptionCancelParams, type V2SubscriptionChangePlanParams, type V2SubscriptionPauseParams, type V2Webhook, type V2WebhookCreateParams, type V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
package/dist/index.d.ts CHANGED
@@ -3341,6 +3341,11 @@ interface V2OrderCreateParams {
3341
3341
  referral_code?: string;
3342
3342
  referrer_site_user_id?: string;
3343
3343
  }
3344
+ interface V2OrderFulfillmentUpdate {
3345
+ fulfillment_status: string;
3346
+ tracking_number?: string;
3347
+ notes?: string;
3348
+ }
3344
3349
  interface V2OrderCreateResult extends V2Object {
3345
3350
  object: "checkout_session";
3346
3351
  checkout_url: string | null;
@@ -3594,6 +3599,71 @@ interface V2WebhookCreateParams {
3594
3599
  }
3595
3600
  interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
3596
3601
  }
3602
+ interface V2SiteUserSubscription extends V2Object {
3603
+ object: "site_user_subscription";
3604
+ site_user_id: string;
3605
+ provider: string | null;
3606
+ provider_subscription_id: string | null;
3607
+ plan_name: string | null;
3608
+ plan_id: string | null;
3609
+ status: string;
3610
+ amount: number | null;
3611
+ currency: string | null;
3612
+ billing_interval: string | null;
3613
+ billing_interval_count: number | null;
3614
+ current_period_start: string | null;
3615
+ current_period_end: string | null;
3616
+ trial_start: string | null;
3617
+ trial_end: string | null;
3618
+ canceled_at: string | null;
3619
+ cancel_at_period_end: boolean;
3620
+ metadata: Record<string, unknown> | null;
3621
+ created_at: string | null;
3622
+ updated_at: string | null;
3623
+ }
3624
+ interface V2SubscriptionPauseParams {
3625
+ resumes_at?: number;
3626
+ }
3627
+ interface V2SubscriptionCancelParams {
3628
+ mode?: "immediate" | "period_end" | "scheduled";
3629
+ cancel_at?: string;
3630
+ }
3631
+ interface V2SubscriptionChangePlanParams {
3632
+ product_id: string;
3633
+ }
3634
+ interface V2CancelSubscriptionResult {
3635
+ object: "subscription_cancel_result";
3636
+ mode: string;
3637
+ status: string;
3638
+ cancel_at_period_end: boolean;
3639
+ effective_at: string | null;
3640
+ scheduled_cancel_at: string | null;
3641
+ message: string;
3642
+ }
3643
+ interface V2CreditTransaction extends V2Object {
3644
+ object: "credit_transaction";
3645
+ site_user_id: string;
3646
+ amount_cents: number;
3647
+ balance_after_cents: number;
3648
+ type: string;
3649
+ description: string | null;
3650
+ reference_id: string | null;
3651
+ reference_type: string | null;
3652
+ created_at: string | null;
3653
+ }
3654
+ interface V2CreditBalance {
3655
+ object: "credit_balance";
3656
+ balance_cents: number;
3657
+ transactions?: V2CreditTransaction[];
3658
+ }
3659
+ interface V2GrantCreditParams {
3660
+ amount_cents: number;
3661
+ description: string;
3662
+ }
3663
+ interface V2GrantCreditResult {
3664
+ object: "grant_credit_result";
3665
+ new_balance_cents: number;
3666
+ }
3597
3667
 
3598
3668
  /**
3599
3669
  * v2 Base Client — cursor pagination, expand support, caching, typed errors.
@@ -3742,6 +3812,8 @@ declare class OrdersV2Client extends BaseV2Client {
3742
3812
  * dance — v2 is API-key-only and requires no CSRF token.
3743
3813
  */
3744
3814
  create(siteName: string, data: V2OrderCreateParams): Promise<V2OrderCreateResult>;
3815
+ /** Update fulfillment status, tracking number, and/or notes on an order. */
3816
+ updateFulfillment(siteName: string, id: string, data: V2OrderFulfillmentUpdate): Promise<V2Order>;
3745
3817
  }
3746
3818
 
3747
3819
  /**
@@ -3912,6 +3984,54 @@ declare class WebhooksV2Client extends BaseV2Client {
3912
3984
  del(siteName: string, id: string): Promise<V2Deleted>;
3913
3985
  }
3914
3986
 
3987
+ /**
3988
+ * v2 Subscriptions Client — lifecycle operations for site user subscriptions.
3989
+ *
3990
+ * Two classes of endpoints:
3991
+ * - /me paths require a site-user JWT (call `setAuth(jwt)` first)
3992
+ * - Admin paths require an API key (call `setApiKey(key)` first)
3993
+ */
3994
+
3995
+ declare class SubscriptionsV2Client extends BaseV2Client {
3996
+ /** List all subscriptions for the authenticated user. */
3997
+ listMySubscriptions(siteName: string): Promise<V2List<V2SiteUserSubscription>>;
3998
+ /** Pause a subscription. */
3999
+ pauseSubscription(siteName: string, subId: string, params?: V2SubscriptionPauseParams): Promise<V2SiteUserSubscription>;
4000
+ /** Resume a paused subscription. */
4001
+ resumeSubscription(siteName: string, subId: string): Promise<V2SiteUserSubscription>;
4002
+ /** Cancel a subscription. */
4003
+ cancelSubscription(siteName: string, subId: string, params?: V2SubscriptionCancelParams): Promise<V2CancelSubscriptionResult>;
4004
+ /** Change the plan (price) of a subscription. */
4005
+ changeSubscriptionPlan(siteName: string, subId: string, params: V2SubscriptionChangePlanParams): Promise<V2SiteUserSubscription>;
4006
+ /** List subscriptions for a specific user (admin). */
4007
+ listUserSubscriptions(siteName: string, userId: string): Promise<V2List<V2SiteUserSubscription>>;
4008
+ /** Pause a user's subscription (admin). */
4009
+ pauseUserSubscription(siteName: string, userId: string, subId: string, params?: V2SubscriptionPauseParams): Promise<V2SiteUserSubscription>;
4010
+ /** Resume a user's paused subscription (admin). */
4011
+ resumeUserSubscription(siteName: string, userId: string, subId: string): Promise<V2SiteUserSubscription>;
4012
+ /** Cancel a user's subscription (admin). */
4013
+ cancelUserSubscription(siteName: string, userId: string, subId: string, params?: V2SubscriptionCancelParams): Promise<V2CancelSubscriptionResult>;
4014
+ }
4015
+
4016
+ /**
4017
+ * v2 Credits Client — balance queries and admin grant operations.
4018
+ *
4019
+ * Two classes of endpoints:
4020
+ * - /me paths require a site-user JWT (call `setAuth(jwt)` first)
4021
+ * - Admin paths require an API key (call `setApiKey(key)` first)
4022
+ */
4023
+
4024
+ declare class CreditsV2Client extends BaseV2Client {
4025
+ /** Get the current credit balance for the authenticated user. */
4026
+ getMyBalance(siteName: string): Promise<V2CreditBalance>;
4027
+ /** Get credit balance and transaction history for the authenticated user. */
4028
+ getMyCredits(siteName: string): Promise<V2CreditBalance>;
4029
+ /** Get the credit balance for a specific user (admin). */
4030
+ getUserBalance(siteName: string, userId: string): Promise<V2CreditBalance>;
4031
+ /** Grant credit to a specific user (admin). */
4032
+ grantCredit(siteName: string, userId: string, data: V2GrantCreditParams): Promise<V2GrantCreditResult>;
4033
+ }
4034
+
3915
4035
  /**
3916
4036
  * PerspectAPI v2 SDK Client
3917
4037
  *
@@ -3942,6 +4062,8 @@ declare class PerspectApiV2Client {
3942
4062
  readonly sites: SitesV2Client;
3943
4063
  readonly apiKeys: ApiKeysV2Client;
3944
4064
  readonly webhooks: WebhooksV2Client;
4065
+ readonly subscriptions: SubscriptionsV2Client;
4066
+ readonly credits: CreditsV2Client;
3945
4067
  constructor(config: PerspectApiV2Config);
3946
4068
  /** Update the JWT token for authenticated requests. */
3947
4069
  setAuth(jwt: string): void;
@@ -3988,21 +4110,6 @@ declare class CloudflareKVCacheAdapter implements CacheAdapter {
3988
4110
  clear(): Promise<void>;
3989
4111
  }
3990
4112
 
3991
- /**
3992
- * Simple in-memory cache adapter primarily suited for development and testing.
3993
- */
3994
-
3995
- declare class InMemoryCacheAdapter implements CacheAdapter {
3996
- private store;
3997
- get(key: string): Promise<string | undefined>;
3998
- set(key: string, value: string, options?: {
3999
- ttlSeconds?: number;
4000
- }): Promise<void>;
4001
- delete(key: string): Promise<void>;
4002
- deleteMany(keys: string[]): Promise<void>;
4003
- clear(): Promise<void>;
4004
- }
4005
-
4006
4113
  /**
4007
4114
  * No-op cache adapter that disables caching while preserving the cache contract.
4008
4115
  */
@@ -4308,4 +4415,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
4308
4415
  error: string;
4309
4416
  }>;
4310
4417
 
4311
- export { type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheConfig, CacheManager, type CancelSubscriptionRequest, type CancelSubscriptionResponse, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, CloudflareKVCacheAdapter, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateBundleCollectionRequest, type CreateBundleGroupRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateProductSkuRequest, type CreateSiteRequest, type CreateWebhookRequest, type CreditBalance, type CreditBalanceWithTransactions, type CreditTransaction, DEFAULT_IMAGE_SIZES, type GrantCreditRequest, HttpClient, type HttpMethod, type ImageTransformOptions, InMemoryCacheAdapter, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type NewsletterCampaignDetail, type NewsletterCampaignListResponse, type NewsletterCampaignSummary, type NewsletterCampaignTestSendRequest, type NewsletterCampaignTestSendResponse, NewsletterClient, type NewsletterConfirmResponse, type NewsletterExportCreateRequest, type NewsletterExportCreateResponse, type NewsletterList, type NewsletterManagementCampaign, type NewsletterManagementCampaignListResponse, NewsletterManagementClient, type NewsletterManagementList, type NewsletterManagementListMembership, type NewsletterManagementPagination, type NewsletterManagementSeries, type NewsletterManagementStatsResponse, type NewsletterManagementSubscription, type NewsletterManagementSubscriptionsListResponse, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterSubscriptionImportRowRequest, type NewsletterSubscriptionMembershipUpdateRequest, type NewsletterSubscriptionSyncRequest, type NewsletterSubscriptionSyncResponse, type NewsletterSubscriptionsBulkAction, type NewsletterSubscriptionsBulkOutcome, type NewsletterSubscriptionsBulkUpdateRequest, type NewsletterSubscriptionsBulkUpdateResponse, type NewsletterSubscriptionsImportRequest, type NewsletterSubscriptionsImportResponse, type NewsletterSubscriptionsImportRowResult, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, PerspectApiV2Client, PerspectV2Error, type Product, type ProductBundleGroup, type ProductQueryParams, type ProductSku, type ProductSkuMediaItem, type ProductSkuOption, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type SubscriptionCancellationMode, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type V2ApiKey, type V2Category, type V2CategoryCreateParams, type V2CategoryUpdateParams, type V2Collection, type V2CollectionCreateParams, type V2CollectionItem, type V2CollectionUpdateParams, type V2ContactSubmission, type V2Content, type V2ContentCreateParams, type V2ContentListParams, type V2ContentUpdateParams, type V2Deleted, type V2Error, type V2ErrorType, type V2List, type V2Media, type V2NewsletterCampaign, type V2NewsletterImportRequest, type V2NewsletterImportResult, type V2NewsletterList, type V2NewsletterListCreateParams, type V2NewsletterListUpdateParams, type V2NewsletterSubscription, type V2NewsletterSubscriptionListMembershipUpdate, type V2NewsletterSyncInput, type V2NewsletterSyncResult, type V2NewsletterTrackingResponse, type V2Object, type V2Order, type V2OrderAddress, type V2OrderCreateParams, type V2OrderCreateResult, type V2OrderLineItem, type V2OrderLineItemPriceData, type V2OrderListParams, type V2OrderTaxRequest, type V2Organization, type V2PaginationParams, type V2Product, type V2ProductCreateParams, type V2ProductListParams, type V2ProductUpdateParams, type V2Site, type V2SiteUser, type V2SiteUserListParams, type V2SiteUserMeUpdateParams, type V2SiteUserProfile, type V2SiteUserUpdateParams, type V2SiteUserWithProfile, type V2Webhook, type V2WebhookCreateParams, type V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
4418
+ export { type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheConfig, CacheManager, type CancelSubscriptionRequest, type CancelSubscriptionResponse, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, CloudflareKVCacheAdapter, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateBundleCollectionRequest, type CreateBundleGroupRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateProductSkuRequest, type CreateSiteRequest, type CreateWebhookRequest, type CreditBalance, type CreditBalanceWithTransactions, type CreditTransaction, DEFAULT_IMAGE_SIZES, type GrantCreditRequest, HttpClient, type HttpMethod, type ImageTransformOptions, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type NewsletterCampaignDetail, type NewsletterCampaignListResponse, type NewsletterCampaignSummary, type NewsletterCampaignTestSendRequest, type NewsletterCampaignTestSendResponse, NewsletterClient, type NewsletterConfirmResponse, type NewsletterExportCreateRequest, type NewsletterExportCreateResponse, type NewsletterList, type NewsletterManagementCampaign, type NewsletterManagementCampaignListResponse, NewsletterManagementClient, type NewsletterManagementList, type NewsletterManagementListMembership, type NewsletterManagementPagination, type NewsletterManagementSeries, type NewsletterManagementStatsResponse, type NewsletterManagementSubscription, type NewsletterManagementSubscriptionsListResponse, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterSubscriptionImportRowRequest, type NewsletterSubscriptionMembershipUpdateRequest, type NewsletterSubscriptionSyncRequest, type NewsletterSubscriptionSyncResponse, type NewsletterSubscriptionsBulkAction, type NewsletterSubscriptionsBulkOutcome, type NewsletterSubscriptionsBulkUpdateRequest, type NewsletterSubscriptionsBulkUpdateResponse, type NewsletterSubscriptionsImportRequest, type NewsletterSubscriptionsImportResponse, type NewsletterSubscriptionsImportRowResult, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, PerspectApiV2Client, PerspectV2Error, type Product, type ProductBundleGroup, type ProductQueryParams, type ProductSku, type ProductSkuMediaItem, type ProductSkuOption, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type SubscriptionCancellationMode, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type V2ApiKey, type V2CancelSubscriptionResult, type V2Category, type V2CategoryCreateParams, type V2CategoryUpdateParams, type V2Collection, type V2CollectionCreateParams, type V2CollectionItem, type V2CollectionUpdateParams, type V2ContactSubmission, type V2Content, type V2ContentCreateParams, type V2ContentListParams, type V2ContentUpdateParams, type V2CreditBalance, type V2CreditTransaction, type V2Deleted, type V2Error, type V2ErrorType, type V2GrantCreditParams, type V2GrantCreditResult, type V2List, type V2Media, type V2NewsletterCampaign, type V2NewsletterImportRequest, type V2NewsletterImportResult, type V2NewsletterList, type V2NewsletterListCreateParams, type V2NewsletterListUpdateParams, type V2NewsletterSubscription, type V2NewsletterSubscriptionListMembershipUpdate, type V2NewsletterSyncInput, type V2NewsletterSyncResult, type V2NewsletterTrackingResponse, type V2Object, type V2Order, type V2OrderAddress, type V2OrderCreateParams, type V2OrderCreateResult, type V2OrderFulfillmentUpdate, type V2OrderLineItem, type V2OrderLineItemPriceData, type V2OrderListParams, type V2OrderTaxRequest, type V2Organization, type V2PaginationParams, type V2Product, type V2ProductCreateParams, type V2ProductListParams, type V2ProductUpdateParams, type V2Site, type V2SiteUser, type V2SiteUserListParams, type V2SiteUserMeUpdateParams, type V2SiteUserProfile, type V2SiteUserSubscription, type V2SiteUserUpdateParams, type V2SiteUserWithProfile, type V2SubscriptionCancelParams, type V2SubscriptionChangePlanParams, type V2SubscriptionPauseParams, type V2Webhook, type V2WebhookCreateParams, type V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
package/dist/index.js CHANGED
@@ -32,7 +32,6 @@ __export(index_exports, {
32
32
  ContentClient: () => ContentClient,
33
33
  DEFAULT_IMAGE_SIZES: () => DEFAULT_IMAGE_SIZES,
34
34
  HttpClient: () => HttpClient,
35
- InMemoryCacheAdapter: () => InMemoryCacheAdapter,
36
35
  NewsletterClient: () => NewsletterClient,
37
36
  NewsletterManagementClient: () => NewsletterManagementClient,
38
37
  NoopCacheAdapter: () => NoopCacheAdapter,
@@ -310,35 +309,6 @@ function createApiError(error) {
310
309
  };
311
310
  }
312
311
 
313
- // src/cache/in-memory-adapter.ts
314
- var InMemoryCacheAdapter = class {
315
- store = /* @__PURE__ */ new Map();
316
- async get(key) {
317
- const entry = this.store.get(key);
318
- if (!entry) {
319
- return void 0;
320
- }
321
- if (entry.expiresAt && entry.expiresAt <= Date.now()) {
322
- this.store.delete(key);
323
- return void 0;
324
- }
325
- return entry.value;
326
- }
327
- async set(key, value, options) {
328
- const expiresAt = options?.ttlSeconds && options.ttlSeconds > 0 ? Date.now() + options.ttlSeconds * 1e3 : void 0;
329
- this.store.set(key, { value, expiresAt });
330
- }
331
- async delete(key) {
332
- this.store.delete(key);
333
- }
334
- async deleteMany(keys) {
335
- keys.forEach((key) => this.store.delete(key));
336
- }
337
- async clear() {
338
- this.store.clear();
339
- }
340
- };
341
-
342
312
  // src/cache/noop-adapter.ts
343
313
  var NoopCacheAdapter = class {
344
314
  async get() {
@@ -370,15 +340,9 @@ var CacheManager = class {
370
340
  ...defaultOptions,
371
341
  ...config
372
342
  };
373
- if (config && config.enabled === false) {
374
- this.enabled = false;
375
- this.adapter = new NoopCacheAdapter();
376
- } else if (config && config.adapter) {
343
+ if (config && config.enabled !== false && config.adapter) {
377
344
  this.enabled = true;
378
345
  this.adapter = config.adapter;
379
- } else if (config) {
380
- this.enabled = true;
381
- this.adapter = new InMemoryCacheAdapter();
382
346
  } else {
383
347
  this.enabled = false;
384
348
  this.adapter = new NoopCacheAdapter();
@@ -3712,6 +3676,13 @@ var OrdersV2Client = class extends BaseV2Client {
3712
3676
  data
3713
3677
  );
3714
3678
  }
3679
+ /** Update fulfillment status, tracking number, and/or notes on an order. */
3680
+ async updateFulfillment(siteName, id, data) {
3681
+ return this.patchOne(
3682
+ this.sitePath(siteName, "orders", `${id}/fulfillment`),
3683
+ data
3684
+ );
3685
+ }
3715
3686
  };
3716
3687
 
3717
3688
  // src/v2/client/site-users-client.ts
@@ -3971,6 +3942,102 @@ var WebhooksV2Client = class extends BaseV2Client {
3971
3942
  }
3972
3943
  };
3973
3944
 
3945
+ // src/v2/client/subscriptions-client.ts
3946
+ var SubscriptionsV2Client = class extends BaseV2Client {
3947
+ // --- Authenticated "me" endpoints (site-user JWT) ---
3948
+ /** List all subscriptions for the authenticated user. */
3949
+ async listMySubscriptions(siteName) {
3950
+ return this.getList(
3951
+ this.sitePath(siteName, "users", "me/subscriptions")
3952
+ );
3953
+ }
3954
+ /** Pause a subscription. */
3955
+ async pauseSubscription(siteName, subId, params) {
3956
+ return this.post(
3957
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/pause`),
3958
+ params ?? {}
3959
+ );
3960
+ }
3961
+ /** Resume a paused subscription. */
3962
+ async resumeSubscription(siteName, subId) {
3963
+ return this.post(
3964
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/resume`)
3965
+ );
3966
+ }
3967
+ /** Cancel a subscription. */
3968
+ async cancelSubscription(siteName, subId, params) {
3969
+ return this.post(
3970
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/cancel`),
3971
+ params ?? {}
3972
+ );
3973
+ }
3974
+ /** Change the plan (price) of a subscription. */
3975
+ async changeSubscriptionPlan(siteName, subId, params) {
3976
+ return this.post(
3977
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/change-plan`),
3978
+ params
3979
+ );
3980
+ }
3981
+ // --- Admin endpoints (API key) ---
3982
+ /** List subscriptions for a specific user (admin). */
3983
+ async listUserSubscriptions(siteName, userId) {
3984
+ return this.getList(
3985
+ this.sitePath(siteName, "users", `${userId}/subscriptions`)
3986
+ );
3987
+ }
3988
+ /** Pause a user's subscription (admin). */
3989
+ async pauseUserSubscription(siteName, userId, subId, params) {
3990
+ return this.post(
3991
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/pause`),
3992
+ params ?? {}
3993
+ );
3994
+ }
3995
+ /** Resume a user's paused subscription (admin). */
3996
+ async resumeUserSubscription(siteName, userId, subId) {
3997
+ return this.post(
3998
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/resume`)
3999
+ );
4000
+ }
4001
+ /** Cancel a user's subscription (admin). */
4002
+ async cancelUserSubscription(siteName, userId, subId, params) {
4003
+ return this.post(
4004
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/cancel`),
4005
+ params ?? {}
4006
+ );
4007
+ }
4008
+ };
4009
+
4010
+ // src/v2/client/credits-client.ts
4011
+ var CreditsV2Client = class extends BaseV2Client {
4012
+ // --- Authenticated "me" endpoints (site-user JWT) ---
4013
+ /** Get the current credit balance for the authenticated user. */
4014
+ async getMyBalance(siteName) {
4015
+ return this.getOne(
4016
+ this.sitePath(siteName, "users", "me/credits/balance")
4017
+ );
4018
+ }
4019
+ /** Get credit balance and transaction history for the authenticated user. */
4020
+ async getMyCredits(siteName) {
4021
+ return this.getOne(
4022
+ this.sitePath(siteName, "users", "me/credits")
4023
+ );
4024
+ }
4025
+ // --- Admin endpoints (API key) ---
4026
+ /** Get the credit balance for a specific user (admin). */
4027
+ async getUserBalance(siteName, userId) {
4028
+ return this.getOne(
4029
+ this.sitePath(siteName, "users", `${userId}/credits/balance`)
4030
+ );
4031
+ }
4032
+ /** Grant credit to a specific user (admin). */
4033
+ async grantCredit(siteName, userId, data) {
4034
+ return this.post(
4035
+ this.sitePath(siteName, "users", `${userId}/credits/grant`),
4036
+ data
4037
+ );
4038
+ }
4039
+ };
4040
+
3974
4041
  // src/v2/index.ts
3975
4042
  var PerspectApiV2Client = class {
3976
4043
  http;
@@ -3987,6 +4054,8 @@ var PerspectApiV2Client = class {
3987
4054
  sites;
3988
4055
  apiKeys;
3989
4056
  webhooks;
4057
+ subscriptions;
4058
+ credits;
3990
4059
  constructor(config) {
3991
4060
  const baseUrl = config.baseUrl.replace(/\/+$/, "");
3992
4061
  const v2BaseUrl = baseUrl.endsWith("/api/v2") ? baseUrl : `${baseUrl}/api/v2`;
@@ -4006,6 +4075,8 @@ var PerspectApiV2Client = class {
4006
4075
  this.sites = new SitesV2Client(this.http, basePath, cache);
4007
4076
  this.apiKeys = new ApiKeysV2Client(this.http, basePath, cache);
4008
4077
  this.webhooks = new WebhooksV2Client(this.http, basePath, cache);
4078
+ this.subscriptions = new SubscriptionsV2Client(this.http, basePath, cache);
4079
+ this.credits = new CreditsV2Client(this.http, basePath, cache);
4009
4080
  }
4010
4081
  /** Update the JWT token for authenticated requests. */
4011
4082
  setAuth(jwt) {
@@ -4674,7 +4745,6 @@ async function createCheckoutSession(options) {
4674
4745
  ContentClient,
4675
4746
  DEFAULT_IMAGE_SIZES,
4676
4747
  HttpClient,
4677
- InMemoryCacheAdapter,
4678
4748
  NewsletterClient,
4679
4749
  NewsletterManagementClient,
4680
4750
  NoopCacheAdapter,
package/dist/index.mjs CHANGED
@@ -242,35 +242,6 @@ function createApiError(error) {
242
242
  };
243
243
  }
244
244
 
245
- // src/cache/in-memory-adapter.ts
246
- var InMemoryCacheAdapter = class {
247
- store = /* @__PURE__ */ new Map();
248
- async get(key) {
249
- const entry = this.store.get(key);
250
- if (!entry) {
251
- return void 0;
252
- }
253
- if (entry.expiresAt && entry.expiresAt <= Date.now()) {
254
- this.store.delete(key);
255
- return void 0;
256
- }
257
- return entry.value;
258
- }
259
- async set(key, value, options) {
260
- const expiresAt = options?.ttlSeconds && options.ttlSeconds > 0 ? Date.now() + options.ttlSeconds * 1e3 : void 0;
261
- this.store.set(key, { value, expiresAt });
262
- }
263
- async delete(key) {
264
- this.store.delete(key);
265
- }
266
- async deleteMany(keys) {
267
- keys.forEach((key) => this.store.delete(key));
268
- }
269
- async clear() {
270
- this.store.clear();
271
- }
272
- };
273
-
274
245
  // src/cache/noop-adapter.ts
275
246
  var NoopCacheAdapter = class {
276
247
  async get() {
@@ -302,15 +273,9 @@ var CacheManager = class {
302
273
  ...defaultOptions,
303
274
  ...config
304
275
  };
305
- if (config && config.enabled === false) {
306
- this.enabled = false;
307
- this.adapter = new NoopCacheAdapter();
308
- } else if (config && config.adapter) {
276
+ if (config && config.enabled !== false && config.adapter) {
309
277
  this.enabled = true;
310
278
  this.adapter = config.adapter;
311
- } else if (config) {
312
- this.enabled = true;
313
- this.adapter = new InMemoryCacheAdapter();
314
279
  } else {
315
280
  this.enabled = false;
316
281
  this.adapter = new NoopCacheAdapter();
@@ -3644,6 +3609,13 @@ var OrdersV2Client = class extends BaseV2Client {
3644
3609
  data
3645
3610
  );
3646
3611
  }
3612
+ /** Update fulfillment status, tracking number, and/or notes on an order. */
3613
+ async updateFulfillment(siteName, id, data) {
3614
+ return this.patchOne(
3615
+ this.sitePath(siteName, "orders", `${id}/fulfillment`),
3616
+ data
3617
+ );
3618
+ }
3647
3619
  };
3648
3620
 
3649
3621
  // src/v2/client/site-users-client.ts
@@ -3903,6 +3875,102 @@ var WebhooksV2Client = class extends BaseV2Client {
3903
3875
  }
3904
3876
  };
3905
3877
 
3878
+ // src/v2/client/subscriptions-client.ts
3879
+ var SubscriptionsV2Client = class extends BaseV2Client {
3880
+ // --- Authenticated "me" endpoints (site-user JWT) ---
3881
+ /** List all subscriptions for the authenticated user. */
3882
+ async listMySubscriptions(siteName) {
3883
+ return this.getList(
3884
+ this.sitePath(siteName, "users", "me/subscriptions")
3885
+ );
3886
+ }
3887
+ /** Pause a subscription. */
3888
+ async pauseSubscription(siteName, subId, params) {
3889
+ return this.post(
3890
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/pause`),
3891
+ params ?? {}
3892
+ );
3893
+ }
3894
+ /** Resume a paused subscription. */
3895
+ async resumeSubscription(siteName, subId) {
3896
+ return this.post(
3897
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/resume`)
3898
+ );
3899
+ }
3900
+ /** Cancel a subscription. */
3901
+ async cancelSubscription(siteName, subId, params) {
3902
+ return this.post(
3903
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/cancel`),
3904
+ params ?? {}
3905
+ );
3906
+ }
3907
+ /** Change the plan (price) of a subscription. */
3908
+ async changeSubscriptionPlan(siteName, subId, params) {
3909
+ return this.post(
3910
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/change-plan`),
3911
+ params
3912
+ );
3913
+ }
3914
+ // --- Admin endpoints (API key) ---
3915
+ /** List subscriptions for a specific user (admin). */
3916
+ async listUserSubscriptions(siteName, userId) {
3917
+ return this.getList(
3918
+ this.sitePath(siteName, "users", `${userId}/subscriptions`)
3919
+ );
3920
+ }
3921
+ /** Pause a user's subscription (admin). */
3922
+ async pauseUserSubscription(siteName, userId, subId, params) {
3923
+ return this.post(
3924
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/pause`),
3925
+ params ?? {}
3926
+ );
3927
+ }
3928
+ /** Resume a user's paused subscription (admin). */
3929
+ async resumeUserSubscription(siteName, userId, subId) {
3930
+ return this.post(
3931
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/resume`)
3932
+ );
3933
+ }
3934
+ /** Cancel a user's subscription (admin). */
3935
+ async cancelUserSubscription(siteName, userId, subId, params) {
3936
+ return this.post(
3937
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/cancel`),
3938
+ params ?? {}
3939
+ );
3940
+ }
3941
+ };
3942
+
3943
+ // src/v2/client/credits-client.ts
3944
+ var CreditsV2Client = class extends BaseV2Client {
3945
+ // --- Authenticated "me" endpoints (site-user JWT) ---
3946
+ /** Get the current credit balance for the authenticated user. */
3947
+ async getMyBalance(siteName) {
3948
+ return this.getOne(
3949
+ this.sitePath(siteName, "users", "me/credits/balance")
3950
+ );
3951
+ }
3952
+ /** Get credit balance and transaction history for the authenticated user. */
3953
+ async getMyCredits(siteName) {
3954
+ return this.getOne(
3955
+ this.sitePath(siteName, "users", "me/credits")
3956
+ );
3957
+ }
3958
+ // --- Admin endpoints (API key) ---
3959
+ /** Get the credit balance for a specific user (admin). */
3960
+ async getUserBalance(siteName, userId) {
3961
+ return this.getOne(
3962
+ this.sitePath(siteName, "users", `${userId}/credits/balance`)
3963
+ );
3964
+ }
3965
+ /** Grant credit to a specific user (admin). */
3966
+ async grantCredit(siteName, userId, data) {
3967
+ return this.post(
3968
+ this.sitePath(siteName, "users", `${userId}/credits/grant`),
3969
+ data
3970
+ );
3971
+ }
3972
+ };
3973
+
3906
3974
  // src/v2/index.ts
3907
3975
  var PerspectApiV2Client = class {
3908
3976
  http;
@@ -3919,6 +3987,8 @@ var PerspectApiV2Client = class {
3919
3987
  sites;
3920
3988
  apiKeys;
3921
3989
  webhooks;
3990
+ subscriptions;
3991
+ credits;
3922
3992
  constructor(config) {
3923
3993
  const baseUrl = config.baseUrl.replace(/\/+$/, "");
3924
3994
  const v2BaseUrl = baseUrl.endsWith("/api/v2") ? baseUrl : `${baseUrl}/api/v2`;
@@ -3938,6 +4008,8 @@ var PerspectApiV2Client = class {
3938
4008
  this.sites = new SitesV2Client(this.http, basePath, cache);
3939
4009
  this.apiKeys = new ApiKeysV2Client(this.http, basePath, cache);
3940
4010
  this.webhooks = new WebhooksV2Client(this.http, basePath, cache);
4011
+ this.subscriptions = new SubscriptionsV2Client(this.http, basePath, cache);
4012
+ this.credits = new CreditsV2Client(this.http, basePath, cache);
3941
4013
  }
3942
4014
  /** Update the JWT token for authenticated requests. */
3943
4015
  setAuth(jwt) {
@@ -4605,7 +4677,6 @@ export {
4605
4677
  ContentClient,
4606
4678
  DEFAULT_IMAGE_SIZES,
4607
4679
  HttpClient,
4608
- InMemoryCacheAdapter,
4609
4680
  NewsletterClient,
4610
4681
  NewsletterManagementClient,
4611
4682
  NoopCacheAdapter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perspectapi-ts-sdk",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
4
4
  "description": "TypeScript SDK for PerspectAPI - Cloudflare Workers compatible",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -2,7 +2,6 @@
2
2
  * CacheManager orchestrates cache get/set/invalidate behaviour using a pluggable adapter.
3
3
  */
4
4
 
5
- import { InMemoryCacheAdapter } from './in-memory-adapter';
6
5
  import { NoopCacheAdapter } from './noop-adapter';
7
6
  import type {
8
7
  CacheAdapter,
@@ -34,17 +33,11 @@ export class CacheManager {
34
33
  ...config,
35
34
  };
36
35
 
37
- if (config && config.enabled === false) {
38
- this.enabled = false;
39
- this.adapter = new NoopCacheAdapter();
40
- } else if (config && config.adapter) {
36
+ if (config && config.enabled !== false && config.adapter) {
41
37
  this.enabled = true;
42
38
  this.adapter = config.adapter;
43
- } else if (config) {
44
- // Cache config supplied but no adapter; fall back to in-memory caching.
45
- this.enabled = true;
46
- this.adapter = new InMemoryCacheAdapter();
47
39
  } else {
40
+ // No adapter provided — caching is disabled.
48
41
  this.enabled = false;
49
42
  this.adapter = new NoopCacheAdapter();
50
43
  }
package/src/index.ts CHANGED
@@ -37,7 +37,7 @@ export { HttpClient, createApiError } from './utils/http-client';
37
37
  // Cache utilities
38
38
  export { CacheManager } from './cache/cache-manager';
39
39
  export { CloudflareKVCacheAdapter } from './cache/cloudflare-kv-adapter';
40
- export { InMemoryCacheAdapter } from './cache/in-memory-adapter';
40
+ // InMemoryCacheAdapter removed useless in Cloudflare Workers (per-request memory, no persistence)
41
41
  export { NoopCacheAdapter } from './cache/noop-adapter';
42
42
 
43
43
  // Image transformation utilities
@@ -0,0 +1,57 @@
1
+ /**
2
+ * v2 Credits Client — balance queries and admin grant operations.
3
+ *
4
+ * Two classes of endpoints:
5
+ * - /me paths require a site-user JWT (call `setAuth(jwt)` first)
6
+ * - Admin paths require an API key (call `setApiKey(key)` first)
7
+ */
8
+
9
+ import { BaseV2Client } from './base-v2-client';
10
+ import type {
11
+ V2CreditBalance,
12
+ V2GrantCreditParams,
13
+ V2GrantCreditResult,
14
+ } from '../types';
15
+
16
+ export class CreditsV2Client extends BaseV2Client {
17
+
18
+ // --- Authenticated "me" endpoints (site-user JWT) ---
19
+
20
+ /** Get the current credit balance for the authenticated user. */
21
+ async getMyBalance(siteName: string): Promise<V2CreditBalance> {
22
+ return this.getOne<V2CreditBalance>(
23
+ this.sitePath(siteName, 'users', 'me/credits/balance'),
24
+ );
25
+ }
26
+
27
+ /** Get credit balance and transaction history for the authenticated user. */
28
+ async getMyCredits(siteName: string): Promise<V2CreditBalance> {
29
+ return this.getOne<V2CreditBalance>(
30
+ this.sitePath(siteName, 'users', 'me/credits'),
31
+ );
32
+ }
33
+
34
+ // --- Admin endpoints (API key) ---
35
+
36
+ /** Get the credit balance for a specific user (admin). */
37
+ async getUserBalance(
38
+ siteName: string,
39
+ userId: string,
40
+ ): Promise<V2CreditBalance> {
41
+ return this.getOne<V2CreditBalance>(
42
+ this.sitePath(siteName, 'users', `${userId}/credits/balance`),
43
+ );
44
+ }
45
+
46
+ /** Grant credit to a specific user (admin). */
47
+ async grantCredit(
48
+ siteName: string,
49
+ userId: string,
50
+ data: V2GrantCreditParams,
51
+ ): Promise<V2GrantCreditResult> {
52
+ return this.post<V2GrantCreditResult>(
53
+ this.sitePath(siteName, 'users', `${userId}/credits/grant`),
54
+ data,
55
+ );
56
+ }
57
+ }
@@ -12,6 +12,7 @@ import type {
12
12
  V2OrderListParams,
13
13
  V2OrderCreateParams,
14
14
  V2OrderCreateResult,
15
+ V2OrderFulfillmentUpdate,
15
16
  V2List,
16
17
  } from '../types';
17
18
 
@@ -45,4 +46,16 @@ export class OrdersV2Client extends BaseV2Client {
45
46
  data,
46
47
  );
47
48
  }
49
+
50
+ /** Update fulfillment status, tracking number, and/or notes on an order. */
51
+ async updateFulfillment(
52
+ siteName: string,
53
+ id: string,
54
+ data: V2OrderFulfillmentUpdate,
55
+ ): Promise<V2Order> {
56
+ return this.patchOne<V2Order>(
57
+ this.sitePath(siteName, 'orders', `${id}/fulfillment`),
58
+ data,
59
+ );
60
+ }
48
61
  }
@@ -0,0 +1,126 @@
1
+ /**
2
+ * v2 Subscriptions Client — lifecycle operations for site user subscriptions.
3
+ *
4
+ * Two classes of endpoints:
5
+ * - /me paths require a site-user JWT (call `setAuth(jwt)` first)
6
+ * - Admin paths require an API key (call `setApiKey(key)` first)
7
+ */
8
+
9
+ import { BaseV2Client } from './base-v2-client';
10
+ import type {
11
+ V2SiteUserSubscription,
12
+ V2SubscriptionPauseParams,
13
+ V2SubscriptionCancelParams,
14
+ V2SubscriptionChangePlanParams,
15
+ V2CancelSubscriptionResult,
16
+ V2List,
17
+ } from '../types';
18
+
19
+ export class SubscriptionsV2Client extends BaseV2Client {
20
+
21
+ // --- Authenticated "me" endpoints (site-user JWT) ---
22
+
23
+ /** List all subscriptions for the authenticated user. */
24
+ async listMySubscriptions(
25
+ siteName: string,
26
+ ): Promise<V2List<V2SiteUserSubscription>> {
27
+ return this.getList<V2SiteUserSubscription>(
28
+ this.sitePath(siteName, 'users', 'me/subscriptions'),
29
+ );
30
+ }
31
+
32
+ /** Pause a subscription. */
33
+ async pauseSubscription(
34
+ siteName: string,
35
+ subId: string,
36
+ params?: V2SubscriptionPauseParams,
37
+ ): Promise<V2SiteUserSubscription> {
38
+ return this.post<V2SiteUserSubscription>(
39
+ this.sitePath(siteName, 'users', `me/subscriptions/${subId}/pause`),
40
+ params ?? {},
41
+ );
42
+ }
43
+
44
+ /** Resume a paused subscription. */
45
+ async resumeSubscription(
46
+ siteName: string,
47
+ subId: string,
48
+ ): Promise<V2SiteUserSubscription> {
49
+ return this.post<V2SiteUserSubscription>(
50
+ this.sitePath(siteName, 'users', `me/subscriptions/${subId}/resume`),
51
+ );
52
+ }
53
+
54
+ /** Cancel a subscription. */
55
+ async cancelSubscription(
56
+ siteName: string,
57
+ subId: string,
58
+ params?: V2SubscriptionCancelParams,
59
+ ): Promise<V2CancelSubscriptionResult> {
60
+ return this.post<V2CancelSubscriptionResult>(
61
+ this.sitePath(siteName, 'users', `me/subscriptions/${subId}/cancel`),
62
+ params ?? {},
63
+ );
64
+ }
65
+
66
+ /** Change the plan (price) of a subscription. */
67
+ async changeSubscriptionPlan(
68
+ siteName: string,
69
+ subId: string,
70
+ params: V2SubscriptionChangePlanParams,
71
+ ): Promise<V2SiteUserSubscription> {
72
+ return this.post<V2SiteUserSubscription>(
73
+ this.sitePath(siteName, 'users', `me/subscriptions/${subId}/change-plan`),
74
+ params,
75
+ );
76
+ }
77
+
78
+ // --- Admin endpoints (API key) ---
79
+
80
+ /** List subscriptions for a specific user (admin). */
81
+ async listUserSubscriptions(
82
+ siteName: string,
83
+ userId: string,
84
+ ): Promise<V2List<V2SiteUserSubscription>> {
85
+ return this.getList<V2SiteUserSubscription>(
86
+ this.sitePath(siteName, 'users', `${userId}/subscriptions`),
87
+ );
88
+ }
89
+
90
+ /** Pause a user's subscription (admin). */
91
+ async pauseUserSubscription(
92
+ siteName: string,
93
+ userId: string,
94
+ subId: string,
95
+ params?: V2SubscriptionPauseParams,
96
+ ): Promise<V2SiteUserSubscription> {
97
+ return this.post<V2SiteUserSubscription>(
98
+ this.sitePath(siteName, 'users', `${userId}/subscriptions/${subId}/pause`),
99
+ params ?? {},
100
+ );
101
+ }
102
+
103
+ /** Resume a user's paused subscription (admin). */
104
+ async resumeUserSubscription(
105
+ siteName: string,
106
+ userId: string,
107
+ subId: string,
108
+ ): Promise<V2SiteUserSubscription> {
109
+ return this.post<V2SiteUserSubscription>(
110
+ this.sitePath(siteName, 'users', `${userId}/subscriptions/${subId}/resume`),
111
+ );
112
+ }
113
+
114
+ /** Cancel a user's subscription (admin). */
115
+ async cancelUserSubscription(
116
+ siteName: string,
117
+ userId: string,
118
+ subId: string,
119
+ params?: V2SubscriptionCancelParams,
120
+ ): Promise<V2CancelSubscriptionResult> {
121
+ return this.post<V2CancelSubscriptionResult>(
122
+ this.sitePath(siteName, 'users', `${userId}/subscriptions/${subId}/cancel`),
123
+ params ?? {},
124
+ );
125
+ }
126
+ }
package/src/v2/index.ts CHANGED
@@ -27,6 +27,8 @@ import { OrganizationsV2Client } from './client/organizations-client';
27
27
  import { SitesV2Client } from './client/sites-client';
28
28
  import { ApiKeysV2Client } from './client/api-keys-client';
29
29
  import { WebhooksV2Client } from './client/webhooks-client';
30
+ import { SubscriptionsV2Client } from './client/subscriptions-client';
31
+ import { CreditsV2Client } from './client/credits-client';
30
32
 
31
33
  export interface PerspectApiV2Config extends PerspectApiConfig {
32
34
  cache?: CacheConfig;
@@ -48,6 +50,8 @@ export class PerspectApiV2Client {
48
50
  readonly sites: SitesV2Client;
49
51
  readonly apiKeys: ApiKeysV2Client;
50
52
  readonly webhooks: WebhooksV2Client;
53
+ readonly subscriptions: SubscriptionsV2Client;
54
+ readonly credits: CreditsV2Client;
51
55
 
52
56
  constructor(config: PerspectApiV2Config) {
53
57
  // Ensure base URL points to /api/v2
@@ -73,6 +77,8 @@ export class PerspectApiV2Client {
73
77
  this.sites = new SitesV2Client(this.http, basePath, cache);
74
78
  this.apiKeys = new ApiKeysV2Client(this.http, basePath, cache);
75
79
  this.webhooks = new WebhooksV2Client(this.http, basePath, cache);
80
+ this.subscriptions = new SubscriptionsV2Client(this.http, basePath, cache);
81
+ this.credits = new CreditsV2Client(this.http, basePath, cache);
76
82
  }
77
83
 
78
84
  /** Update the JWT token for authenticated requests. */
@@ -112,3 +118,5 @@ export { OrganizationsV2Client } from './client/organizations-client';
112
118
  export { SitesV2Client } from './client/sites-client';
113
119
  export { ApiKeysV2Client } from './client/api-keys-client';
114
120
  export { WebhooksV2Client } from './client/webhooks-client';
121
+ export { SubscriptionsV2Client } from './client/subscriptions-client';
122
+ export { CreditsV2Client } from './client/credits-client';
package/src/v2/types.ts CHANGED
@@ -314,6 +314,12 @@ export interface V2OrderCreateParams {
314
314
  referrer_site_user_id?: string;
315
315
  }
316
316
 
317
+ export interface V2OrderFulfillmentUpdate {
318
+ fulfillment_status: string;
319
+ tracking_number?: string;
320
+ notes?: string;
321
+ }
322
+
317
323
  export interface V2OrderCreateResult extends V2Object {
318
324
  object: "checkout_session";
319
325
  checkout_url: string | null;
@@ -606,3 +612,81 @@ export interface V2WebhookCreateParams {
606
612
  }
607
613
 
608
614
  export interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {}
615
+
616
+ // --- Site User Subscriptions ---
617
+
618
+ export interface V2SiteUserSubscription extends V2Object {
619
+ object: "site_user_subscription";
620
+ site_user_id: string;
621
+ provider: string | null;
622
+ provider_subscription_id: string | null;
623
+ plan_name: string | null;
624
+ plan_id: string | null;
625
+ status: string;
626
+ amount: number | null;
627
+ currency: string | null;
628
+ billing_interval: string | null;
629
+ billing_interval_count: number | null;
630
+ current_period_start: string | null;
631
+ current_period_end: string | null;
632
+ trial_start: string | null;
633
+ trial_end: string | null;
634
+ canceled_at: string | null;
635
+ cancel_at_period_end: boolean;
636
+ metadata: Record<string, unknown> | null;
637
+ created_at: string | null;
638
+ updated_at: string | null;
639
+ }
640
+
641
+ export interface V2SubscriptionPauseParams {
642
+ resumes_at?: number;
643
+ }
644
+
645
+ export interface V2SubscriptionCancelParams {
646
+ mode?: "immediate" | "period_end" | "scheduled";
647
+ cancel_at?: string;
648
+ }
649
+
650
+ export interface V2SubscriptionChangePlanParams {
651
+ product_id: string;
652
+ }
653
+
654
+ export interface V2CancelSubscriptionResult {
655
+ object: "subscription_cancel_result";
656
+ mode: string;
657
+ status: string;
658
+ cancel_at_period_end: boolean;
659
+ effective_at: string | null;
660
+ scheduled_cancel_at: string | null;
661
+ message: string;
662
+ }
663
+
664
+ // --- Credits ---
665
+
666
+ export interface V2CreditTransaction extends V2Object {
667
+ object: "credit_transaction";
668
+ site_user_id: string;
669
+ amount_cents: number;
670
+ balance_after_cents: number;
671
+ type: string;
672
+ description: string | null;
673
+ reference_id: string | null;
674
+ reference_type: string | null;
675
+ created_at: string | null;
676
+ }
677
+
678
+ export interface V2CreditBalance {
679
+ object: "credit_balance";
680
+ balance_cents: number;
681
+ transactions?: V2CreditTransaction[];
682
+ }
683
+
684
+ export interface V2GrantCreditParams {
685
+ amount_cents: number;
686
+ description: string;
687
+ }
688
+
689
+ export interface V2GrantCreditResult {
690
+ object: "grant_credit_result";
691
+ new_balance_cents: number;
692
+ }