perspectapi-ts-sdk 6.5.4 → 6.5.7
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 +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +35 -10
- package/dist/index.mjs +35 -10
- package/package.json +1 -1
- package/src/client/base-client.ts +2 -1
- package/src/types/index.ts +31 -2
- 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 +1 -1
- package/src/v2/types.ts +31 -2
package/dist/index.d.mts
CHANGED
|
@@ -741,12 +741,13 @@ interface CreatePaymentGatewayRequest {
|
|
|
741
741
|
configuration: Record<string, any>;
|
|
742
742
|
isActive?: boolean;
|
|
743
743
|
}
|
|
744
|
+
type WebhookEventType = "content.created" | "content.updated" | "content.published" | "content.unpublished" | "content.deleted" | "newsletter.created" | "newsletter.updated" | "newsletter.published" | "newsletter.sent" | "newsletter.deleted" | "product.created" | "product.updated" | "product.deleted" | "product.stock_changed" | "order.paid" | "category.created" | "category.updated" | "category.deleted" | "site.updated" | "site.settings_changed" | "ab.flag_started" | "ab.flag_paused" | "ab.flag_resumed" | "ab.flag_stopped" | "ab.flag_updated" | "ab.config_warmup" | (string & Record<never, never>);
|
|
744
745
|
interface Webhook {
|
|
745
746
|
id: string;
|
|
746
747
|
name: string;
|
|
747
748
|
url: string;
|
|
748
749
|
provider: string;
|
|
749
|
-
events:
|
|
750
|
+
events: WebhookEventType[];
|
|
750
751
|
isActive: boolean;
|
|
751
752
|
secret?: string;
|
|
752
753
|
organizationId?: number;
|
|
@@ -757,7 +758,7 @@ interface CreateWebhookRequest {
|
|
|
757
758
|
name: string;
|
|
758
759
|
url: string;
|
|
759
760
|
provider: string;
|
|
760
|
-
events:
|
|
761
|
+
events: WebhookEventType[];
|
|
761
762
|
isActive?: boolean;
|
|
762
763
|
secret?: string;
|
|
763
764
|
}
|
|
@@ -1125,6 +1126,11 @@ declare class HttpClient {
|
|
|
1125
1126
|
* Update API key
|
|
1126
1127
|
*/
|
|
1127
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;
|
|
1128
1134
|
/**
|
|
1129
1135
|
* Remove authentication
|
|
1130
1136
|
*/
|
|
@@ -1701,11 +1707,12 @@ interface V2ApiKey extends V2Object {
|
|
|
1701
1707
|
created_at: string | null;
|
|
1702
1708
|
updated_at: string | null;
|
|
1703
1709
|
}
|
|
1710
|
+
type V2WebhookEventType = "content.created" | "content.updated" | "content.published" | "content.unpublished" | "content.deleted" | "newsletter.created" | "newsletter.updated" | "newsletter.published" | "newsletter.sent" | "newsletter.deleted" | "product.created" | "product.updated" | "product.deleted" | "product.stock_changed" | "order.paid" | "category.created" | "category.updated" | "category.deleted" | "site.updated" | "site.settings_changed" | "ab.flag_started" | "ab.flag_paused" | "ab.flag_resumed" | "ab.flag_stopped" | "ab.flag_updated" | "ab.config_warmup" | (string & Record<never, never>);
|
|
1704
1711
|
interface V2Webhook extends V2Object {
|
|
1705
1712
|
object: "webhook";
|
|
1706
1713
|
url: string;
|
|
1707
1714
|
description: string | null;
|
|
1708
|
-
events:
|
|
1715
|
+
events: V2WebhookEventType[] | null;
|
|
1709
1716
|
is_active: boolean;
|
|
1710
1717
|
created_at: string | null;
|
|
1711
1718
|
updated_at: string | null;
|
|
@@ -1713,7 +1720,7 @@ interface V2Webhook extends V2Object {
|
|
|
1713
1720
|
interface V2WebhookCreateParams {
|
|
1714
1721
|
url: string;
|
|
1715
1722
|
description?: string;
|
|
1716
|
-
events?:
|
|
1723
|
+
events?: V2WebhookEventType[];
|
|
1717
1724
|
is_active?: boolean;
|
|
1718
1725
|
}
|
|
1719
1726
|
interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
|
|
@@ -1967,13 +1974,14 @@ declare class SiteUsersV2Client extends BaseV2Client {
|
|
|
1967
1974
|
list(siteName: string, params?: V2SiteUserListParams): Promise<V2List<V2SiteUser>>;
|
|
1968
1975
|
listAutoPaginated(siteName: string, params?: Omit<V2SiteUserListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2SiteUser, void, unknown>;
|
|
1969
1976
|
get(siteName: string, id: string): Promise<V2SiteUser>;
|
|
1977
|
+
getProfileForUser(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2SiteUserProfile>;
|
|
1970
1978
|
update(siteName: string, id: string, data: V2SiteUserUpdateParams): Promise<V2SiteUser>;
|
|
1971
1979
|
/**
|
|
1972
1980
|
* Load the currently-authenticated site user's canonical record plus their
|
|
1973
1981
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
1974
1982
|
* the token returned from `verifyOtp`.
|
|
1975
1983
|
*/
|
|
1976
|
-
getMe(siteName: string): Promise<V2SiteUserWithProfile>;
|
|
1984
|
+
getMe(siteName: string, cachePolicy?: CachePolicy): Promise<V2SiteUserWithProfile>;
|
|
1977
1985
|
/** Update the authenticated user's own fields. */
|
|
1978
1986
|
updateMe(siteName: string, data: V2SiteUserMeUpdateParams): Promise<V2SiteUser>;
|
|
1979
1987
|
/** Fetch the profile KV map as a dedicated `site_user_profile` envelope. */
|
|
@@ -2143,9 +2151,9 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2143
2151
|
|
|
2144
2152
|
declare class CreditsV2Client extends BaseV2Client {
|
|
2145
2153
|
/** Get the current credit balance for the authenticated user. */
|
|
2146
|
-
getMyBalance(siteName: string): Promise<V2CreditBalance>;
|
|
2154
|
+
getMyBalance(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2147
2155
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
2148
|
-
getMyCredits(siteName: string): Promise<V2CreditBalance>;
|
|
2156
|
+
getMyCredits(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2149
2157
|
/** Get the credit balance for a specific user (admin). */
|
|
2150
2158
|
getUserBalance(siteName: string, userId: string): Promise<V2CreditBalance>;
|
|
2151
2159
|
/** Grant credit to a specific user (admin). */
|
|
@@ -4534,4 +4542,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4534
4542
|
error: string;
|
|
4535
4543
|
}>;
|
|
4536
4544
|
|
|
4537
|
-
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 V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, 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 };
|
|
4545
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -741,12 +741,13 @@ interface CreatePaymentGatewayRequest {
|
|
|
741
741
|
configuration: Record<string, any>;
|
|
742
742
|
isActive?: boolean;
|
|
743
743
|
}
|
|
744
|
+
type WebhookEventType = "content.created" | "content.updated" | "content.published" | "content.unpublished" | "content.deleted" | "newsletter.created" | "newsletter.updated" | "newsletter.published" | "newsletter.sent" | "newsletter.deleted" | "product.created" | "product.updated" | "product.deleted" | "product.stock_changed" | "order.paid" | "category.created" | "category.updated" | "category.deleted" | "site.updated" | "site.settings_changed" | "ab.flag_started" | "ab.flag_paused" | "ab.flag_resumed" | "ab.flag_stopped" | "ab.flag_updated" | "ab.config_warmup" | (string & Record<never, never>);
|
|
744
745
|
interface Webhook {
|
|
745
746
|
id: string;
|
|
746
747
|
name: string;
|
|
747
748
|
url: string;
|
|
748
749
|
provider: string;
|
|
749
|
-
events:
|
|
750
|
+
events: WebhookEventType[];
|
|
750
751
|
isActive: boolean;
|
|
751
752
|
secret?: string;
|
|
752
753
|
organizationId?: number;
|
|
@@ -757,7 +758,7 @@ interface CreateWebhookRequest {
|
|
|
757
758
|
name: string;
|
|
758
759
|
url: string;
|
|
759
760
|
provider: string;
|
|
760
|
-
events:
|
|
761
|
+
events: WebhookEventType[];
|
|
761
762
|
isActive?: boolean;
|
|
762
763
|
secret?: string;
|
|
763
764
|
}
|
|
@@ -1125,6 +1126,11 @@ declare class HttpClient {
|
|
|
1125
1126
|
* Update API key
|
|
1126
1127
|
*/
|
|
1127
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;
|
|
1128
1134
|
/**
|
|
1129
1135
|
* Remove authentication
|
|
1130
1136
|
*/
|
|
@@ -1701,11 +1707,12 @@ interface V2ApiKey extends V2Object {
|
|
|
1701
1707
|
created_at: string | null;
|
|
1702
1708
|
updated_at: string | null;
|
|
1703
1709
|
}
|
|
1710
|
+
type V2WebhookEventType = "content.created" | "content.updated" | "content.published" | "content.unpublished" | "content.deleted" | "newsletter.created" | "newsletter.updated" | "newsletter.published" | "newsletter.sent" | "newsletter.deleted" | "product.created" | "product.updated" | "product.deleted" | "product.stock_changed" | "order.paid" | "category.created" | "category.updated" | "category.deleted" | "site.updated" | "site.settings_changed" | "ab.flag_started" | "ab.flag_paused" | "ab.flag_resumed" | "ab.flag_stopped" | "ab.flag_updated" | "ab.config_warmup" | (string & Record<never, never>);
|
|
1704
1711
|
interface V2Webhook extends V2Object {
|
|
1705
1712
|
object: "webhook";
|
|
1706
1713
|
url: string;
|
|
1707
1714
|
description: string | null;
|
|
1708
|
-
events:
|
|
1715
|
+
events: V2WebhookEventType[] | null;
|
|
1709
1716
|
is_active: boolean;
|
|
1710
1717
|
created_at: string | null;
|
|
1711
1718
|
updated_at: string | null;
|
|
@@ -1713,7 +1720,7 @@ interface V2Webhook extends V2Object {
|
|
|
1713
1720
|
interface V2WebhookCreateParams {
|
|
1714
1721
|
url: string;
|
|
1715
1722
|
description?: string;
|
|
1716
|
-
events?:
|
|
1723
|
+
events?: V2WebhookEventType[];
|
|
1717
1724
|
is_active?: boolean;
|
|
1718
1725
|
}
|
|
1719
1726
|
interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
|
|
@@ -1967,13 +1974,14 @@ declare class SiteUsersV2Client extends BaseV2Client {
|
|
|
1967
1974
|
list(siteName: string, params?: V2SiteUserListParams): Promise<V2List<V2SiteUser>>;
|
|
1968
1975
|
listAutoPaginated(siteName: string, params?: Omit<V2SiteUserListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2SiteUser, void, unknown>;
|
|
1969
1976
|
get(siteName: string, id: string): Promise<V2SiteUser>;
|
|
1977
|
+
getProfileForUser(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2SiteUserProfile>;
|
|
1970
1978
|
update(siteName: string, id: string, data: V2SiteUserUpdateParams): Promise<V2SiteUser>;
|
|
1971
1979
|
/**
|
|
1972
1980
|
* Load the currently-authenticated site user's canonical record plus their
|
|
1973
1981
|
* profile KV map. Requires `client.setAuth(jwt)` to have been called with
|
|
1974
1982
|
* the token returned from `verifyOtp`.
|
|
1975
1983
|
*/
|
|
1976
|
-
getMe(siteName: string): Promise<V2SiteUserWithProfile>;
|
|
1984
|
+
getMe(siteName: string, cachePolicy?: CachePolicy): Promise<V2SiteUserWithProfile>;
|
|
1977
1985
|
/** Update the authenticated user's own fields. */
|
|
1978
1986
|
updateMe(siteName: string, data: V2SiteUserMeUpdateParams): Promise<V2SiteUser>;
|
|
1979
1987
|
/** Fetch the profile KV map as a dedicated `site_user_profile` envelope. */
|
|
@@ -2143,9 +2151,9 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2143
2151
|
|
|
2144
2152
|
declare class CreditsV2Client extends BaseV2Client {
|
|
2145
2153
|
/** Get the current credit balance for the authenticated user. */
|
|
2146
|
-
getMyBalance(siteName: string): Promise<V2CreditBalance>;
|
|
2154
|
+
getMyBalance(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2147
2155
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
2148
|
-
getMyCredits(siteName: string): Promise<V2CreditBalance>;
|
|
2156
|
+
getMyCredits(siteName: string, cachePolicy?: CachePolicy): Promise<V2CreditBalance>;
|
|
2149
2157
|
/** Get the credit balance for a specific user (admin). */
|
|
2150
2158
|
getUserBalance(siteName: string, userId: string): Promise<V2CreditBalance>;
|
|
2151
2159
|
/** Grant credit to a specific user (admin). */
|
|
@@ -4534,4 +4542,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4534
4542
|
error: string;
|
|
4535
4543
|
}>;
|
|
4536
4544
|
|
|
4537
|
-
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 V2WebhookUpdateParams, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, 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 };
|
|
4545
|
+
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 };
|
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. */
|
|
@@ -1332,15 +1352,19 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1332
1352
|
var CreditsV2Client = class extends BaseV2Client {
|
|
1333
1353
|
// --- Authenticated "me" endpoints (site-user JWT) ---
|
|
1334
1354
|
/** Get the current credit balance for the authenticated user. */
|
|
1335
|
-
async getMyBalance(siteName) {
|
|
1355
|
+
async getMyBalance(siteName, cachePolicy) {
|
|
1336
1356
|
return this.getOne(
|
|
1337
|
-
this.sitePath(siteName, "users", "me/credits/balance")
|
|
1357
|
+
this.sitePath(siteName, "users", "me/credits/balance"),
|
|
1358
|
+
void 0,
|
|
1359
|
+
{ ...cachePolicy, skipCache: true }
|
|
1338
1360
|
);
|
|
1339
1361
|
}
|
|
1340
1362
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
1341
|
-
async getMyCredits(siteName) {
|
|
1363
|
+
async getMyCredits(siteName, cachePolicy) {
|
|
1342
1364
|
return this.getOne(
|
|
1343
|
-
this.sitePath(siteName, "users", "me/credits")
|
|
1365
|
+
this.sitePath(siteName, "users", "me/credits"),
|
|
1366
|
+
void 0,
|
|
1367
|
+
{ ...cachePolicy, skipCache: true }
|
|
1344
1368
|
);
|
|
1345
1369
|
}
|
|
1346
1370
|
// --- Admin endpoints (API key) ---
|
|
@@ -1488,7 +1512,8 @@ var BaseClient = class {
|
|
|
1488
1512
|
* Fetch a GET endpoint with optional caching support.
|
|
1489
1513
|
*/
|
|
1490
1514
|
async fetchWithCache(endpoint, params, tags, policy, fetcher) {
|
|
1491
|
-
|
|
1515
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
1516
|
+
if (!this.cache || hasBearerAuth) {
|
|
1492
1517
|
return fetcher();
|
|
1493
1518
|
}
|
|
1494
1519
|
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. */
|
|
@@ -1256,15 +1276,19 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1256
1276
|
var CreditsV2Client = class extends BaseV2Client {
|
|
1257
1277
|
// --- Authenticated "me" endpoints (site-user JWT) ---
|
|
1258
1278
|
/** Get the current credit balance for the authenticated user. */
|
|
1259
|
-
async getMyBalance(siteName) {
|
|
1279
|
+
async getMyBalance(siteName, cachePolicy) {
|
|
1260
1280
|
return this.getOne(
|
|
1261
|
-
this.sitePath(siteName, "users", "me/credits/balance")
|
|
1281
|
+
this.sitePath(siteName, "users", "me/credits/balance"),
|
|
1282
|
+
void 0,
|
|
1283
|
+
{ ...cachePolicy, skipCache: true }
|
|
1262
1284
|
);
|
|
1263
1285
|
}
|
|
1264
1286
|
/** Get credit balance and transaction history for the authenticated user. */
|
|
1265
|
-
async getMyCredits(siteName) {
|
|
1287
|
+
async getMyCredits(siteName, cachePolicy) {
|
|
1266
1288
|
return this.getOne(
|
|
1267
|
-
this.sitePath(siteName, "users", "me/credits")
|
|
1289
|
+
this.sitePath(siteName, "users", "me/credits"),
|
|
1290
|
+
void 0,
|
|
1291
|
+
{ ...cachePolicy, skipCache: true }
|
|
1268
1292
|
);
|
|
1269
1293
|
}
|
|
1270
1294
|
// --- Admin endpoints (API key) ---
|
|
@@ -1412,7 +1436,8 @@ var BaseClient = class {
|
|
|
1412
1436
|
* Fetch a GET endpoint with optional caching support.
|
|
1413
1437
|
*/
|
|
1414
1438
|
async fetchWithCache(endpoint, params, tags, policy, fetcher) {
|
|
1415
|
-
|
|
1439
|
+
const hasBearerAuth = typeof this.http.hasBearerAuth === "function" && this.http.hasBearerAuth();
|
|
1440
|
+
if (!this.cache || hasBearerAuth) {
|
|
1416
1441
|
return fetcher();
|
|
1417
1442
|
}
|
|
1418
1443
|
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/types/index.ts
CHANGED
|
@@ -732,12 +732,41 @@ export interface CreatePaymentGatewayRequest {
|
|
|
732
732
|
}
|
|
733
733
|
|
|
734
734
|
// Webhooks
|
|
735
|
+
export type WebhookEventType =
|
|
736
|
+
| "content.created"
|
|
737
|
+
| "content.updated"
|
|
738
|
+
| "content.published"
|
|
739
|
+
| "content.unpublished"
|
|
740
|
+
| "content.deleted"
|
|
741
|
+
| "newsletter.created"
|
|
742
|
+
| "newsletter.updated"
|
|
743
|
+
| "newsletter.published"
|
|
744
|
+
| "newsletter.sent"
|
|
745
|
+
| "newsletter.deleted"
|
|
746
|
+
| "product.created"
|
|
747
|
+
| "product.updated"
|
|
748
|
+
| "product.deleted"
|
|
749
|
+
| "product.stock_changed"
|
|
750
|
+
| "order.paid"
|
|
751
|
+
| "category.created"
|
|
752
|
+
| "category.updated"
|
|
753
|
+
| "category.deleted"
|
|
754
|
+
| "site.updated"
|
|
755
|
+
| "site.settings_changed"
|
|
756
|
+
| "ab.flag_started"
|
|
757
|
+
| "ab.flag_paused"
|
|
758
|
+
| "ab.flag_resumed"
|
|
759
|
+
| "ab.flag_stopped"
|
|
760
|
+
| "ab.flag_updated"
|
|
761
|
+
| "ab.config_warmup"
|
|
762
|
+
| (string & Record<never, never>);
|
|
763
|
+
|
|
735
764
|
export interface Webhook {
|
|
736
765
|
id: string;
|
|
737
766
|
name: string;
|
|
738
767
|
url: string;
|
|
739
768
|
provider: string;
|
|
740
|
-
events:
|
|
769
|
+
events: WebhookEventType[];
|
|
741
770
|
isActive: boolean;
|
|
742
771
|
secret?: string;
|
|
743
772
|
organizationId?: number;
|
|
@@ -749,7 +778,7 @@ export interface CreateWebhookRequest {
|
|
|
749
778
|
name: string;
|
|
750
779
|
url: string;
|
|
751
780
|
provider: string;
|
|
752
|
-
events:
|
|
781
|
+
events: WebhookEventType[];
|
|
753
782
|
isActive?: boolean;
|
|
754
783
|
secret?: string;
|
|
755
784
|
}
|
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
|
|
package/src/v2/types.ts
CHANGED
|
@@ -603,11 +603,40 @@ export interface V2ApiKey extends V2Object {
|
|
|
603
603
|
|
|
604
604
|
// --- Webhooks ---
|
|
605
605
|
|
|
606
|
+
export type V2WebhookEventType =
|
|
607
|
+
| "content.created"
|
|
608
|
+
| "content.updated"
|
|
609
|
+
| "content.published"
|
|
610
|
+
| "content.unpublished"
|
|
611
|
+
| "content.deleted"
|
|
612
|
+
| "newsletter.created"
|
|
613
|
+
| "newsletter.updated"
|
|
614
|
+
| "newsletter.published"
|
|
615
|
+
| "newsletter.sent"
|
|
616
|
+
| "newsletter.deleted"
|
|
617
|
+
| "product.created"
|
|
618
|
+
| "product.updated"
|
|
619
|
+
| "product.deleted"
|
|
620
|
+
| "product.stock_changed"
|
|
621
|
+
| "order.paid"
|
|
622
|
+
| "category.created"
|
|
623
|
+
| "category.updated"
|
|
624
|
+
| "category.deleted"
|
|
625
|
+
| "site.updated"
|
|
626
|
+
| "site.settings_changed"
|
|
627
|
+
| "ab.flag_started"
|
|
628
|
+
| "ab.flag_paused"
|
|
629
|
+
| "ab.flag_resumed"
|
|
630
|
+
| "ab.flag_stopped"
|
|
631
|
+
| "ab.flag_updated"
|
|
632
|
+
| "ab.config_warmup"
|
|
633
|
+
| (string & Record<never, never>);
|
|
634
|
+
|
|
606
635
|
export interface V2Webhook extends V2Object {
|
|
607
636
|
object: "webhook";
|
|
608
637
|
url: string;
|
|
609
638
|
description: string | null;
|
|
610
|
-
events:
|
|
639
|
+
events: V2WebhookEventType[] | null;
|
|
611
640
|
is_active: boolean;
|
|
612
641
|
created_at: string | null;
|
|
613
642
|
updated_at: string | null;
|
|
@@ -616,7 +645,7 @@ export interface V2Webhook extends V2Object {
|
|
|
616
645
|
export interface V2WebhookCreateParams {
|
|
617
646
|
url: string;
|
|
618
647
|
description?: string;
|
|
619
|
-
events?:
|
|
648
|
+
events?: V2WebhookEventType[];
|
|
620
649
|
is_active?: boolean;
|
|
621
650
|
}
|
|
622
651
|
|