perspectapi-ts-sdk 6.0.0 → 6.0.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.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;
@@ -4308,4 +4430,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
4308
4430
  error: string;
4309
4431
  }>;
4310
4432
 
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 };
4433
+ 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 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;
@@ -4308,4 +4430,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
4308
4430
  error: string;
4309
4431
  }>;
4310
4432
 
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 };
4433
+ 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 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
@@ -3712,6 +3712,13 @@ var OrdersV2Client = class extends BaseV2Client {
3712
3712
  data
3713
3713
  );
3714
3714
  }
3715
+ /** Update fulfillment status, tracking number, and/or notes on an order. */
3716
+ async updateFulfillment(siteName, id, data) {
3717
+ return this.patchOne(
3718
+ this.sitePath(siteName, "orders", `${id}/fulfillment`),
3719
+ data
3720
+ );
3721
+ }
3715
3722
  };
3716
3723
 
3717
3724
  // src/v2/client/site-users-client.ts
@@ -3971,6 +3978,102 @@ var WebhooksV2Client = class extends BaseV2Client {
3971
3978
  }
3972
3979
  };
3973
3980
 
3981
+ // src/v2/client/subscriptions-client.ts
3982
+ var SubscriptionsV2Client = class extends BaseV2Client {
3983
+ // --- Authenticated "me" endpoints (site-user JWT) ---
3984
+ /** List all subscriptions for the authenticated user. */
3985
+ async listMySubscriptions(siteName) {
3986
+ return this.getList(
3987
+ this.sitePath(siteName, "users", "me/subscriptions")
3988
+ );
3989
+ }
3990
+ /** Pause a subscription. */
3991
+ async pauseSubscription(siteName, subId, params) {
3992
+ return this.post(
3993
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/pause`),
3994
+ params ?? {}
3995
+ );
3996
+ }
3997
+ /** Resume a paused subscription. */
3998
+ async resumeSubscription(siteName, subId) {
3999
+ return this.post(
4000
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/resume`)
4001
+ );
4002
+ }
4003
+ /** Cancel a subscription. */
4004
+ async cancelSubscription(siteName, subId, params) {
4005
+ return this.post(
4006
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/cancel`),
4007
+ params ?? {}
4008
+ );
4009
+ }
4010
+ /** Change the plan (price) of a subscription. */
4011
+ async changeSubscriptionPlan(siteName, subId, params) {
4012
+ return this.post(
4013
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/change-plan`),
4014
+ params
4015
+ );
4016
+ }
4017
+ // --- Admin endpoints (API key) ---
4018
+ /** List subscriptions for a specific user (admin). */
4019
+ async listUserSubscriptions(siteName, userId) {
4020
+ return this.getList(
4021
+ this.sitePath(siteName, "users", `${userId}/subscriptions`)
4022
+ );
4023
+ }
4024
+ /** Pause a user's subscription (admin). */
4025
+ async pauseUserSubscription(siteName, userId, subId, params) {
4026
+ return this.post(
4027
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/pause`),
4028
+ params ?? {}
4029
+ );
4030
+ }
4031
+ /** Resume a user's paused subscription (admin). */
4032
+ async resumeUserSubscription(siteName, userId, subId) {
4033
+ return this.post(
4034
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/resume`)
4035
+ );
4036
+ }
4037
+ /** Cancel a user's subscription (admin). */
4038
+ async cancelUserSubscription(siteName, userId, subId, params) {
4039
+ return this.post(
4040
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/cancel`),
4041
+ params ?? {}
4042
+ );
4043
+ }
4044
+ };
4045
+
4046
+ // src/v2/client/credits-client.ts
4047
+ var CreditsV2Client = class extends BaseV2Client {
4048
+ // --- Authenticated "me" endpoints (site-user JWT) ---
4049
+ /** Get the current credit balance for the authenticated user. */
4050
+ async getMyBalance(siteName) {
4051
+ return this.getOne(
4052
+ this.sitePath(siteName, "users", "me/credits/balance")
4053
+ );
4054
+ }
4055
+ /** Get credit balance and transaction history for the authenticated user. */
4056
+ async getMyCredits(siteName) {
4057
+ return this.getOne(
4058
+ this.sitePath(siteName, "users", "me/credits")
4059
+ );
4060
+ }
4061
+ // --- Admin endpoints (API key) ---
4062
+ /** Get the credit balance for a specific user (admin). */
4063
+ async getUserBalance(siteName, userId) {
4064
+ return this.getOne(
4065
+ this.sitePath(siteName, "users", `${userId}/credits/balance`)
4066
+ );
4067
+ }
4068
+ /** Grant credit to a specific user (admin). */
4069
+ async grantCredit(siteName, userId, data) {
4070
+ return this.post(
4071
+ this.sitePath(siteName, "users", `${userId}/credits/grant`),
4072
+ data
4073
+ );
4074
+ }
4075
+ };
4076
+
3974
4077
  // src/v2/index.ts
3975
4078
  var PerspectApiV2Client = class {
3976
4079
  http;
@@ -3987,6 +4090,8 @@ var PerspectApiV2Client = class {
3987
4090
  sites;
3988
4091
  apiKeys;
3989
4092
  webhooks;
4093
+ subscriptions;
4094
+ credits;
3990
4095
  constructor(config) {
3991
4096
  const baseUrl = config.baseUrl.replace(/\/+$/, "");
3992
4097
  const v2BaseUrl = baseUrl.endsWith("/api/v2") ? baseUrl : `${baseUrl}/api/v2`;
@@ -4006,6 +4111,8 @@ var PerspectApiV2Client = class {
4006
4111
  this.sites = new SitesV2Client(this.http, basePath, cache);
4007
4112
  this.apiKeys = new ApiKeysV2Client(this.http, basePath, cache);
4008
4113
  this.webhooks = new WebhooksV2Client(this.http, basePath, cache);
4114
+ this.subscriptions = new SubscriptionsV2Client(this.http, basePath, cache);
4115
+ this.credits = new CreditsV2Client(this.http, basePath, cache);
4009
4116
  }
4010
4117
  /** Update the JWT token for authenticated requests. */
4011
4118
  setAuth(jwt) {
package/dist/index.mjs CHANGED
@@ -3644,6 +3644,13 @@ var OrdersV2Client = class extends BaseV2Client {
3644
3644
  data
3645
3645
  );
3646
3646
  }
3647
+ /** Update fulfillment status, tracking number, and/or notes on an order. */
3648
+ async updateFulfillment(siteName, id, data) {
3649
+ return this.patchOne(
3650
+ this.sitePath(siteName, "orders", `${id}/fulfillment`),
3651
+ data
3652
+ );
3653
+ }
3647
3654
  };
3648
3655
 
3649
3656
  // src/v2/client/site-users-client.ts
@@ -3903,6 +3910,102 @@ var WebhooksV2Client = class extends BaseV2Client {
3903
3910
  }
3904
3911
  };
3905
3912
 
3913
+ // src/v2/client/subscriptions-client.ts
3914
+ var SubscriptionsV2Client = class extends BaseV2Client {
3915
+ // --- Authenticated "me" endpoints (site-user JWT) ---
3916
+ /** List all subscriptions for the authenticated user. */
3917
+ async listMySubscriptions(siteName) {
3918
+ return this.getList(
3919
+ this.sitePath(siteName, "users", "me/subscriptions")
3920
+ );
3921
+ }
3922
+ /** Pause a subscription. */
3923
+ async pauseSubscription(siteName, subId, params) {
3924
+ return this.post(
3925
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/pause`),
3926
+ params ?? {}
3927
+ );
3928
+ }
3929
+ /** Resume a paused subscription. */
3930
+ async resumeSubscription(siteName, subId) {
3931
+ return this.post(
3932
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/resume`)
3933
+ );
3934
+ }
3935
+ /** Cancel a subscription. */
3936
+ async cancelSubscription(siteName, subId, params) {
3937
+ return this.post(
3938
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/cancel`),
3939
+ params ?? {}
3940
+ );
3941
+ }
3942
+ /** Change the plan (price) of a subscription. */
3943
+ async changeSubscriptionPlan(siteName, subId, params) {
3944
+ return this.post(
3945
+ this.sitePath(siteName, "users", `me/subscriptions/${subId}/change-plan`),
3946
+ params
3947
+ );
3948
+ }
3949
+ // --- Admin endpoints (API key) ---
3950
+ /** List subscriptions for a specific user (admin). */
3951
+ async listUserSubscriptions(siteName, userId) {
3952
+ return this.getList(
3953
+ this.sitePath(siteName, "users", `${userId}/subscriptions`)
3954
+ );
3955
+ }
3956
+ /** Pause a user's subscription (admin). */
3957
+ async pauseUserSubscription(siteName, userId, subId, params) {
3958
+ return this.post(
3959
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/pause`),
3960
+ params ?? {}
3961
+ );
3962
+ }
3963
+ /** Resume a user's paused subscription (admin). */
3964
+ async resumeUserSubscription(siteName, userId, subId) {
3965
+ return this.post(
3966
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/resume`)
3967
+ );
3968
+ }
3969
+ /** Cancel a user's subscription (admin). */
3970
+ async cancelUserSubscription(siteName, userId, subId, params) {
3971
+ return this.post(
3972
+ this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/cancel`),
3973
+ params ?? {}
3974
+ );
3975
+ }
3976
+ };
3977
+
3978
+ // src/v2/client/credits-client.ts
3979
+ var CreditsV2Client = class extends BaseV2Client {
3980
+ // --- Authenticated "me" endpoints (site-user JWT) ---
3981
+ /** Get the current credit balance for the authenticated user. */
3982
+ async getMyBalance(siteName) {
3983
+ return this.getOne(
3984
+ this.sitePath(siteName, "users", "me/credits/balance")
3985
+ );
3986
+ }
3987
+ /** Get credit balance and transaction history for the authenticated user. */
3988
+ async getMyCredits(siteName) {
3989
+ return this.getOne(
3990
+ this.sitePath(siteName, "users", "me/credits")
3991
+ );
3992
+ }
3993
+ // --- Admin endpoints (API key) ---
3994
+ /** Get the credit balance for a specific user (admin). */
3995
+ async getUserBalance(siteName, userId) {
3996
+ return this.getOne(
3997
+ this.sitePath(siteName, "users", `${userId}/credits/balance`)
3998
+ );
3999
+ }
4000
+ /** Grant credit to a specific user (admin). */
4001
+ async grantCredit(siteName, userId, data) {
4002
+ return this.post(
4003
+ this.sitePath(siteName, "users", `${userId}/credits/grant`),
4004
+ data
4005
+ );
4006
+ }
4007
+ };
4008
+
3906
4009
  // src/v2/index.ts
3907
4010
  var PerspectApiV2Client = class {
3908
4011
  http;
@@ -3919,6 +4022,8 @@ var PerspectApiV2Client = class {
3919
4022
  sites;
3920
4023
  apiKeys;
3921
4024
  webhooks;
4025
+ subscriptions;
4026
+ credits;
3922
4027
  constructor(config) {
3923
4028
  const baseUrl = config.baseUrl.replace(/\/+$/, "");
3924
4029
  const v2BaseUrl = baseUrl.endsWith("/api/v2") ? baseUrl : `${baseUrl}/api/v2`;
@@ -3938,6 +4043,8 @@ var PerspectApiV2Client = class {
3938
4043
  this.sites = new SitesV2Client(this.http, basePath, cache);
3939
4044
  this.apiKeys = new ApiKeysV2Client(this.http, basePath, cache);
3940
4045
  this.webhooks = new WebhooksV2Client(this.http, basePath, cache);
4046
+ this.subscriptions = new SubscriptionsV2Client(this.http, basePath, cache);
4047
+ this.credits = new CreditsV2Client(this.http, basePath, cache);
3941
4048
  }
3942
4049
  /** Update the JWT token for authenticated requests. */
3943
4050
  setAuth(jwt) {
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.1",
4
4
  "description": "TypeScript SDK for PerspectAPI - Cloudflare Workers compatible",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -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
+ }