perspectapi-ts-sdk 5.0.3 → 5.1.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 +67 -21
- package/dist/index.d.ts +67 -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/dist/index.d.mts
CHANGED
|
@@ -3410,7 +3410,7 @@ interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
|
|
|
3410
3410
|
}
|
|
3411
3411
|
|
|
3412
3412
|
/**
|
|
3413
|
-
* v2 Base Client — cursor pagination, expand support, typed errors.
|
|
3413
|
+
* v2 Base Client — cursor pagination, expand support, caching, typed errors.
|
|
3414
3414
|
*/
|
|
3415
3415
|
|
|
3416
3416
|
declare class PerspectV2Error extends Error {
|
|
@@ -3423,7 +3423,8 @@ declare class PerspectV2Error extends Error {
|
|
|
3423
3423
|
declare abstract class BaseV2Client {
|
|
3424
3424
|
protected http: HttpClient;
|
|
3425
3425
|
protected basePath: string;
|
|
3426
|
-
|
|
3426
|
+
protected cache?: CacheManager;
|
|
3427
|
+
constructor(http: HttpClient, basePath: string, cache?: CacheManager);
|
|
3427
3428
|
protected buildPath(endpoint: string): string;
|
|
3428
3429
|
protected sitePath(siteName: string, resource: string, suffix?: string): string;
|
|
3429
3430
|
private toParams;
|
|
@@ -3439,16 +3440,21 @@ declare abstract class BaseV2Client {
|
|
|
3439
3440
|
* We unwrap accordingly.
|
|
3440
3441
|
*/
|
|
3441
3442
|
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>>;
|
|
3443
|
+
/** GET a single resource, with optional caching. */
|
|
3444
|
+
protected getOne<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<T>;
|
|
3445
|
+
/** GET a list of resources with cursor pagination, with optional caching. */
|
|
3446
|
+
protected getList<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<V2List<T>>;
|
|
3446
3447
|
/** POST to create a resource. */
|
|
3447
3448
|
protected post<T>(path: string, body?: unknown): Promise<T>;
|
|
3448
3449
|
/** PATCH to update a resource. */
|
|
3449
3450
|
protected patchOne<T>(path: string, body?: unknown): Promise<T>;
|
|
3450
3451
|
/** DELETE a resource. */
|
|
3451
3452
|
protected deleteOne(path: string): Promise<V2Deleted>;
|
|
3453
|
+
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
3454
|
+
private fetchWithCache;
|
|
3455
|
+
/** Invalidate cache entries by keys or tags. */
|
|
3456
|
+
protected invalidateCache(options: CacheInvalidateOptions): Promise<void>;
|
|
3457
|
+
private buildCacheKey;
|
|
3452
3458
|
/**
|
|
3453
3459
|
* Auto-paginating async generator.
|
|
3454
3460
|
* Yields every item across all pages.
|
|
@@ -3467,9 +3473,9 @@ declare abstract class BaseV2Client {
|
|
|
3467
3473
|
*/
|
|
3468
3474
|
|
|
3469
3475
|
declare class ContentV2Client extends BaseV2Client {
|
|
3470
|
-
list(siteName: string, params?: V2ContentListParams): Promise<V2List<V2Content>>;
|
|
3476
|
+
list(siteName: string, params?: V2ContentListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Content>>;
|
|
3471
3477
|
listAutoPaginated(siteName: string, params?: Omit<V2ContentListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Content, void, unknown>;
|
|
3472
|
-
get(siteName: string, idOrSlug: string): Promise<V2Content>;
|
|
3478
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Content>;
|
|
3473
3479
|
create(siteName: string, data: V2ContentCreateParams): Promise<V2Content>;
|
|
3474
3480
|
update(siteName: string, id: string, data: V2ContentUpdateParams): Promise<V2Content>;
|
|
3475
3481
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3482,9 +3488,9 @@ declare class ContentV2Client extends BaseV2Client {
|
|
|
3482
3488
|
*/
|
|
3483
3489
|
|
|
3484
3490
|
declare class ProductsV2Client extends BaseV2Client {
|
|
3485
|
-
list(siteName: string, params?: V2ProductListParams): Promise<V2List<V2Product>>;
|
|
3491
|
+
list(siteName: string, params?: V2ProductListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Product>>;
|
|
3486
3492
|
listAutoPaginated(siteName: string, params?: Omit<V2ProductListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Product, void, unknown>;
|
|
3487
|
-
get(siteName: string, idOrSlug: string): Promise<V2Product>;
|
|
3493
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Product>;
|
|
3488
3494
|
create(siteName: string, data: V2ProductCreateParams): Promise<V2Product>;
|
|
3489
3495
|
update(siteName: string, id: string, data: V2ProductUpdateParams): Promise<V2Product>;
|
|
3490
3496
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3497,8 +3503,8 @@ declare class ProductsV2Client extends BaseV2Client {
|
|
|
3497
3503
|
declare class CategoriesV2Client extends BaseV2Client {
|
|
3498
3504
|
list(siteName: string, params?: V2PaginationParams & {
|
|
3499
3505
|
type?: string;
|
|
3500
|
-
}): Promise<V2List<V2Category>>;
|
|
3501
|
-
get(siteName: string, id: string): Promise<V2Category>;
|
|
3506
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2Category>>;
|
|
3507
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Category>;
|
|
3502
3508
|
create(siteName: string, data: V2CategoryCreateParams): Promise<V2Category>;
|
|
3503
3509
|
update(siteName: string, id: string, data: V2CategoryUpdateParams): Promise<V2Category>;
|
|
3504
3510
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3529,9 +3535,9 @@ declare class CollectionsV2Client extends BaseV2Client {
|
|
|
3529
3535
|
*/
|
|
3530
3536
|
|
|
3531
3537
|
declare class OrdersV2Client extends BaseV2Client {
|
|
3532
|
-
list(siteName: string, params?: V2OrderListParams): Promise<V2List<V2Order>>;
|
|
3538
|
+
list(siteName: string, params?: V2OrderListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Order>>;
|
|
3533
3539
|
listAutoPaginated(siteName: string, params?: Omit<V2OrderListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Order, void, unknown>;
|
|
3534
|
-
get(siteName: string, id: string): Promise<V2Order>;
|
|
3540
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Order>;
|
|
3535
3541
|
}
|
|
3536
3542
|
|
|
3537
3543
|
/**
|
|
@@ -3588,13 +3594,13 @@ declare class NewsletterV2Client extends BaseV2Client {
|
|
|
3588
3594
|
trackClick(siteName: string, token: string, url: string): Promise<V2NewsletterTrackingResponse>;
|
|
3589
3595
|
listSubscriptions(siteName: string, params?: V2PaginationParams & {
|
|
3590
3596
|
status?: string;
|
|
3591
|
-
}): Promise<V2List<V2NewsletterSubscription>>;
|
|
3592
|
-
getSubscription(siteName: string, id: string): Promise<V2NewsletterSubscription>;
|
|
3593
|
-
listLists(siteName: string): Promise<V2List<V2NewsletterList>>;
|
|
3597
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterSubscription>>;
|
|
3598
|
+
getSubscription(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2NewsletterSubscription>;
|
|
3599
|
+
listLists(siteName: string, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterList>>;
|
|
3594
3600
|
listCampaigns(siteName: string, params?: V2PaginationParams & {
|
|
3595
3601
|
status?: string;
|
|
3596
|
-
}): Promise<V2List<V2NewsletterCampaign>>;
|
|
3597
|
-
getCampaign(siteName: string, idOrSlug: string): Promise<V2NewsletterCampaign>;
|
|
3602
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterCampaign>>;
|
|
3603
|
+
getCampaign(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2NewsletterCampaign>;
|
|
3598
3604
|
}
|
|
3599
3605
|
|
|
3600
3606
|
/**
|
|
@@ -3671,8 +3677,12 @@ declare class WebhooksV2Client extends BaseV2Client {
|
|
|
3671
3677
|
* const posts = await client.content.list('mysite', { type: 'post', limit: 10 });
|
|
3672
3678
|
*/
|
|
3673
3679
|
|
|
3680
|
+
interface PerspectApiV2Config extends PerspectApiConfig {
|
|
3681
|
+
cache?: CacheConfig;
|
|
3682
|
+
}
|
|
3674
3683
|
declare class PerspectApiV2Client {
|
|
3675
3684
|
private http;
|
|
3685
|
+
readonly cache: CacheManager;
|
|
3676
3686
|
readonly content: ContentV2Client;
|
|
3677
3687
|
readonly products: ProductsV2Client;
|
|
3678
3688
|
readonly categories: CategoriesV2Client;
|
|
@@ -3685,7 +3695,7 @@ declare class PerspectApiV2Client {
|
|
|
3685
3695
|
readonly sites: SitesV2Client;
|
|
3686
3696
|
readonly apiKeys: ApiKeysV2Client;
|
|
3687
3697
|
readonly webhooks: WebhooksV2Client;
|
|
3688
|
-
constructor(config:
|
|
3698
|
+
constructor(config: PerspectApiV2Config);
|
|
3689
3699
|
/** Update the JWT token for authenticated requests. */
|
|
3690
3700
|
setAuth(jwt: string): void;
|
|
3691
3701
|
/** Update the API key. */
|
|
@@ -3695,6 +3705,42 @@ declare class PerspectApiV2Client {
|
|
|
3695
3705
|
}
|
|
3696
3706
|
declare function createPerspectApiV2Client(config: PerspectApiConfig): PerspectApiV2Client;
|
|
3697
3707
|
|
|
3708
|
+
/**
|
|
3709
|
+
* Adapter that bridges a CacheStorage-compatible KV implementation
|
|
3710
|
+
* (e.g. CloudflareKvAdapter from @perspect/shared) to the SDK's CacheAdapter interface.
|
|
3711
|
+
*
|
|
3712
|
+
* Usage:
|
|
3713
|
+
* import { CloudflareKvAdapter } from '@perspect/shared';
|
|
3714
|
+
* import { CloudflareKVCacheAdapter } from 'perspectapi-ts-sdk';
|
|
3715
|
+
*
|
|
3716
|
+
* const kvAdapter = new CloudflareKvAdapter(env.CACHE_KV);
|
|
3717
|
+
* const cacheAdapter = new CloudflareKVCacheAdapter(kvAdapter);
|
|
3718
|
+
*
|
|
3719
|
+
* Or pass any object with get/put/delete methods matching Cloudflare KV semantics.
|
|
3720
|
+
*/
|
|
3721
|
+
|
|
3722
|
+
/** Minimal interface matching CloudflareKvAdapter / CacheStorage from @perspect/shared. */
|
|
3723
|
+
interface KVLike {
|
|
3724
|
+
get(key: string): Promise<string | null>;
|
|
3725
|
+
put(key: string, value: string, options?: {
|
|
3726
|
+
expirationTtl?: number;
|
|
3727
|
+
}): Promise<void>;
|
|
3728
|
+
delete(key: string): Promise<void>;
|
|
3729
|
+
deleteMultiple?(keys: string[]): Promise<void>;
|
|
3730
|
+
clear?(): Promise<void>;
|
|
3731
|
+
}
|
|
3732
|
+
declare class CloudflareKVCacheAdapter implements CacheAdapter {
|
|
3733
|
+
private kv;
|
|
3734
|
+
constructor(kv: KVLike);
|
|
3735
|
+
get(key: string): Promise<string | null>;
|
|
3736
|
+
set(key: string, value: string, options?: {
|
|
3737
|
+
ttlSeconds?: number;
|
|
3738
|
+
}): Promise<void>;
|
|
3739
|
+
delete(key: string): Promise<void>;
|
|
3740
|
+
deleteMany(keys: string[]): Promise<void>;
|
|
3741
|
+
clear(): Promise<void>;
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3698
3744
|
/**
|
|
3699
3745
|
* Simple in-memory cache adapter primarily suited for development and testing.
|
|
3700
3746
|
*/
|
|
@@ -4013,4 +4059,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4013
4059
|
error: string;
|
|
4014
4060
|
}>;
|
|
4015
4061
|
|
|
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 };
|
|
4062
|
+
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
|
@@ -3410,7 +3410,7 @@ interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
|
|
|
3410
3410
|
}
|
|
3411
3411
|
|
|
3412
3412
|
/**
|
|
3413
|
-
* v2 Base Client — cursor pagination, expand support, typed errors.
|
|
3413
|
+
* v2 Base Client — cursor pagination, expand support, caching, typed errors.
|
|
3414
3414
|
*/
|
|
3415
3415
|
|
|
3416
3416
|
declare class PerspectV2Error extends Error {
|
|
@@ -3423,7 +3423,8 @@ declare class PerspectV2Error extends Error {
|
|
|
3423
3423
|
declare abstract class BaseV2Client {
|
|
3424
3424
|
protected http: HttpClient;
|
|
3425
3425
|
protected basePath: string;
|
|
3426
|
-
|
|
3426
|
+
protected cache?: CacheManager;
|
|
3427
|
+
constructor(http: HttpClient, basePath: string, cache?: CacheManager);
|
|
3427
3428
|
protected buildPath(endpoint: string): string;
|
|
3428
3429
|
protected sitePath(siteName: string, resource: string, suffix?: string): string;
|
|
3429
3430
|
private toParams;
|
|
@@ -3439,16 +3440,21 @@ declare abstract class BaseV2Client {
|
|
|
3439
3440
|
* We unwrap accordingly.
|
|
3440
3441
|
*/
|
|
3441
3442
|
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>>;
|
|
3443
|
+
/** GET a single resource, with optional caching. */
|
|
3444
|
+
protected getOne<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<T>;
|
|
3445
|
+
/** GET a list of resources with cursor pagination, with optional caching. */
|
|
3446
|
+
protected getList<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<V2List<T>>;
|
|
3446
3447
|
/** POST to create a resource. */
|
|
3447
3448
|
protected post<T>(path: string, body?: unknown): Promise<T>;
|
|
3448
3449
|
/** PATCH to update a resource. */
|
|
3449
3450
|
protected patchOne<T>(path: string, body?: unknown): Promise<T>;
|
|
3450
3451
|
/** DELETE a resource. */
|
|
3451
3452
|
protected deleteOne(path: string): Promise<V2Deleted>;
|
|
3453
|
+
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
3454
|
+
private fetchWithCache;
|
|
3455
|
+
/** Invalidate cache entries by keys or tags. */
|
|
3456
|
+
protected invalidateCache(options: CacheInvalidateOptions): Promise<void>;
|
|
3457
|
+
private buildCacheKey;
|
|
3452
3458
|
/**
|
|
3453
3459
|
* Auto-paginating async generator.
|
|
3454
3460
|
* Yields every item across all pages.
|
|
@@ -3467,9 +3473,9 @@ declare abstract class BaseV2Client {
|
|
|
3467
3473
|
*/
|
|
3468
3474
|
|
|
3469
3475
|
declare class ContentV2Client extends BaseV2Client {
|
|
3470
|
-
list(siteName: string, params?: V2ContentListParams): Promise<V2List<V2Content>>;
|
|
3476
|
+
list(siteName: string, params?: V2ContentListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Content>>;
|
|
3471
3477
|
listAutoPaginated(siteName: string, params?: Omit<V2ContentListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Content, void, unknown>;
|
|
3472
|
-
get(siteName: string, idOrSlug: string): Promise<V2Content>;
|
|
3478
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Content>;
|
|
3473
3479
|
create(siteName: string, data: V2ContentCreateParams): Promise<V2Content>;
|
|
3474
3480
|
update(siteName: string, id: string, data: V2ContentUpdateParams): Promise<V2Content>;
|
|
3475
3481
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3482,9 +3488,9 @@ declare class ContentV2Client extends BaseV2Client {
|
|
|
3482
3488
|
*/
|
|
3483
3489
|
|
|
3484
3490
|
declare class ProductsV2Client extends BaseV2Client {
|
|
3485
|
-
list(siteName: string, params?: V2ProductListParams): Promise<V2List<V2Product>>;
|
|
3491
|
+
list(siteName: string, params?: V2ProductListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Product>>;
|
|
3486
3492
|
listAutoPaginated(siteName: string, params?: Omit<V2ProductListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Product, void, unknown>;
|
|
3487
|
-
get(siteName: string, idOrSlug: string): Promise<V2Product>;
|
|
3493
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Product>;
|
|
3488
3494
|
create(siteName: string, data: V2ProductCreateParams): Promise<V2Product>;
|
|
3489
3495
|
update(siteName: string, id: string, data: V2ProductUpdateParams): Promise<V2Product>;
|
|
3490
3496
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3497,8 +3503,8 @@ declare class ProductsV2Client extends BaseV2Client {
|
|
|
3497
3503
|
declare class CategoriesV2Client extends BaseV2Client {
|
|
3498
3504
|
list(siteName: string, params?: V2PaginationParams & {
|
|
3499
3505
|
type?: string;
|
|
3500
|
-
}): Promise<V2List<V2Category>>;
|
|
3501
|
-
get(siteName: string, id: string): Promise<V2Category>;
|
|
3506
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2Category>>;
|
|
3507
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Category>;
|
|
3502
3508
|
create(siteName: string, data: V2CategoryCreateParams): Promise<V2Category>;
|
|
3503
3509
|
update(siteName: string, id: string, data: V2CategoryUpdateParams): Promise<V2Category>;
|
|
3504
3510
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3529,9 +3535,9 @@ declare class CollectionsV2Client extends BaseV2Client {
|
|
|
3529
3535
|
*/
|
|
3530
3536
|
|
|
3531
3537
|
declare class OrdersV2Client extends BaseV2Client {
|
|
3532
|
-
list(siteName: string, params?: V2OrderListParams): Promise<V2List<V2Order>>;
|
|
3538
|
+
list(siteName: string, params?: V2OrderListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Order>>;
|
|
3533
3539
|
listAutoPaginated(siteName: string, params?: Omit<V2OrderListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Order, void, unknown>;
|
|
3534
|
-
get(siteName: string, id: string): Promise<V2Order>;
|
|
3540
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Order>;
|
|
3535
3541
|
}
|
|
3536
3542
|
|
|
3537
3543
|
/**
|
|
@@ -3588,13 +3594,13 @@ declare class NewsletterV2Client extends BaseV2Client {
|
|
|
3588
3594
|
trackClick(siteName: string, token: string, url: string): Promise<V2NewsletterTrackingResponse>;
|
|
3589
3595
|
listSubscriptions(siteName: string, params?: V2PaginationParams & {
|
|
3590
3596
|
status?: string;
|
|
3591
|
-
}): Promise<V2List<V2NewsletterSubscription>>;
|
|
3592
|
-
getSubscription(siteName: string, id: string): Promise<V2NewsletterSubscription>;
|
|
3593
|
-
listLists(siteName: string): Promise<V2List<V2NewsletterList>>;
|
|
3597
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterSubscription>>;
|
|
3598
|
+
getSubscription(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2NewsletterSubscription>;
|
|
3599
|
+
listLists(siteName: string, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterList>>;
|
|
3594
3600
|
listCampaigns(siteName: string, params?: V2PaginationParams & {
|
|
3595
3601
|
status?: string;
|
|
3596
|
-
}): Promise<V2List<V2NewsletterCampaign>>;
|
|
3597
|
-
getCampaign(siteName: string, idOrSlug: string): Promise<V2NewsletterCampaign>;
|
|
3602
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterCampaign>>;
|
|
3603
|
+
getCampaign(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2NewsletterCampaign>;
|
|
3598
3604
|
}
|
|
3599
3605
|
|
|
3600
3606
|
/**
|
|
@@ -3671,8 +3677,12 @@ declare class WebhooksV2Client extends BaseV2Client {
|
|
|
3671
3677
|
* const posts = await client.content.list('mysite', { type: 'post', limit: 10 });
|
|
3672
3678
|
*/
|
|
3673
3679
|
|
|
3680
|
+
interface PerspectApiV2Config extends PerspectApiConfig {
|
|
3681
|
+
cache?: CacheConfig;
|
|
3682
|
+
}
|
|
3674
3683
|
declare class PerspectApiV2Client {
|
|
3675
3684
|
private http;
|
|
3685
|
+
readonly cache: CacheManager;
|
|
3676
3686
|
readonly content: ContentV2Client;
|
|
3677
3687
|
readonly products: ProductsV2Client;
|
|
3678
3688
|
readonly categories: CategoriesV2Client;
|
|
@@ -3685,7 +3695,7 @@ declare class PerspectApiV2Client {
|
|
|
3685
3695
|
readonly sites: SitesV2Client;
|
|
3686
3696
|
readonly apiKeys: ApiKeysV2Client;
|
|
3687
3697
|
readonly webhooks: WebhooksV2Client;
|
|
3688
|
-
constructor(config:
|
|
3698
|
+
constructor(config: PerspectApiV2Config);
|
|
3689
3699
|
/** Update the JWT token for authenticated requests. */
|
|
3690
3700
|
setAuth(jwt: string): void;
|
|
3691
3701
|
/** Update the API key. */
|
|
@@ -3695,6 +3705,42 @@ declare class PerspectApiV2Client {
|
|
|
3695
3705
|
}
|
|
3696
3706
|
declare function createPerspectApiV2Client(config: PerspectApiConfig): PerspectApiV2Client;
|
|
3697
3707
|
|
|
3708
|
+
/**
|
|
3709
|
+
* Adapter that bridges a CacheStorage-compatible KV implementation
|
|
3710
|
+
* (e.g. CloudflareKvAdapter from @perspect/shared) to the SDK's CacheAdapter interface.
|
|
3711
|
+
*
|
|
3712
|
+
* Usage:
|
|
3713
|
+
* import { CloudflareKvAdapter } from '@perspect/shared';
|
|
3714
|
+
* import { CloudflareKVCacheAdapter } from 'perspectapi-ts-sdk';
|
|
3715
|
+
*
|
|
3716
|
+
* const kvAdapter = new CloudflareKvAdapter(env.CACHE_KV);
|
|
3717
|
+
* const cacheAdapter = new CloudflareKVCacheAdapter(kvAdapter);
|
|
3718
|
+
*
|
|
3719
|
+
* Or pass any object with get/put/delete methods matching Cloudflare KV semantics.
|
|
3720
|
+
*/
|
|
3721
|
+
|
|
3722
|
+
/** Minimal interface matching CloudflareKvAdapter / CacheStorage from @perspect/shared. */
|
|
3723
|
+
interface KVLike {
|
|
3724
|
+
get(key: string): Promise<string | null>;
|
|
3725
|
+
put(key: string, value: string, options?: {
|
|
3726
|
+
expirationTtl?: number;
|
|
3727
|
+
}): Promise<void>;
|
|
3728
|
+
delete(key: string): Promise<void>;
|
|
3729
|
+
deleteMultiple?(keys: string[]): Promise<void>;
|
|
3730
|
+
clear?(): Promise<void>;
|
|
3731
|
+
}
|
|
3732
|
+
declare class CloudflareKVCacheAdapter implements CacheAdapter {
|
|
3733
|
+
private kv;
|
|
3734
|
+
constructor(kv: KVLike);
|
|
3735
|
+
get(key: string): Promise<string | null>;
|
|
3736
|
+
set(key: string, value: string, options?: {
|
|
3737
|
+
ttlSeconds?: number;
|
|
3738
|
+
}): Promise<void>;
|
|
3739
|
+
delete(key: string): Promise<void>;
|
|
3740
|
+
deleteMany(keys: string[]): Promise<void>;
|
|
3741
|
+
clear(): Promise<void>;
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3698
3744
|
/**
|
|
3699
3745
|
* Simple in-memory cache adapter primarily suited for development and testing.
|
|
3700
3746
|
*/
|
|
@@ -4013,4 +4059,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4013
4059
|
error: string;
|
|
4014
4060
|
}>;
|
|
4015
4061
|
|
|
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 };
|
|
4062
|
+
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 };
|