perspectapi-ts-sdk 5.0.3 → 5.2.0
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 +68 -21
- package/dist/index.d.ts +68 -21
- package/dist/index.js +124 -47
- package/dist/index.mjs +123 -47
- package/package.json +1 -1
- package/src/cache/cloudflare-kv-adapter.ts +58 -0
- package/src/index.ts +1 -0
- package/src/v2/client/base-v2-client.ts +55 -9
- package/src/v2/client/categories-client.ts +5 -4
- package/src/v2/client/content-client.ts +5 -4
- package/src/v2/client/newsletter-client.ts +14 -3
- package/src/v2/client/orders-client.ts +5 -4
- package/src/v2/client/products-client.ts +5 -4
- package/src/v2/index.ts +22 -13
- package/src/v2/types.ts +1 -0
package/dist/index.d.mts
CHANGED
|
@@ -3139,6 +3139,7 @@ interface V2ContentListParams extends V2PaginationParams {
|
|
|
3139
3139
|
type?: "post" | "page" | "block";
|
|
3140
3140
|
search?: string;
|
|
3141
3141
|
slug_prefix?: string;
|
|
3142
|
+
category?: string;
|
|
3142
3143
|
}
|
|
3143
3144
|
interface V2Product extends V2Object {
|
|
3144
3145
|
object: "product";
|
|
@@ -3410,7 +3411,7 @@ interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
|
|
|
3410
3411
|
}
|
|
3411
3412
|
|
|
3412
3413
|
/**
|
|
3413
|
-
* v2 Base Client — cursor pagination, expand support, typed errors.
|
|
3414
|
+
* v2 Base Client — cursor pagination, expand support, caching, typed errors.
|
|
3414
3415
|
*/
|
|
3415
3416
|
|
|
3416
3417
|
declare class PerspectV2Error extends Error {
|
|
@@ -3423,7 +3424,8 @@ declare class PerspectV2Error extends Error {
|
|
|
3423
3424
|
declare abstract class BaseV2Client {
|
|
3424
3425
|
protected http: HttpClient;
|
|
3425
3426
|
protected basePath: string;
|
|
3426
|
-
|
|
3427
|
+
protected cache?: CacheManager;
|
|
3428
|
+
constructor(http: HttpClient, basePath: string, cache?: CacheManager);
|
|
3427
3429
|
protected buildPath(endpoint: string): string;
|
|
3428
3430
|
protected sitePath(siteName: string, resource: string, suffix?: string): string;
|
|
3429
3431
|
private toParams;
|
|
@@ -3439,16 +3441,21 @@ declare abstract class BaseV2Client {
|
|
|
3439
3441
|
* We unwrap accordingly.
|
|
3440
3442
|
*/
|
|
3441
3443
|
private extractData;
|
|
3442
|
-
/** GET a single resource. */
|
|
3443
|
-
protected getOne<T>(path: string, params?: object): Promise<T>;
|
|
3444
|
-
/** GET a list of resources with cursor pagination. */
|
|
3445
|
-
protected getList<T>(path: string, params?: object): Promise<V2List<T>>;
|
|
3444
|
+
/** GET a single resource, with optional caching. */
|
|
3445
|
+
protected getOne<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<T>;
|
|
3446
|
+
/** GET a list of resources with cursor pagination, with optional caching. */
|
|
3447
|
+
protected getList<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<V2List<T>>;
|
|
3446
3448
|
/** POST to create a resource. */
|
|
3447
3449
|
protected post<T>(path: string, body?: unknown): Promise<T>;
|
|
3448
3450
|
/** PATCH to update a resource. */
|
|
3449
3451
|
protected patchOne<T>(path: string, body?: unknown): Promise<T>;
|
|
3450
3452
|
/** DELETE a resource. */
|
|
3451
3453
|
protected deleteOne(path: string): Promise<V2Deleted>;
|
|
3454
|
+
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
3455
|
+
private fetchWithCache;
|
|
3456
|
+
/** Invalidate cache entries by keys or tags. */
|
|
3457
|
+
protected invalidateCache(options: CacheInvalidateOptions): Promise<void>;
|
|
3458
|
+
private buildCacheKey;
|
|
3452
3459
|
/**
|
|
3453
3460
|
* Auto-paginating async generator.
|
|
3454
3461
|
* Yields every item across all pages.
|
|
@@ -3467,9 +3474,9 @@ declare abstract class BaseV2Client {
|
|
|
3467
3474
|
*/
|
|
3468
3475
|
|
|
3469
3476
|
declare class ContentV2Client extends BaseV2Client {
|
|
3470
|
-
list(siteName: string, params?: V2ContentListParams): Promise<V2List<V2Content>>;
|
|
3477
|
+
list(siteName: string, params?: V2ContentListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Content>>;
|
|
3471
3478
|
listAutoPaginated(siteName: string, params?: Omit<V2ContentListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Content, void, unknown>;
|
|
3472
|
-
get(siteName: string, idOrSlug: string): Promise<V2Content>;
|
|
3479
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Content>;
|
|
3473
3480
|
create(siteName: string, data: V2ContentCreateParams): Promise<V2Content>;
|
|
3474
3481
|
update(siteName: string, id: string, data: V2ContentUpdateParams): Promise<V2Content>;
|
|
3475
3482
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3482,9 +3489,9 @@ declare class ContentV2Client extends BaseV2Client {
|
|
|
3482
3489
|
*/
|
|
3483
3490
|
|
|
3484
3491
|
declare class ProductsV2Client extends BaseV2Client {
|
|
3485
|
-
list(siteName: string, params?: V2ProductListParams): Promise<V2List<V2Product>>;
|
|
3492
|
+
list(siteName: string, params?: V2ProductListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Product>>;
|
|
3486
3493
|
listAutoPaginated(siteName: string, params?: Omit<V2ProductListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Product, void, unknown>;
|
|
3487
|
-
get(siteName: string, idOrSlug: string): Promise<V2Product>;
|
|
3494
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Product>;
|
|
3488
3495
|
create(siteName: string, data: V2ProductCreateParams): Promise<V2Product>;
|
|
3489
3496
|
update(siteName: string, id: string, data: V2ProductUpdateParams): Promise<V2Product>;
|
|
3490
3497
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3497,8 +3504,8 @@ declare class ProductsV2Client extends BaseV2Client {
|
|
|
3497
3504
|
declare class CategoriesV2Client extends BaseV2Client {
|
|
3498
3505
|
list(siteName: string, params?: V2PaginationParams & {
|
|
3499
3506
|
type?: string;
|
|
3500
|
-
}): Promise<V2List<V2Category>>;
|
|
3501
|
-
get(siteName: string, id: string): Promise<V2Category>;
|
|
3507
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2Category>>;
|
|
3508
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Category>;
|
|
3502
3509
|
create(siteName: string, data: V2CategoryCreateParams): Promise<V2Category>;
|
|
3503
3510
|
update(siteName: string, id: string, data: V2CategoryUpdateParams): Promise<V2Category>;
|
|
3504
3511
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3529,9 +3536,9 @@ declare class CollectionsV2Client extends BaseV2Client {
|
|
|
3529
3536
|
*/
|
|
3530
3537
|
|
|
3531
3538
|
declare class OrdersV2Client extends BaseV2Client {
|
|
3532
|
-
list(siteName: string, params?: V2OrderListParams): Promise<V2List<V2Order>>;
|
|
3539
|
+
list(siteName: string, params?: V2OrderListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Order>>;
|
|
3533
3540
|
listAutoPaginated(siteName: string, params?: Omit<V2OrderListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Order, void, unknown>;
|
|
3534
|
-
get(siteName: string, id: string): Promise<V2Order>;
|
|
3541
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Order>;
|
|
3535
3542
|
}
|
|
3536
3543
|
|
|
3537
3544
|
/**
|
|
@@ -3588,13 +3595,13 @@ declare class NewsletterV2Client extends BaseV2Client {
|
|
|
3588
3595
|
trackClick(siteName: string, token: string, url: string): Promise<V2NewsletterTrackingResponse>;
|
|
3589
3596
|
listSubscriptions(siteName: string, params?: V2PaginationParams & {
|
|
3590
3597
|
status?: string;
|
|
3591
|
-
}): Promise<V2List<V2NewsletterSubscription>>;
|
|
3592
|
-
getSubscription(siteName: string, id: string): Promise<V2NewsletterSubscription>;
|
|
3593
|
-
listLists(siteName: string): Promise<V2List<V2NewsletterList>>;
|
|
3598
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterSubscription>>;
|
|
3599
|
+
getSubscription(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2NewsletterSubscription>;
|
|
3600
|
+
listLists(siteName: string, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterList>>;
|
|
3594
3601
|
listCampaigns(siteName: string, params?: V2PaginationParams & {
|
|
3595
3602
|
status?: string;
|
|
3596
|
-
}): Promise<V2List<V2NewsletterCampaign>>;
|
|
3597
|
-
getCampaign(siteName: string, idOrSlug: string): Promise<V2NewsletterCampaign>;
|
|
3603
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterCampaign>>;
|
|
3604
|
+
getCampaign(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2NewsletterCampaign>;
|
|
3598
3605
|
}
|
|
3599
3606
|
|
|
3600
3607
|
/**
|
|
@@ -3671,8 +3678,12 @@ declare class WebhooksV2Client extends BaseV2Client {
|
|
|
3671
3678
|
* const posts = await client.content.list('mysite', { type: 'post', limit: 10 });
|
|
3672
3679
|
*/
|
|
3673
3680
|
|
|
3681
|
+
interface PerspectApiV2Config extends PerspectApiConfig {
|
|
3682
|
+
cache?: CacheConfig;
|
|
3683
|
+
}
|
|
3674
3684
|
declare class PerspectApiV2Client {
|
|
3675
3685
|
private http;
|
|
3686
|
+
readonly cache: CacheManager;
|
|
3676
3687
|
readonly content: ContentV2Client;
|
|
3677
3688
|
readonly products: ProductsV2Client;
|
|
3678
3689
|
readonly categories: CategoriesV2Client;
|
|
@@ -3685,7 +3696,7 @@ declare class PerspectApiV2Client {
|
|
|
3685
3696
|
readonly sites: SitesV2Client;
|
|
3686
3697
|
readonly apiKeys: ApiKeysV2Client;
|
|
3687
3698
|
readonly webhooks: WebhooksV2Client;
|
|
3688
|
-
constructor(config:
|
|
3699
|
+
constructor(config: PerspectApiV2Config);
|
|
3689
3700
|
/** Update the JWT token for authenticated requests. */
|
|
3690
3701
|
setAuth(jwt: string): void;
|
|
3691
3702
|
/** Update the API key. */
|
|
@@ -3695,6 +3706,42 @@ declare class PerspectApiV2Client {
|
|
|
3695
3706
|
}
|
|
3696
3707
|
declare function createPerspectApiV2Client(config: PerspectApiConfig): PerspectApiV2Client;
|
|
3697
3708
|
|
|
3709
|
+
/**
|
|
3710
|
+
* Adapter that bridges a CacheStorage-compatible KV implementation
|
|
3711
|
+
* (e.g. CloudflareKvAdapter from @perspect/shared) to the SDK's CacheAdapter interface.
|
|
3712
|
+
*
|
|
3713
|
+
* Usage:
|
|
3714
|
+
* import { CloudflareKvAdapter } from '@perspect/shared';
|
|
3715
|
+
* import { CloudflareKVCacheAdapter } from 'perspectapi-ts-sdk';
|
|
3716
|
+
*
|
|
3717
|
+
* const kvAdapter = new CloudflareKvAdapter(env.CACHE_KV);
|
|
3718
|
+
* const cacheAdapter = new CloudflareKVCacheAdapter(kvAdapter);
|
|
3719
|
+
*
|
|
3720
|
+
* Or pass any object with get/put/delete methods matching Cloudflare KV semantics.
|
|
3721
|
+
*/
|
|
3722
|
+
|
|
3723
|
+
/** Minimal interface matching CloudflareKvAdapter / CacheStorage from @perspect/shared. */
|
|
3724
|
+
interface KVLike {
|
|
3725
|
+
get(key: string): Promise<string | null>;
|
|
3726
|
+
put(key: string, value: string, options?: {
|
|
3727
|
+
expirationTtl?: number;
|
|
3728
|
+
}): Promise<void>;
|
|
3729
|
+
delete(key: string): Promise<void>;
|
|
3730
|
+
deleteMultiple?(keys: string[]): Promise<void>;
|
|
3731
|
+
clear?(): Promise<void>;
|
|
3732
|
+
}
|
|
3733
|
+
declare class CloudflareKVCacheAdapter implements CacheAdapter {
|
|
3734
|
+
private kv;
|
|
3735
|
+
constructor(kv: KVLike);
|
|
3736
|
+
get(key: string): Promise<string | null>;
|
|
3737
|
+
set(key: string, value: string, options?: {
|
|
3738
|
+
ttlSeconds?: number;
|
|
3739
|
+
}): Promise<void>;
|
|
3740
|
+
delete(key: string): Promise<void>;
|
|
3741
|
+
deleteMany(keys: string[]): Promise<void>;
|
|
3742
|
+
clear(): Promise<void>;
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3698
3745
|
/**
|
|
3699
3746
|
* Simple in-memory cache adapter primarily suited for development and testing.
|
|
3700
3747
|
*/
|
|
@@ -4013,4 +4060,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4013
4060
|
error: string;
|
|
4014
4061
|
}>;
|
|
4015
4062
|
|
|
4016
|
-
export { type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheConfig, CacheManager, type CancelSubscriptionRequest, type CancelSubscriptionResponse, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateBundleCollectionRequest, type CreateBundleGroupRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateProductSkuRequest, type CreateSiteRequest, type CreateWebhookRequest, type CreditBalance, type CreditBalanceWithTransactions, type CreditTransaction, DEFAULT_IMAGE_SIZES, type GrantCreditRequest, HttpClient, type HttpMethod, type ImageTransformOptions, InMemoryCacheAdapter, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type NewsletterCampaignDetail, type NewsletterCampaignListResponse, type NewsletterCampaignSummary, type NewsletterCampaignTestSendRequest, type NewsletterCampaignTestSendResponse, NewsletterClient, type NewsletterConfirmResponse, type NewsletterExportCreateRequest, type NewsletterExportCreateResponse, type NewsletterList, type NewsletterManagementCampaign, type NewsletterManagementCampaignListResponse, NewsletterManagementClient, type NewsletterManagementList, type NewsletterManagementListMembership, type NewsletterManagementPagination, type NewsletterManagementSeries, type NewsletterManagementStatsResponse, type NewsletterManagementSubscription, type NewsletterManagementSubscriptionsListResponse, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterSubscriptionImportRowRequest, type NewsletterSubscriptionMembershipUpdateRequest, type NewsletterSubscriptionSyncRequest, type NewsletterSubscriptionSyncResponse, type NewsletterSubscriptionsBulkAction, type NewsletterSubscriptionsBulkOutcome, type NewsletterSubscriptionsBulkUpdateRequest, type NewsletterSubscriptionsBulkUpdateResponse, type NewsletterSubscriptionsImportRequest, type NewsletterSubscriptionsImportResponse, type NewsletterSubscriptionsImportRowResult, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, PerspectApiV2Client, PerspectV2Error, type Product, type ProductBundleGroup, type ProductQueryParams, type ProductSku, type ProductSkuMediaItem, type ProductSkuOption, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type SubscriptionCancellationMode, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
|
|
4063
|
+
export { type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheConfig, CacheManager, type CancelSubscriptionRequest, type CancelSubscriptionResponse, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, CloudflareKVCacheAdapter, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateBundleCollectionRequest, type CreateBundleGroupRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateProductSkuRequest, type CreateSiteRequest, type CreateWebhookRequest, type CreditBalance, type CreditBalanceWithTransactions, type CreditTransaction, DEFAULT_IMAGE_SIZES, type GrantCreditRequest, HttpClient, type HttpMethod, type ImageTransformOptions, InMemoryCacheAdapter, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type NewsletterCampaignDetail, type NewsletterCampaignListResponse, type NewsletterCampaignSummary, type NewsletterCampaignTestSendRequest, type NewsletterCampaignTestSendResponse, NewsletterClient, type NewsletterConfirmResponse, type NewsletterExportCreateRequest, type NewsletterExportCreateResponse, type NewsletterList, type NewsletterManagementCampaign, type NewsletterManagementCampaignListResponse, NewsletterManagementClient, type NewsletterManagementList, type NewsletterManagementListMembership, type NewsletterManagementPagination, type NewsletterManagementSeries, type NewsletterManagementStatsResponse, type NewsletterManagementSubscription, type NewsletterManagementSubscriptionsListResponse, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterSubscriptionImportRowRequest, type NewsletterSubscriptionMembershipUpdateRequest, type NewsletterSubscriptionSyncRequest, type NewsletterSubscriptionSyncResponse, type NewsletterSubscriptionsBulkAction, type NewsletterSubscriptionsBulkOutcome, type NewsletterSubscriptionsBulkUpdateRequest, type NewsletterSubscriptionsBulkUpdateResponse, type NewsletterSubscriptionsImportRequest, type NewsletterSubscriptionsImportResponse, type NewsletterSubscriptionsImportRowResult, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, PerspectApiV2Client, PerspectV2Error, type Product, type ProductBundleGroup, type ProductQueryParams, type ProductSku, type ProductSkuMediaItem, type ProductSkuOption, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type SubscriptionCancellationMode, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
|
package/dist/index.d.ts
CHANGED
|
@@ -3139,6 +3139,7 @@ interface V2ContentListParams extends V2PaginationParams {
|
|
|
3139
3139
|
type?: "post" | "page" | "block";
|
|
3140
3140
|
search?: string;
|
|
3141
3141
|
slug_prefix?: string;
|
|
3142
|
+
category?: string;
|
|
3142
3143
|
}
|
|
3143
3144
|
interface V2Product extends V2Object {
|
|
3144
3145
|
object: "product";
|
|
@@ -3410,7 +3411,7 @@ interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
|
|
|
3410
3411
|
}
|
|
3411
3412
|
|
|
3412
3413
|
/**
|
|
3413
|
-
* v2 Base Client — cursor pagination, expand support, typed errors.
|
|
3414
|
+
* v2 Base Client — cursor pagination, expand support, caching, typed errors.
|
|
3414
3415
|
*/
|
|
3415
3416
|
|
|
3416
3417
|
declare class PerspectV2Error extends Error {
|
|
@@ -3423,7 +3424,8 @@ declare class PerspectV2Error extends Error {
|
|
|
3423
3424
|
declare abstract class BaseV2Client {
|
|
3424
3425
|
protected http: HttpClient;
|
|
3425
3426
|
protected basePath: string;
|
|
3426
|
-
|
|
3427
|
+
protected cache?: CacheManager;
|
|
3428
|
+
constructor(http: HttpClient, basePath: string, cache?: CacheManager);
|
|
3427
3429
|
protected buildPath(endpoint: string): string;
|
|
3428
3430
|
protected sitePath(siteName: string, resource: string, suffix?: string): string;
|
|
3429
3431
|
private toParams;
|
|
@@ -3439,16 +3441,21 @@ declare abstract class BaseV2Client {
|
|
|
3439
3441
|
* We unwrap accordingly.
|
|
3440
3442
|
*/
|
|
3441
3443
|
private extractData;
|
|
3442
|
-
/** GET a single resource. */
|
|
3443
|
-
protected getOne<T>(path: string, params?: object): Promise<T>;
|
|
3444
|
-
/** GET a list of resources with cursor pagination. */
|
|
3445
|
-
protected getList<T>(path: string, params?: object): Promise<V2List<T>>;
|
|
3444
|
+
/** GET a single resource, with optional caching. */
|
|
3445
|
+
protected getOne<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<T>;
|
|
3446
|
+
/** GET a list of resources with cursor pagination, with optional caching. */
|
|
3447
|
+
protected getList<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<V2List<T>>;
|
|
3446
3448
|
/** POST to create a resource. */
|
|
3447
3449
|
protected post<T>(path: string, body?: unknown): Promise<T>;
|
|
3448
3450
|
/** PATCH to update a resource. */
|
|
3449
3451
|
protected patchOne<T>(path: string, body?: unknown): Promise<T>;
|
|
3450
3452
|
/** DELETE a resource. */
|
|
3451
3453
|
protected deleteOne(path: string): Promise<V2Deleted>;
|
|
3454
|
+
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
3455
|
+
private fetchWithCache;
|
|
3456
|
+
/** Invalidate cache entries by keys or tags. */
|
|
3457
|
+
protected invalidateCache(options: CacheInvalidateOptions): Promise<void>;
|
|
3458
|
+
private buildCacheKey;
|
|
3452
3459
|
/**
|
|
3453
3460
|
* Auto-paginating async generator.
|
|
3454
3461
|
* Yields every item across all pages.
|
|
@@ -3467,9 +3474,9 @@ declare abstract class BaseV2Client {
|
|
|
3467
3474
|
*/
|
|
3468
3475
|
|
|
3469
3476
|
declare class ContentV2Client extends BaseV2Client {
|
|
3470
|
-
list(siteName: string, params?: V2ContentListParams): Promise<V2List<V2Content>>;
|
|
3477
|
+
list(siteName: string, params?: V2ContentListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Content>>;
|
|
3471
3478
|
listAutoPaginated(siteName: string, params?: Omit<V2ContentListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Content, void, unknown>;
|
|
3472
|
-
get(siteName: string, idOrSlug: string): Promise<V2Content>;
|
|
3479
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Content>;
|
|
3473
3480
|
create(siteName: string, data: V2ContentCreateParams): Promise<V2Content>;
|
|
3474
3481
|
update(siteName: string, id: string, data: V2ContentUpdateParams): Promise<V2Content>;
|
|
3475
3482
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3482,9 +3489,9 @@ declare class ContentV2Client extends BaseV2Client {
|
|
|
3482
3489
|
*/
|
|
3483
3490
|
|
|
3484
3491
|
declare class ProductsV2Client extends BaseV2Client {
|
|
3485
|
-
list(siteName: string, params?: V2ProductListParams): Promise<V2List<V2Product>>;
|
|
3492
|
+
list(siteName: string, params?: V2ProductListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Product>>;
|
|
3486
3493
|
listAutoPaginated(siteName: string, params?: Omit<V2ProductListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Product, void, unknown>;
|
|
3487
|
-
get(siteName: string, idOrSlug: string): Promise<V2Product>;
|
|
3494
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Product>;
|
|
3488
3495
|
create(siteName: string, data: V2ProductCreateParams): Promise<V2Product>;
|
|
3489
3496
|
update(siteName: string, id: string, data: V2ProductUpdateParams): Promise<V2Product>;
|
|
3490
3497
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3497,8 +3504,8 @@ declare class ProductsV2Client extends BaseV2Client {
|
|
|
3497
3504
|
declare class CategoriesV2Client extends BaseV2Client {
|
|
3498
3505
|
list(siteName: string, params?: V2PaginationParams & {
|
|
3499
3506
|
type?: string;
|
|
3500
|
-
}): Promise<V2List<V2Category>>;
|
|
3501
|
-
get(siteName: string, id: string): Promise<V2Category>;
|
|
3507
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2Category>>;
|
|
3508
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Category>;
|
|
3502
3509
|
create(siteName: string, data: V2CategoryCreateParams): Promise<V2Category>;
|
|
3503
3510
|
update(siteName: string, id: string, data: V2CategoryUpdateParams): Promise<V2Category>;
|
|
3504
3511
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3529,9 +3536,9 @@ declare class CollectionsV2Client extends BaseV2Client {
|
|
|
3529
3536
|
*/
|
|
3530
3537
|
|
|
3531
3538
|
declare class OrdersV2Client extends BaseV2Client {
|
|
3532
|
-
list(siteName: string, params?: V2OrderListParams): Promise<V2List<V2Order>>;
|
|
3539
|
+
list(siteName: string, params?: V2OrderListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Order>>;
|
|
3533
3540
|
listAutoPaginated(siteName: string, params?: Omit<V2OrderListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Order, void, unknown>;
|
|
3534
|
-
get(siteName: string, id: string): Promise<V2Order>;
|
|
3541
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Order>;
|
|
3535
3542
|
}
|
|
3536
3543
|
|
|
3537
3544
|
/**
|
|
@@ -3588,13 +3595,13 @@ declare class NewsletterV2Client extends BaseV2Client {
|
|
|
3588
3595
|
trackClick(siteName: string, token: string, url: string): Promise<V2NewsletterTrackingResponse>;
|
|
3589
3596
|
listSubscriptions(siteName: string, params?: V2PaginationParams & {
|
|
3590
3597
|
status?: string;
|
|
3591
|
-
}): Promise<V2List<V2NewsletterSubscription>>;
|
|
3592
|
-
getSubscription(siteName: string, id: string): Promise<V2NewsletterSubscription>;
|
|
3593
|
-
listLists(siteName: string): Promise<V2List<V2NewsletterList>>;
|
|
3598
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterSubscription>>;
|
|
3599
|
+
getSubscription(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2NewsletterSubscription>;
|
|
3600
|
+
listLists(siteName: string, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterList>>;
|
|
3594
3601
|
listCampaigns(siteName: string, params?: V2PaginationParams & {
|
|
3595
3602
|
status?: string;
|
|
3596
|
-
}): Promise<V2List<V2NewsletterCampaign>>;
|
|
3597
|
-
getCampaign(siteName: string, idOrSlug: string): Promise<V2NewsletterCampaign>;
|
|
3603
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterCampaign>>;
|
|
3604
|
+
getCampaign(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2NewsletterCampaign>;
|
|
3598
3605
|
}
|
|
3599
3606
|
|
|
3600
3607
|
/**
|
|
@@ -3671,8 +3678,12 @@ declare class WebhooksV2Client extends BaseV2Client {
|
|
|
3671
3678
|
* const posts = await client.content.list('mysite', { type: 'post', limit: 10 });
|
|
3672
3679
|
*/
|
|
3673
3680
|
|
|
3681
|
+
interface PerspectApiV2Config extends PerspectApiConfig {
|
|
3682
|
+
cache?: CacheConfig;
|
|
3683
|
+
}
|
|
3674
3684
|
declare class PerspectApiV2Client {
|
|
3675
3685
|
private http;
|
|
3686
|
+
readonly cache: CacheManager;
|
|
3676
3687
|
readonly content: ContentV2Client;
|
|
3677
3688
|
readonly products: ProductsV2Client;
|
|
3678
3689
|
readonly categories: CategoriesV2Client;
|
|
@@ -3685,7 +3696,7 @@ declare class PerspectApiV2Client {
|
|
|
3685
3696
|
readonly sites: SitesV2Client;
|
|
3686
3697
|
readonly apiKeys: ApiKeysV2Client;
|
|
3687
3698
|
readonly webhooks: WebhooksV2Client;
|
|
3688
|
-
constructor(config:
|
|
3699
|
+
constructor(config: PerspectApiV2Config);
|
|
3689
3700
|
/** Update the JWT token for authenticated requests. */
|
|
3690
3701
|
setAuth(jwt: string): void;
|
|
3691
3702
|
/** Update the API key. */
|
|
@@ -3695,6 +3706,42 @@ declare class PerspectApiV2Client {
|
|
|
3695
3706
|
}
|
|
3696
3707
|
declare function createPerspectApiV2Client(config: PerspectApiConfig): PerspectApiV2Client;
|
|
3697
3708
|
|
|
3709
|
+
/**
|
|
3710
|
+
* Adapter that bridges a CacheStorage-compatible KV implementation
|
|
3711
|
+
* (e.g. CloudflareKvAdapter from @perspect/shared) to the SDK's CacheAdapter interface.
|
|
3712
|
+
*
|
|
3713
|
+
* Usage:
|
|
3714
|
+
* import { CloudflareKvAdapter } from '@perspect/shared';
|
|
3715
|
+
* import { CloudflareKVCacheAdapter } from 'perspectapi-ts-sdk';
|
|
3716
|
+
*
|
|
3717
|
+
* const kvAdapter = new CloudflareKvAdapter(env.CACHE_KV);
|
|
3718
|
+
* const cacheAdapter = new CloudflareKVCacheAdapter(kvAdapter);
|
|
3719
|
+
*
|
|
3720
|
+
* Or pass any object with get/put/delete methods matching Cloudflare KV semantics.
|
|
3721
|
+
*/
|
|
3722
|
+
|
|
3723
|
+
/** Minimal interface matching CloudflareKvAdapter / CacheStorage from @perspect/shared. */
|
|
3724
|
+
interface KVLike {
|
|
3725
|
+
get(key: string): Promise<string | null>;
|
|
3726
|
+
put(key: string, value: string, options?: {
|
|
3727
|
+
expirationTtl?: number;
|
|
3728
|
+
}): Promise<void>;
|
|
3729
|
+
delete(key: string): Promise<void>;
|
|
3730
|
+
deleteMultiple?(keys: string[]): Promise<void>;
|
|
3731
|
+
clear?(): Promise<void>;
|
|
3732
|
+
}
|
|
3733
|
+
declare class CloudflareKVCacheAdapter implements CacheAdapter {
|
|
3734
|
+
private kv;
|
|
3735
|
+
constructor(kv: KVLike);
|
|
3736
|
+
get(key: string): Promise<string | null>;
|
|
3737
|
+
set(key: string, value: string, options?: {
|
|
3738
|
+
ttlSeconds?: number;
|
|
3739
|
+
}): Promise<void>;
|
|
3740
|
+
delete(key: string): Promise<void>;
|
|
3741
|
+
deleteMany(keys: string[]): Promise<void>;
|
|
3742
|
+
clear(): Promise<void>;
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3698
3745
|
/**
|
|
3699
3746
|
* Simple in-memory cache adapter primarily suited for development and testing.
|
|
3700
3747
|
*/
|
|
@@ -4013,4 +4060,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4013
4060
|
error: string;
|
|
4014
4061
|
}>;
|
|
4015
4062
|
|
|
4016
|
-
export { type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheConfig, CacheManager, type CancelSubscriptionRequest, type CancelSubscriptionResponse, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateBundleCollectionRequest, type CreateBundleGroupRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateProductSkuRequest, type CreateSiteRequest, type CreateWebhookRequest, type CreditBalance, type CreditBalanceWithTransactions, type CreditTransaction, DEFAULT_IMAGE_SIZES, type GrantCreditRequest, HttpClient, type HttpMethod, type ImageTransformOptions, InMemoryCacheAdapter, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type NewsletterCampaignDetail, type NewsletterCampaignListResponse, type NewsletterCampaignSummary, type NewsletterCampaignTestSendRequest, type NewsletterCampaignTestSendResponse, NewsletterClient, type NewsletterConfirmResponse, type NewsletterExportCreateRequest, type NewsletterExportCreateResponse, type NewsletterList, type NewsletterManagementCampaign, type NewsletterManagementCampaignListResponse, NewsletterManagementClient, type NewsletterManagementList, type NewsletterManagementListMembership, type NewsletterManagementPagination, type NewsletterManagementSeries, type NewsletterManagementStatsResponse, type NewsletterManagementSubscription, type NewsletterManagementSubscriptionsListResponse, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterSubscriptionImportRowRequest, type NewsletterSubscriptionMembershipUpdateRequest, type NewsletterSubscriptionSyncRequest, type NewsletterSubscriptionSyncResponse, type NewsletterSubscriptionsBulkAction, type NewsletterSubscriptionsBulkOutcome, type NewsletterSubscriptionsBulkUpdateRequest, type NewsletterSubscriptionsBulkUpdateResponse, type NewsletterSubscriptionsImportRequest, type NewsletterSubscriptionsImportResponse, type NewsletterSubscriptionsImportRowResult, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, PerspectApiV2Client, PerspectV2Error, type Product, type ProductBundleGroup, type ProductQueryParams, type ProductSku, type ProductSkuMediaItem, type ProductSkuOption, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type SubscriptionCancellationMode, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
|
|
4063
|
+
export { type AddCollectionItemRequest, type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, BaseClient, type BlogPost, type BundleCollection, type BundleCollectionItem, type BundleCollectionItemWithProduct, BundlesClient, type CacheConfig, CacheManager, type CancelSubscriptionRequest, type CancelSubscriptionResponse, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, CloudflareKVCacheAdapter, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateBundleCollectionRequest, type CreateBundleGroupRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateProductSkuRequest, type CreateSiteRequest, type CreateWebhookRequest, type CreditBalance, type CreditBalanceWithTransactions, type CreditTransaction, DEFAULT_IMAGE_SIZES, type GrantCreditRequest, HttpClient, type HttpMethod, type ImageTransformOptions, InMemoryCacheAdapter, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type NewsletterCampaignDetail, type NewsletterCampaignListResponse, type NewsletterCampaignSummary, type NewsletterCampaignTestSendRequest, type NewsletterCampaignTestSendResponse, NewsletterClient, type NewsletterConfirmResponse, type NewsletterExportCreateRequest, type NewsletterExportCreateResponse, type NewsletterList, type NewsletterManagementCampaign, type NewsletterManagementCampaignListResponse, NewsletterManagementClient, type NewsletterManagementList, type NewsletterManagementListMembership, type NewsletterManagementPagination, type NewsletterManagementSeries, type NewsletterManagementStatsResponse, type NewsletterManagementSubscription, type NewsletterManagementSubscriptionsListResponse, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterSubscriptionImportRowRequest, type NewsletterSubscriptionMembershipUpdateRequest, type NewsletterSubscriptionSyncRequest, type NewsletterSubscriptionSyncResponse, type NewsletterSubscriptionsBulkAction, type NewsletterSubscriptionsBulkOutcome, type NewsletterSubscriptionsBulkUpdateRequest, type NewsletterSubscriptionsBulkUpdateResponse, type NewsletterSubscriptionsImportRequest, type NewsletterSubscriptionsImportResponse, type NewsletterSubscriptionsImportRowResult, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, PerspectApiV2Client, PerspectV2Error, type Product, type ProductBundleGroup, type ProductQueryParams, type ProductSku, type ProductSkuMediaItem, type ProductSkuOption, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type SubscriptionCancellationMode, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, createPerspectApiV2Client, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
|