perspectapi-ts-sdk 6.5.6 → 6.5.9
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 +30 -4
- package/dist/index.d.ts +30 -4
- package/dist/index.js +42 -10
- package/dist/index.mjs +42 -10
- package/package.json +1 -1
- package/src/client/base-client.ts +2 -1
- package/src/utils/http-client.ts +8 -0
- package/src/v2/client/base-v2-client.ts +2 -1
- package/src/v2/client/credits-client.ts +7 -2
- package/src/v2/client/site-users-client.ts +20 -2
- package/src/v2/client/subscriptions-client.ts +16 -1
- package/src/v2/types.ts +20 -0
package/dist/index.d.mts
CHANGED
|
@@ -1126,6 +1126,11 @@ declare class HttpClient {
|
|
|
1126
1126
|
* Update API key
|
|
1127
1127
|
*/
|
|
1128
1128
|
setApiKey(apiKey: string): void;
|
|
1129
|
+
/**
|
|
1130
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
1131
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
1132
|
+
*/
|
|
1133
|
+
hasBearerAuth(): boolean;
|
|
1129
1134
|
/**
|
|
1130
1135
|
* Remove authentication
|
|
1131
1136
|
*/
|
|
@@ -1752,6 +1757,24 @@ interface V2SubscriptionCancelParams {
|
|
|
1752
1757
|
interface V2SubscriptionChangePlanParams {
|
|
1753
1758
|
product_id: string;
|
|
1754
1759
|
}
|
|
1760
|
+
interface V2SubscriptionChargeParams {
|
|
1761
|
+
amount_cents: number;
|
|
1762
|
+
currency?: string;
|
|
1763
|
+
description?: string;
|
|
1764
|
+
idempotency_key: string;
|
|
1765
|
+
metadata?: Record<string, string>;
|
|
1766
|
+
}
|
|
1767
|
+
interface V2SubscriptionChargeResult {
|
|
1768
|
+
object: "subscription_charge";
|
|
1769
|
+
provider_invoice_id: string | null;
|
|
1770
|
+
provider_invoice_item_id: string | null;
|
|
1771
|
+
provider_payment_intent_id: string | null;
|
|
1772
|
+
status: string | null;
|
|
1773
|
+
paid: boolean;
|
|
1774
|
+
amount_due: number | null;
|
|
1775
|
+
amount_paid: number | null;
|
|
1776
|
+
currency: string;
|
|
1777
|
+
}
|
|
1755
1778
|
interface V2CancelSubscriptionResult {
|
|
1756
1779
|
object: "subscription_cancel_result";
|
|
1757
1780
|
mode: string;
|
|
@@ -1969,13 +1992,14 @@ declare class SiteUsersV2Client extends BaseV2Client {
|
|
|
1969
1992
|
list(siteName: string, params?: V2SiteUserListParams): Promise<V2List<V2SiteUser>>;
|
|
1970
1993
|
listAutoPaginated(siteName: string, params?: Omit<V2SiteUserListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2SiteUser, void, unknown>;
|
|
1971
1994
|
get(siteName: string, id: string): Promise<V2SiteUser>;
|
|
1995
|
+
getProfileForUser(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2SiteUserProfile>;
|
|
1972
1996
|
update(siteName: string, id: string, data: V2SiteUserUpdateParams): Promise<V2SiteUser>;
|
|
1973
1997
|
/**
|
|
1974
1998
|
* Load the currently-authenticated site user's canonical record plus their
|
|
1975
1999
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
1976
2000
|
* the token returned from `verifyOtp`.
|
|
1977
2001
|
*/
|
|
1978
|
-
getMe(siteName: string): Promise<V2SiteUserWithProfile>;
|
|
2002
|
+
getMe(siteName: string, cachePolicy?: CachePolicy): Promise<V2SiteUserWithProfile>;
|
|
1979
2003
|
/** Update the authenticated user's own fields. */
|
|
1980
2004
|
updateMe(siteName: string, data: V2SiteUserMeUpdateParams): Promise<V2SiteUser>;
|
|
1981
2005
|
/** Fetch the profile KV map as a dedicated `site_user_profile` envelope. */
|
|
@@ -2133,6 +2157,8 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2133
2157
|
resumeUserSubscription(siteName: string, userId: string, subId: string): Promise<V2SiteUserSubscription>;
|
|
2134
2158
|
/** Cancel a user's subscription (admin). */
|
|
2135
2159
|
cancelUserSubscription(siteName: string, userId: string, subId: string, params?: V2SubscriptionCancelParams): Promise<V2CancelSubscriptionResult>;
|
|
2160
|
+
/** Charge a user's subscription once (admin). */
|
|
2161
|
+
chargeUserSubscription(siteName: string, userId: string, subId: string, params: V2SubscriptionChargeParams): Promise<V2SubscriptionChargeResult>;
|
|
2136
2162
|
}
|
|
2137
2163
|
|
|
2138
2164
|
/**
|
|
@@ -2145,9 +2171,9 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2145
2171
|
|
|
2146
2172
|
declare class CreditsV2Client extends BaseV2Client {
|
|
2147
2173
|
/** Get the current credit balance for the authenticated user. */
|
|
2148
|
-
getMyBalance(siteName: string): Promise<V2CreditBalance>;
|
|
2174
|
+
getMyBalance(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2149
2175
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
2150
|
-
getMyCredits(siteName: string): Promise<V2CreditBalance>;
|
|
2176
|
+
getMyCredits(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2151
2177
|
/** Get the credit balance for a specific user (admin). */
|
|
2152
2178
|
getUserBalance(siteName: string, userId: string): Promise<V2CreditBalance>;
|
|
2153
2179
|
/** Grant credit to a specific user (admin). */
|
|
@@ -4536,4 +4562,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4536
4562
|
error: string;
|
|
4537
4563
|
}>;
|
|
4538
4564
|
|
|
4539
|
-
export { type AbClient, type AbForRequestResult, type AbVariantResult, type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheAdapter, 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 CreatePerspectAbOptions, 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 LoadBlockBySlugOptions, 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, type PerspectAb, PerspectApiClient, type PerspectApiConfig, PerspectApiError, 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, V1_DEPRECATION_NOTICE, V1_SUNSET_DATE, 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 V2WebhookEventType, type V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, type WebhookEventType, WebhooksClient, bucketFor, buildImageUrl, createApiError, createCheckoutSession, createPerspectAb, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadBlockBySlug, loadBlocks, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct, variantForBucket };
|
|
4565
|
+
export { type AbClient, type AbForRequestResult, type AbVariantResult, type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheAdapter, 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 CreatePerspectAbOptions, 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 LoadBlockBySlugOptions, 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, type PerspectAb, PerspectApiClient, type PerspectApiConfig, PerspectApiError, 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, V1_DEPRECATION_NOTICE, V1_SUNSET_DATE, 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 V2SubscriptionChargeParams, type V2SubscriptionChargeResult, type V2SubscriptionPauseParams, type V2Webhook, type V2WebhookCreateParams, type V2WebhookEventType, type V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, type WebhookEventType, WebhooksClient, bucketFor, buildImageUrl, createApiError, createCheckoutSession, createPerspectAb, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadBlockBySlug, loadBlocks, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct, variantForBucket };
|
package/dist/index.d.ts
CHANGED
|
@@ -1126,6 +1126,11 @@ declare class HttpClient {
|
|
|
1126
1126
|
* Update API key
|
|
1127
1127
|
*/
|
|
1128
1128
|
setApiKey(apiKey: string): void;
|
|
1129
|
+
/**
|
|
1130
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
1131
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
1132
|
+
*/
|
|
1133
|
+
hasBearerAuth(): boolean;
|
|
1129
1134
|
/**
|
|
1130
1135
|
* Remove authentication
|
|
1131
1136
|
*/
|
|
@@ -1752,6 +1757,24 @@ interface V2SubscriptionCancelParams {
|
|
|
1752
1757
|
interface V2SubscriptionChangePlanParams {
|
|
1753
1758
|
product_id: string;
|
|
1754
1759
|
}
|
|
1760
|
+
interface V2SubscriptionChargeParams {
|
|
1761
|
+
amount_cents: number;
|
|
1762
|
+
currency?: string;
|
|
1763
|
+
description?: string;
|
|
1764
|
+
idempotency_key: string;
|
|
1765
|
+
metadata?: Record<string, string>;
|
|
1766
|
+
}
|
|
1767
|
+
interface V2SubscriptionChargeResult {
|
|
1768
|
+
object: "subscription_charge";
|
|
1769
|
+
provider_invoice_id: string | null;
|
|
1770
|
+
provider_invoice_item_id: string | null;
|
|
1771
|
+
provider_payment_intent_id: string | null;
|
|
1772
|
+
status: string | null;
|
|
1773
|
+
paid: boolean;
|
|
1774
|
+
amount_due: number | null;
|
|
1775
|
+
amount_paid: number | null;
|
|
1776
|
+
currency: string;
|
|
1777
|
+
}
|
|
1755
1778
|
interface V2CancelSubscriptionResult {
|
|
1756
1779
|
object: "subscription_cancel_result";
|
|
1757
1780
|
mode: string;
|
|
@@ -1969,13 +1992,14 @@ declare class SiteUsersV2Client extends BaseV2Client {
|
|
|
1969
1992
|
list(siteName: string, params?: V2SiteUserListParams): Promise<V2List<V2SiteUser>>;
|
|
1970
1993
|
listAutoPaginated(siteName: string, params?: Omit<V2SiteUserListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2SiteUser, void, unknown>;
|
|
1971
1994
|
get(siteName: string, id: string): Promise<V2SiteUser>;
|
|
1995
|
+
getProfileForUser(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2SiteUserProfile>;
|
|
1972
1996
|
update(siteName: string, id: string, data: V2SiteUserUpdateParams): Promise<V2SiteUser>;
|
|
1973
1997
|
/**
|
|
1974
1998
|
* Load the currently-authenticated site user's canonical record plus their
|
|
1975
1999
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
1976
2000
|
* the token returned from `verifyOtp`.
|
|
1977
2001
|
*/
|
|
1978
|
-
getMe(siteName: string): Promise<V2SiteUserWithProfile>;
|
|
2002
|
+
getMe(siteName: string, cachePolicy?: CachePolicy): Promise<V2SiteUserWithProfile>;
|
|
1979
2003
|
/** Update the authenticated user's own fields. */
|
|
1980
2004
|
updateMe(siteName: string, data: V2SiteUserMeUpdateParams): Promise<V2SiteUser>;
|
|
1981
2005
|
/** Fetch the profile KV map as a dedicated `site_user_profile` envelope. */
|
|
@@ -2133,6 +2157,8 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2133
2157
|
resumeUserSubscription(siteName: string, userId: string, subId: string): Promise<V2SiteUserSubscription>;
|
|
2134
2158
|
/** Cancel a user's subscription (admin). */
|
|
2135
2159
|
cancelUserSubscription(siteName: string, userId: string, subId: string, params?: V2SubscriptionCancelParams): Promise<V2CancelSubscriptionResult>;
|
|
2160
|
+
/** Charge a user's subscription once (admin). */
|
|
2161
|
+
chargeUserSubscription(siteName: string, userId: string, subId: string, params: V2SubscriptionChargeParams): Promise<V2SubscriptionChargeResult>;
|
|
2136
2162
|
}
|
|
2137
2163
|
|
|
2138
2164
|
/**
|
|
@@ -2145,9 +2171,9 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2145
2171
|
|
|
2146
2172
|
declare class CreditsV2Client extends BaseV2Client {
|
|
2147
2173
|
/** Get the current credit balance for the authenticated user. */
|
|
2148
|
-
getMyBalance(siteName: string): Promise<V2CreditBalance>;
|
|
2174
|
+
getMyBalance(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2149
2175
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
2150
|
-
getMyCredits(siteName: string): Promise<V2CreditBalance>;
|
|
2176
|
+
getMyCredits(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2151
2177
|
/** Get the credit balance for a specific user (admin). */
|
|
2152
2178
|
getUserBalance(siteName: string, userId: string): Promise<V2CreditBalance>;
|
|
2153
2179
|
/** Grant credit to a specific user (admin). */
|
|
@@ -4536,4 +4562,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4536
4562
|
error: string;
|
|
4537
4563
|
}>;
|
|
4538
4564
|
|
|
4539
|
-
export { type AbClient, type AbForRequestResult, type AbVariantResult, type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheAdapter, 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 CreatePerspectAbOptions, 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 LoadBlockBySlugOptions, 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, type PerspectAb, PerspectApiClient, type PerspectApiConfig, PerspectApiError, 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, V1_DEPRECATION_NOTICE, V1_SUNSET_DATE, 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 V2WebhookEventType, type V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, type WebhookEventType, WebhooksClient, bucketFor, buildImageUrl, createApiError, createCheckoutSession, createPerspectAb, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadBlockBySlug, loadBlocks, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct, variantForBucket };
|
|
4565
|
+
export { type AbClient, type AbForRequestResult, type AbVariantResult, type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheAdapter, 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 CreatePerspectAbOptions, 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 LoadBlockBySlugOptions, 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, type PerspectAb, PerspectApiClient, type PerspectApiConfig, PerspectApiError, 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, V1_DEPRECATION_NOTICE, V1_SUNSET_DATE, 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 V2SubscriptionChargeParams, type V2SubscriptionChargeResult, type V2SubscriptionPauseParams, type V2Webhook, type V2WebhookCreateParams, type V2WebhookEventType, type V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, type WebhookEventType, WebhooksClient, bucketFor, buildImageUrl, createApiError, createCheckoutSession, createPerspectAb, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadBlockBySlug, loadBlocks, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct, variantForBucket };
|
package/dist/index.js
CHANGED
|
@@ -132,6 +132,13 @@ var HttpClient = class {
|
|
|
132
132
|
setApiKey(apiKey) {
|
|
133
133
|
this.defaultHeaders["X-API-Key"] = apiKey;
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
137
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
138
|
+
*/
|
|
139
|
+
hasBearerAuth() {
|
|
140
|
+
return Boolean(this.defaultHeaders["Authorization"]);
|
|
141
|
+
}
|
|
135
142
|
/**
|
|
136
143
|
* Remove authentication
|
|
137
144
|
*/
|
|
@@ -684,7 +691,8 @@ var BaseV2Client = class {
|
|
|
684
691
|
}
|
|
685
692
|
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
686
693
|
async fetchWithCache(path, params, policy, fetcher) {
|
|
687
|
-
|
|
694
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
695
|
+
if (!this.cache || policy?.skipCache || hasBearerAuth) {
|
|
688
696
|
return fetcher();
|
|
689
697
|
}
|
|
690
698
|
const key = this.buildCacheKey(path, params);
|
|
@@ -1001,6 +1009,9 @@ var OrdersV2Client = class extends BaseV2Client {
|
|
|
1001
1009
|
};
|
|
1002
1010
|
|
|
1003
1011
|
// src/v2/client/site-users-client.ts
|
|
1012
|
+
function bypassAuthenticatedCache(policy) {
|
|
1013
|
+
return { ...policy, skipCache: true };
|
|
1014
|
+
}
|
|
1004
1015
|
var SiteUsersV2Client = class extends BaseV2Client {
|
|
1005
1016
|
// --- OTP Auth (public, API-key-scoped) ---
|
|
1006
1017
|
async requestOtp(siteName, data) {
|
|
@@ -1019,6 +1030,13 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
1019
1030
|
async get(siteName, id) {
|
|
1020
1031
|
return this.getOne(this.sitePath(siteName, "users", id));
|
|
1021
1032
|
}
|
|
1033
|
+
async getProfileForUser(siteName, id, cachePolicy) {
|
|
1034
|
+
return this.getOne(
|
|
1035
|
+
this.sitePath(siteName, "users", `${id}/profile`),
|
|
1036
|
+
void 0,
|
|
1037
|
+
cachePolicy
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1022
1040
|
async update(siteName, id, data) {
|
|
1023
1041
|
return this.patchOne(this.sitePath(siteName, "users", id), data);
|
|
1024
1042
|
}
|
|
@@ -1028,9 +1046,11 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
1028
1046
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
1029
1047
|
* the token returned from `verifyOtp`.
|
|
1030
1048
|
*/
|
|
1031
|
-
async getMe(siteName) {
|
|
1049
|
+
async getMe(siteName, cachePolicy) {
|
|
1032
1050
|
return this.getOne(
|
|
1033
|
-
this.sitePath(siteName, "users", "me")
|
|
1051
|
+
this.sitePath(siteName, "users", "me"),
|
|
1052
|
+
void 0,
|
|
1053
|
+
bypassAuthenticatedCache(cachePolicy)
|
|
1034
1054
|
);
|
|
1035
1055
|
}
|
|
1036
1056
|
/** Update the authenticated user's own fields. */
|
|
@@ -1045,7 +1065,7 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
1045
1065
|
return this.getOne(
|
|
1046
1066
|
this.sitePath(siteName, "users", "me/profile"),
|
|
1047
1067
|
void 0,
|
|
1048
|
-
cachePolicy
|
|
1068
|
+
bypassAuthenticatedCache(cachePolicy)
|
|
1049
1069
|
);
|
|
1050
1070
|
}
|
|
1051
1071
|
/**
|
|
@@ -1267,7 +1287,7 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1267
1287
|
return this.getList(
|
|
1268
1288
|
this.sitePath(siteName, "users", "me/subscriptions"),
|
|
1269
1289
|
void 0,
|
|
1270
|
-
cachePolicy
|
|
1290
|
+
{ ...cachePolicy, skipCache: true }
|
|
1271
1291
|
);
|
|
1272
1292
|
}
|
|
1273
1293
|
/** Pause a subscription. */
|
|
@@ -1326,21 +1346,32 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1326
1346
|
params ?? {}
|
|
1327
1347
|
);
|
|
1328
1348
|
}
|
|
1349
|
+
/** Charge a user's subscription once (admin). */
|
|
1350
|
+
async chargeUserSubscription(siteName, userId, subId, params) {
|
|
1351
|
+
return this.post(
|
|
1352
|
+
this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/charges`),
|
|
1353
|
+
params
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1329
1356
|
};
|
|
1330
1357
|
|
|
1331
1358
|
// src/v2/client/credits-client.ts
|
|
1332
1359
|
var CreditsV2Client = class extends BaseV2Client {
|
|
1333
1360
|
// --- Authenticated "me" endpoints (site-user JWT) ---
|
|
1334
1361
|
/** Get the current credit balance for the authenticated user. */
|
|
1335
|
-
async getMyBalance(siteName) {
|
|
1362
|
+
async getMyBalance(siteName, cachePolicy) {
|
|
1336
1363
|
return this.getOne(
|
|
1337
|
-
this.sitePath(siteName, "users", "me/credits/balance")
|
|
1364
|
+
this.sitePath(siteName, "users", "me/credits/balance"),
|
|
1365
|
+
void 0,
|
|
1366
|
+
{ ...cachePolicy, skipCache: true }
|
|
1338
1367
|
);
|
|
1339
1368
|
}
|
|
1340
1369
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
1341
|
-
async getMyCredits(siteName) {
|
|
1370
|
+
async getMyCredits(siteName, cachePolicy) {
|
|
1342
1371
|
return this.getOne(
|
|
1343
|
-
this.sitePath(siteName, "users", "me/credits")
|
|
1372
|
+
this.sitePath(siteName, "users", "me/credits"),
|
|
1373
|
+
void 0,
|
|
1374
|
+
{ ...cachePolicy, skipCache: true }
|
|
1344
1375
|
);
|
|
1345
1376
|
}
|
|
1346
1377
|
// --- Admin endpoints (API key) ---
|
|
@@ -1488,7 +1519,8 @@ var BaseClient = class {
|
|
|
1488
1519
|
* Fetch a GET endpoint with optional caching support.
|
|
1489
1520
|
*/
|
|
1490
1521
|
async fetchWithCache(endpoint, params, tags, policy, fetcher) {
|
|
1491
|
-
|
|
1522
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
1523
|
+
if (!this.cache || hasBearerAuth) {
|
|
1492
1524
|
return fetcher();
|
|
1493
1525
|
}
|
|
1494
1526
|
const cacheKey = this.buildCacheKey(endpoint, params);
|
package/dist/index.mjs
CHANGED
|
@@ -56,6 +56,13 @@ var HttpClient = class {
|
|
|
56
56
|
setApiKey(apiKey) {
|
|
57
57
|
this.defaultHeaders["X-API-Key"] = apiKey;
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
61
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
62
|
+
*/
|
|
63
|
+
hasBearerAuth() {
|
|
64
|
+
return Boolean(this.defaultHeaders["Authorization"]);
|
|
65
|
+
}
|
|
59
66
|
/**
|
|
60
67
|
* Remove authentication
|
|
61
68
|
*/
|
|
@@ -608,7 +615,8 @@ var BaseV2Client = class {
|
|
|
608
615
|
}
|
|
609
616
|
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
610
617
|
async fetchWithCache(path, params, policy, fetcher) {
|
|
611
|
-
|
|
618
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
619
|
+
if (!this.cache || policy?.skipCache || hasBearerAuth) {
|
|
612
620
|
return fetcher();
|
|
613
621
|
}
|
|
614
622
|
const key = this.buildCacheKey(path, params);
|
|
@@ -925,6 +933,9 @@ var OrdersV2Client = class extends BaseV2Client {
|
|
|
925
933
|
};
|
|
926
934
|
|
|
927
935
|
// src/v2/client/site-users-client.ts
|
|
936
|
+
function bypassAuthenticatedCache(policy) {
|
|
937
|
+
return { ...policy, skipCache: true };
|
|
938
|
+
}
|
|
928
939
|
var SiteUsersV2Client = class extends BaseV2Client {
|
|
929
940
|
// --- OTP Auth (public, API-key-scoped) ---
|
|
930
941
|
async requestOtp(siteName, data) {
|
|
@@ -943,6 +954,13 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
943
954
|
async get(siteName, id) {
|
|
944
955
|
return this.getOne(this.sitePath(siteName, "users", id));
|
|
945
956
|
}
|
|
957
|
+
async getProfileForUser(siteName, id, cachePolicy) {
|
|
958
|
+
return this.getOne(
|
|
959
|
+
this.sitePath(siteName, "users", `${id}/profile`),
|
|
960
|
+
void 0,
|
|
961
|
+
cachePolicy
|
|
962
|
+
);
|
|
963
|
+
}
|
|
946
964
|
async update(siteName, id, data) {
|
|
947
965
|
return this.patchOne(this.sitePath(siteName, "users", id), data);
|
|
948
966
|
}
|
|
@@ -952,9 +970,11 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
952
970
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
953
971
|
* the token returned from `verifyOtp`.
|
|
954
972
|
*/
|
|
955
|
-
async getMe(siteName) {
|
|
973
|
+
async getMe(siteName, cachePolicy) {
|
|
956
974
|
return this.getOne(
|
|
957
|
-
this.sitePath(siteName, "users", "me")
|
|
975
|
+
this.sitePath(siteName, "users", "me"),
|
|
976
|
+
void 0,
|
|
977
|
+
bypassAuthenticatedCache(cachePolicy)
|
|
958
978
|
);
|
|
959
979
|
}
|
|
960
980
|
/** Update the authenticated user's own fields. */
|
|
@@ -969,7 +989,7 @@ var SiteUsersV2Client = class extends BaseV2Client {
|
|
|
969
989
|
return this.getOne(
|
|
970
990
|
this.sitePath(siteName, "users", "me/profile"),
|
|
971
991
|
void 0,
|
|
972
|
-
cachePolicy
|
|
992
|
+
bypassAuthenticatedCache(cachePolicy)
|
|
973
993
|
);
|
|
974
994
|
}
|
|
975
995
|
/**
|
|
@@ -1191,7 +1211,7 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1191
1211
|
return this.getList(
|
|
1192
1212
|
this.sitePath(siteName, "users", "me/subscriptions"),
|
|
1193
1213
|
void 0,
|
|
1194
|
-
cachePolicy
|
|
1214
|
+
{ ...cachePolicy, skipCache: true }
|
|
1195
1215
|
);
|
|
1196
1216
|
}
|
|
1197
1217
|
/** Pause a subscription. */
|
|
@@ -1250,21 +1270,32 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1250
1270
|
params ?? {}
|
|
1251
1271
|
);
|
|
1252
1272
|
}
|
|
1273
|
+
/** Charge a user's subscription once (admin). */
|
|
1274
|
+
async chargeUserSubscription(siteName, userId, subId, params) {
|
|
1275
|
+
return this.post(
|
|
1276
|
+
this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/charges`),
|
|
1277
|
+
params
|
|
1278
|
+
);
|
|
1279
|
+
}
|
|
1253
1280
|
};
|
|
1254
1281
|
|
|
1255
1282
|
// src/v2/client/credits-client.ts
|
|
1256
1283
|
var CreditsV2Client = class extends BaseV2Client {
|
|
1257
1284
|
// --- Authenticated "me" endpoints (site-user JWT) ---
|
|
1258
1285
|
/** Get the current credit balance for the authenticated user. */
|
|
1259
|
-
async getMyBalance(siteName) {
|
|
1286
|
+
async getMyBalance(siteName, cachePolicy) {
|
|
1260
1287
|
return this.getOne(
|
|
1261
|
-
this.sitePath(siteName, "users", "me/credits/balance")
|
|
1288
|
+
this.sitePath(siteName, "users", "me/credits/balance"),
|
|
1289
|
+
void 0,
|
|
1290
|
+
{ ...cachePolicy, skipCache: true }
|
|
1262
1291
|
);
|
|
1263
1292
|
}
|
|
1264
1293
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
1265
|
-
async getMyCredits(siteName) {
|
|
1294
|
+
async getMyCredits(siteName, cachePolicy) {
|
|
1266
1295
|
return this.getOne(
|
|
1267
|
-
this.sitePath(siteName, "users", "me/credits")
|
|
1296
|
+
this.sitePath(siteName, "users", "me/credits"),
|
|
1297
|
+
void 0,
|
|
1298
|
+
{ ...cachePolicy, skipCache: true }
|
|
1268
1299
|
);
|
|
1269
1300
|
}
|
|
1270
1301
|
// --- Admin endpoints (API key) ---
|
|
@@ -1412,7 +1443,8 @@ var BaseClient = class {
|
|
|
1412
1443
|
* Fetch a GET endpoint with optional caching support.
|
|
1413
1444
|
*/
|
|
1414
1445
|
async fetchWithCache(endpoint, params, tags, policy, fetcher) {
|
|
1415
|
-
|
|
1446
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
1447
|
+
if (!this.cache || hasBearerAuth) {
|
|
1416
1448
|
return fetcher();
|
|
1417
1449
|
}
|
|
1418
1450
|
const cacheKey = this.buildCacheKey(endpoint, params);
|
package/package.json
CHANGED
|
@@ -115,7 +115,8 @@ export abstract class BaseClient {
|
|
|
115
115
|
policy: CachePolicy | undefined,
|
|
116
116
|
fetcher: () => Promise<T>
|
|
117
117
|
): Promise<T> {
|
|
118
|
-
|
|
118
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === 'function' && this.http.hasBearerAuth();
|
|
119
|
+
if (!this.cache || hasBearerAuth) {
|
|
119
120
|
return fetcher();
|
|
120
121
|
}
|
|
121
122
|
|
package/src/utils/http-client.ts
CHANGED
|
@@ -51,6 +51,14 @@ export class HttpClient {
|
|
|
51
51
|
this.defaultHeaders['X-API-Key'] = apiKey;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Whether this client currently has a site-user/admin bearer token attached.
|
|
56
|
+
* Bearer-scoped GETs must not share cache entries across callers.
|
|
57
|
+
*/
|
|
58
|
+
hasBearerAuth(): boolean {
|
|
59
|
+
return Boolean(this.defaultHeaders['Authorization']);
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
/**
|
|
55
63
|
* Remove authentication
|
|
56
64
|
*/
|
|
@@ -148,7 +148,8 @@ export abstract class BaseV2Client {
|
|
|
148
148
|
policy: CachePolicy | undefined,
|
|
149
149
|
fetcher: () => Promise<T>,
|
|
150
150
|
): Promise<T> {
|
|
151
|
-
|
|
151
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === 'function' && this.http.hasBearerAuth();
|
|
152
|
+
if (!this.cache || policy?.skipCache || hasBearerAuth) {
|
|
152
153
|
return fetcher();
|
|
153
154
|
}
|
|
154
155
|
const key = this.buildCacheKey(path, params);
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { BaseV2Client } from './base-v2-client';
|
|
10
|
+
import type { CachePolicy } from '../../cache/types';
|
|
10
11
|
import type {
|
|
11
12
|
V2CreditBalance,
|
|
12
13
|
V2GrantCreditParams,
|
|
@@ -18,16 +19,20 @@ export class CreditsV2Client extends BaseV2Client {
|
|
|
18
19
|
// --- Authenticated "me" endpoints (site-user JWT) ---
|
|
19
20
|
|
|
20
21
|
/** Get the current credit balance for the authenticated user. */
|
|
21
|
-
async getMyBalance(siteName: string): Promise<V2CreditBalance> {
|
|
22
|
+
async getMyBalance(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance> {
|
|
22
23
|
return this.getOne<V2CreditBalance>(
|
|
23
24
|
this.sitePath(siteName, 'users', 'me/credits/balance'),
|
|
25
|
+
undefined,
|
|
26
|
+
{ ...cachePolicy, skipCache: true },
|
|
24
27
|
);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
28
|
-
async getMyCredits(siteName: string): Promise<V2CreditBalance> {
|
|
31
|
+
async getMyCredits(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance> {
|
|
29
32
|
return this.getOne<V2CreditBalance>(
|
|
30
33
|
this.sitePath(siteName, 'users', 'me/credits'),
|
|
34
|
+
undefined,
|
|
35
|
+
{ ...cachePolicy, skipCache: true },
|
|
31
36
|
);
|
|
32
37
|
}
|
|
33
38
|
|
|
@@ -31,6 +31,10 @@ export interface V2OtpVerifyResponse extends V2SiteUser {
|
|
|
31
31
|
token: string;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function bypassAuthenticatedCache(policy?: CachePolicy): CachePolicy {
|
|
35
|
+
return { ...policy, skipCache: true };
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
export class SiteUsersV2Client extends BaseV2Client {
|
|
35
39
|
|
|
36
40
|
// --- OTP Auth (public, API-key-scoped) ---
|
|
@@ -63,6 +67,18 @@ export class SiteUsersV2Client extends BaseV2Client {
|
|
|
63
67
|
return this.getOne<V2SiteUser>(this.sitePath(siteName, 'users', id));
|
|
64
68
|
}
|
|
65
69
|
|
|
70
|
+
async getProfileForUser(
|
|
71
|
+
siteName: string,
|
|
72
|
+
id: string,
|
|
73
|
+
cachePolicy?: CachePolicy,
|
|
74
|
+
): Promise<V2SiteUserProfile> {
|
|
75
|
+
return this.getOne<V2SiteUserProfile>(
|
|
76
|
+
this.sitePath(siteName, 'users', `${id}/profile`),
|
|
77
|
+
undefined,
|
|
78
|
+
cachePolicy,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
66
82
|
async update(siteName: string, id: string, data: V2SiteUserUpdateParams): Promise<V2SiteUser> {
|
|
67
83
|
return this.patchOne<V2SiteUser>(this.sitePath(siteName, 'users', id), data);
|
|
68
84
|
}
|
|
@@ -74,9 +90,11 @@ export class SiteUsersV2Client extends BaseV2Client {
|
|
|
74
90
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
75
91
|
* the token returned from `verifyOtp`.
|
|
76
92
|
*/
|
|
77
|
-
async getMe(siteName: string): Promise<V2SiteUserWithProfile> {
|
|
93
|
+
async getMe(siteName: string, cachePolicy?: CachePolicy): Promise<V2SiteUserWithProfile> {
|
|
78
94
|
return this.getOne<V2SiteUserWithProfile>(
|
|
79
95
|
this.sitePath(siteName, 'users', 'me'),
|
|
96
|
+
undefined,
|
|
97
|
+
bypassAuthenticatedCache(cachePolicy),
|
|
80
98
|
);
|
|
81
99
|
}
|
|
82
100
|
|
|
@@ -96,7 +114,7 @@ export class SiteUsersV2Client extends BaseV2Client {
|
|
|
96
114
|
return this.getOne<V2SiteUserProfile>(
|
|
97
115
|
this.sitePath(siteName, 'users', 'me/profile'),
|
|
98
116
|
undefined,
|
|
99
|
-
cachePolicy,
|
|
117
|
+
bypassAuthenticatedCache(cachePolicy),
|
|
100
118
|
);
|
|
101
119
|
}
|
|
102
120
|
|
|
@@ -13,6 +13,8 @@ import type {
|
|
|
13
13
|
V2SubscriptionPauseParams,
|
|
14
14
|
V2SubscriptionCancelParams,
|
|
15
15
|
V2SubscriptionChangePlanParams,
|
|
16
|
+
V2SubscriptionChargeParams,
|
|
17
|
+
V2SubscriptionChargeResult,
|
|
16
18
|
V2CancelSubscriptionResult,
|
|
17
19
|
V2List,
|
|
18
20
|
} from '../types';
|
|
@@ -29,7 +31,7 @@ export class SubscriptionsV2Client extends BaseV2Client {
|
|
|
29
31
|
return this.getList<V2SiteUserSubscription>(
|
|
30
32
|
this.sitePath(siteName, 'users', 'me/subscriptions'),
|
|
31
33
|
undefined,
|
|
32
|
-
cachePolicy,
|
|
34
|
+
{ ...cachePolicy, skipCache: true },
|
|
33
35
|
);
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -130,4 +132,17 @@ export class SubscriptionsV2Client extends BaseV2Client {
|
|
|
130
132
|
params ?? {},
|
|
131
133
|
);
|
|
132
134
|
}
|
|
135
|
+
|
|
136
|
+
/** Charge a user's subscription once (admin). */
|
|
137
|
+
async chargeUserSubscription(
|
|
138
|
+
siteName: string,
|
|
139
|
+
userId: string,
|
|
140
|
+
subId: string,
|
|
141
|
+
params: V2SubscriptionChargeParams,
|
|
142
|
+
): Promise<V2SubscriptionChargeResult> {
|
|
143
|
+
return this.post<V2SubscriptionChargeResult>(
|
|
144
|
+
this.sitePath(siteName, 'users', `${userId}/subscriptions/${subId}/charges`),
|
|
145
|
+
params,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
133
148
|
}
|
package/src/v2/types.ts
CHANGED
|
@@ -689,6 +689,26 @@ export interface V2SubscriptionChangePlanParams {
|
|
|
689
689
|
product_id: string;
|
|
690
690
|
}
|
|
691
691
|
|
|
692
|
+
export interface V2SubscriptionChargeParams {
|
|
693
|
+
amount_cents: number;
|
|
694
|
+
currency?: string;
|
|
695
|
+
description?: string;
|
|
696
|
+
idempotency_key: string;
|
|
697
|
+
metadata?: Record<string, string>;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
export interface V2SubscriptionChargeResult {
|
|
701
|
+
object: "subscription_charge";
|
|
702
|
+
provider_invoice_id: string | null;
|
|
703
|
+
provider_invoice_item_id: string | null;
|
|
704
|
+
provider_payment_intent_id: string | null;
|
|
705
|
+
status: string | null;
|
|
706
|
+
paid: boolean;
|
|
707
|
+
amount_due: number | null;
|
|
708
|
+
amount_paid: number | null;
|
|
709
|
+
currency: string;
|
|
710
|
+
}
|
|
711
|
+
|
|
692
712
|
export interface V2CancelSubscriptionResult {
|
|
693
713
|
object: "subscription_cancel_result";
|
|
694
714
|
mode: string;
|