perspectapi-ts-sdk 5.0.2 → 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 +72 -21
- package/dist/index.d.ts +72 -21
- package/dist/index.js +135 -47
- package/dist/index.mjs +134 -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 +35 -4
- 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 +4 -0
package/dist/index.d.mts
CHANGED
|
@@ -3338,6 +3338,9 @@ interface V2NewsletterCampaign extends V2Object {
|
|
|
3338
3338
|
created_at: string | null;
|
|
3339
3339
|
updated_at: string | null;
|
|
3340
3340
|
}
|
|
3341
|
+
interface V2NewsletterTrackingResponse {
|
|
3342
|
+
success: boolean;
|
|
3343
|
+
}
|
|
3341
3344
|
interface V2ContactSubmission extends V2Object {
|
|
3342
3345
|
object: "contact_submission";
|
|
3343
3346
|
name: string | null;
|
|
@@ -3407,7 +3410,7 @@ interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
|
|
|
3407
3410
|
}
|
|
3408
3411
|
|
|
3409
3412
|
/**
|
|
3410
|
-
* v2 Base Client — cursor pagination, expand support, typed errors.
|
|
3413
|
+
* v2 Base Client — cursor pagination, expand support, caching, typed errors.
|
|
3411
3414
|
*/
|
|
3412
3415
|
|
|
3413
3416
|
declare class PerspectV2Error extends Error {
|
|
@@ -3420,7 +3423,8 @@ declare class PerspectV2Error extends Error {
|
|
|
3420
3423
|
declare abstract class BaseV2Client {
|
|
3421
3424
|
protected http: HttpClient;
|
|
3422
3425
|
protected basePath: string;
|
|
3423
|
-
|
|
3426
|
+
protected cache?: CacheManager;
|
|
3427
|
+
constructor(http: HttpClient, basePath: string, cache?: CacheManager);
|
|
3424
3428
|
protected buildPath(endpoint: string): string;
|
|
3425
3429
|
protected sitePath(siteName: string, resource: string, suffix?: string): string;
|
|
3426
3430
|
private toParams;
|
|
@@ -3436,16 +3440,21 @@ declare abstract class BaseV2Client {
|
|
|
3436
3440
|
* We unwrap accordingly.
|
|
3437
3441
|
*/
|
|
3438
3442
|
private extractData;
|
|
3439
|
-
/** GET a single resource. */
|
|
3440
|
-
protected getOne<T>(path: string, params?: object): Promise<T>;
|
|
3441
|
-
/** GET a list of resources with cursor pagination. */
|
|
3442
|
-
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>>;
|
|
3443
3447
|
/** POST to create a resource. */
|
|
3444
3448
|
protected post<T>(path: string, body?: unknown): Promise<T>;
|
|
3445
3449
|
/** PATCH to update a resource. */
|
|
3446
3450
|
protected patchOne<T>(path: string, body?: unknown): Promise<T>;
|
|
3447
3451
|
/** DELETE a resource. */
|
|
3448
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;
|
|
3449
3458
|
/**
|
|
3450
3459
|
* Auto-paginating async generator.
|
|
3451
3460
|
* Yields every item across all pages.
|
|
@@ -3464,9 +3473,9 @@ declare abstract class BaseV2Client {
|
|
|
3464
3473
|
*/
|
|
3465
3474
|
|
|
3466
3475
|
declare class ContentV2Client extends BaseV2Client {
|
|
3467
|
-
list(siteName: string, params?: V2ContentListParams): Promise<V2List<V2Content>>;
|
|
3476
|
+
list(siteName: string, params?: V2ContentListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Content>>;
|
|
3468
3477
|
listAutoPaginated(siteName: string, params?: Omit<V2ContentListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Content, void, unknown>;
|
|
3469
|
-
get(siteName: string, idOrSlug: string): Promise<V2Content>;
|
|
3478
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Content>;
|
|
3470
3479
|
create(siteName: string, data: V2ContentCreateParams): Promise<V2Content>;
|
|
3471
3480
|
update(siteName: string, id: string, data: V2ContentUpdateParams): Promise<V2Content>;
|
|
3472
3481
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3479,9 +3488,9 @@ declare class ContentV2Client extends BaseV2Client {
|
|
|
3479
3488
|
*/
|
|
3480
3489
|
|
|
3481
3490
|
declare class ProductsV2Client extends BaseV2Client {
|
|
3482
|
-
list(siteName: string, params?: V2ProductListParams): Promise<V2List<V2Product>>;
|
|
3491
|
+
list(siteName: string, params?: V2ProductListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Product>>;
|
|
3483
3492
|
listAutoPaginated(siteName: string, params?: Omit<V2ProductListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Product, void, unknown>;
|
|
3484
|
-
get(siteName: string, idOrSlug: string): Promise<V2Product>;
|
|
3493
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Product>;
|
|
3485
3494
|
create(siteName: string, data: V2ProductCreateParams): Promise<V2Product>;
|
|
3486
3495
|
update(siteName: string, id: string, data: V2ProductUpdateParams): Promise<V2Product>;
|
|
3487
3496
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3494,8 +3503,8 @@ declare class ProductsV2Client extends BaseV2Client {
|
|
|
3494
3503
|
declare class CategoriesV2Client extends BaseV2Client {
|
|
3495
3504
|
list(siteName: string, params?: V2PaginationParams & {
|
|
3496
3505
|
type?: string;
|
|
3497
|
-
}): Promise<V2List<V2Category>>;
|
|
3498
|
-
get(siteName: string, id: string): Promise<V2Category>;
|
|
3506
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2Category>>;
|
|
3507
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Category>;
|
|
3499
3508
|
create(siteName: string, data: V2CategoryCreateParams): Promise<V2Category>;
|
|
3500
3509
|
update(siteName: string, id: string, data: V2CategoryUpdateParams): Promise<V2Category>;
|
|
3501
3510
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3526,9 +3535,9 @@ declare class CollectionsV2Client extends BaseV2Client {
|
|
|
3526
3535
|
*/
|
|
3527
3536
|
|
|
3528
3537
|
declare class OrdersV2Client extends BaseV2Client {
|
|
3529
|
-
list(siteName: string, params?: V2OrderListParams): Promise<V2List<V2Order>>;
|
|
3538
|
+
list(siteName: string, params?: V2OrderListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Order>>;
|
|
3530
3539
|
listAutoPaginated(siteName: string, params?: Omit<V2OrderListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Order, void, unknown>;
|
|
3531
|
-
get(siteName: string, id: string): Promise<V2Order>;
|
|
3540
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Order>;
|
|
3532
3541
|
}
|
|
3533
3542
|
|
|
3534
3543
|
/**
|
|
@@ -3581,15 +3590,17 @@ declare class NewsletterV2Client extends BaseV2Client {
|
|
|
3581
3590
|
email?: string;
|
|
3582
3591
|
reason?: string;
|
|
3583
3592
|
}): Promise<V2NewsletterSubscription>;
|
|
3593
|
+
trackOpen(siteName: string, token: string): Promise<V2NewsletterTrackingResponse>;
|
|
3594
|
+
trackClick(siteName: string, token: string, url: string): Promise<V2NewsletterTrackingResponse>;
|
|
3584
3595
|
listSubscriptions(siteName: string, params?: V2PaginationParams & {
|
|
3585
3596
|
status?: string;
|
|
3586
|
-
}): Promise<V2List<V2NewsletterSubscription>>;
|
|
3587
|
-
getSubscription(siteName: string, id: string): Promise<V2NewsletterSubscription>;
|
|
3588
|
-
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>>;
|
|
3589
3600
|
listCampaigns(siteName: string, params?: V2PaginationParams & {
|
|
3590
3601
|
status?: string;
|
|
3591
|
-
}): Promise<V2List<V2NewsletterCampaign>>;
|
|
3592
|
-
getCampaign(siteName: string, idOrSlug: string): Promise<V2NewsletterCampaign>;
|
|
3602
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterCampaign>>;
|
|
3603
|
+
getCampaign(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2NewsletterCampaign>;
|
|
3593
3604
|
}
|
|
3594
3605
|
|
|
3595
3606
|
/**
|
|
@@ -3666,8 +3677,12 @@ declare class WebhooksV2Client extends BaseV2Client {
|
|
|
3666
3677
|
* const posts = await client.content.list('mysite', { type: 'post', limit: 10 });
|
|
3667
3678
|
*/
|
|
3668
3679
|
|
|
3680
|
+
interface PerspectApiV2Config extends PerspectApiConfig {
|
|
3681
|
+
cache?: CacheConfig;
|
|
3682
|
+
}
|
|
3669
3683
|
declare class PerspectApiV2Client {
|
|
3670
3684
|
private http;
|
|
3685
|
+
readonly cache: CacheManager;
|
|
3671
3686
|
readonly content: ContentV2Client;
|
|
3672
3687
|
readonly products: ProductsV2Client;
|
|
3673
3688
|
readonly categories: CategoriesV2Client;
|
|
@@ -3680,7 +3695,7 @@ declare class PerspectApiV2Client {
|
|
|
3680
3695
|
readonly sites: SitesV2Client;
|
|
3681
3696
|
readonly apiKeys: ApiKeysV2Client;
|
|
3682
3697
|
readonly webhooks: WebhooksV2Client;
|
|
3683
|
-
constructor(config:
|
|
3698
|
+
constructor(config: PerspectApiV2Config);
|
|
3684
3699
|
/** Update the JWT token for authenticated requests. */
|
|
3685
3700
|
setAuth(jwt: string): void;
|
|
3686
3701
|
/** Update the API key. */
|
|
@@ -3690,6 +3705,42 @@ declare class PerspectApiV2Client {
|
|
|
3690
3705
|
}
|
|
3691
3706
|
declare function createPerspectApiV2Client(config: PerspectApiConfig): PerspectApiV2Client;
|
|
3692
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
|
+
|
|
3693
3744
|
/**
|
|
3694
3745
|
* Simple in-memory cache adapter primarily suited for development and testing.
|
|
3695
3746
|
*/
|
|
@@ -4008,4 +4059,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4008
4059
|
error: string;
|
|
4009
4060
|
}>;
|
|
4010
4061
|
|
|
4011
|
-
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
|
@@ -3338,6 +3338,9 @@ interface V2NewsletterCampaign extends V2Object {
|
|
|
3338
3338
|
created_at: string | null;
|
|
3339
3339
|
updated_at: string | null;
|
|
3340
3340
|
}
|
|
3341
|
+
interface V2NewsletterTrackingResponse {
|
|
3342
|
+
success: boolean;
|
|
3343
|
+
}
|
|
3341
3344
|
interface V2ContactSubmission extends V2Object {
|
|
3342
3345
|
object: "contact_submission";
|
|
3343
3346
|
name: string | null;
|
|
@@ -3407,7 +3410,7 @@ interface V2WebhookUpdateParams extends Partial<V2WebhookCreateParams> {
|
|
|
3407
3410
|
}
|
|
3408
3411
|
|
|
3409
3412
|
/**
|
|
3410
|
-
* v2 Base Client — cursor pagination, expand support, typed errors.
|
|
3413
|
+
* v2 Base Client — cursor pagination, expand support, caching, typed errors.
|
|
3411
3414
|
*/
|
|
3412
3415
|
|
|
3413
3416
|
declare class PerspectV2Error extends Error {
|
|
@@ -3420,7 +3423,8 @@ declare class PerspectV2Error extends Error {
|
|
|
3420
3423
|
declare abstract class BaseV2Client {
|
|
3421
3424
|
protected http: HttpClient;
|
|
3422
3425
|
protected basePath: string;
|
|
3423
|
-
|
|
3426
|
+
protected cache?: CacheManager;
|
|
3427
|
+
constructor(http: HttpClient, basePath: string, cache?: CacheManager);
|
|
3424
3428
|
protected buildPath(endpoint: string): string;
|
|
3425
3429
|
protected sitePath(siteName: string, resource: string, suffix?: string): string;
|
|
3426
3430
|
private toParams;
|
|
@@ -3436,16 +3440,21 @@ declare abstract class BaseV2Client {
|
|
|
3436
3440
|
* We unwrap accordingly.
|
|
3437
3441
|
*/
|
|
3438
3442
|
private extractData;
|
|
3439
|
-
/** GET a single resource. */
|
|
3440
|
-
protected getOne<T>(path: string, params?: object): Promise<T>;
|
|
3441
|
-
/** GET a list of resources with cursor pagination. */
|
|
3442
|
-
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>>;
|
|
3443
3447
|
/** POST to create a resource. */
|
|
3444
3448
|
protected post<T>(path: string, body?: unknown): Promise<T>;
|
|
3445
3449
|
/** PATCH to update a resource. */
|
|
3446
3450
|
protected patchOne<T>(path: string, body?: unknown): Promise<T>;
|
|
3447
3451
|
/** DELETE a resource. */
|
|
3448
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;
|
|
3449
3458
|
/**
|
|
3450
3459
|
* Auto-paginating async generator.
|
|
3451
3460
|
* Yields every item across all pages.
|
|
@@ -3464,9 +3473,9 @@ declare abstract class BaseV2Client {
|
|
|
3464
3473
|
*/
|
|
3465
3474
|
|
|
3466
3475
|
declare class ContentV2Client extends BaseV2Client {
|
|
3467
|
-
list(siteName: string, params?: V2ContentListParams): Promise<V2List<V2Content>>;
|
|
3476
|
+
list(siteName: string, params?: V2ContentListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Content>>;
|
|
3468
3477
|
listAutoPaginated(siteName: string, params?: Omit<V2ContentListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Content, void, unknown>;
|
|
3469
|
-
get(siteName: string, idOrSlug: string): Promise<V2Content>;
|
|
3478
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Content>;
|
|
3470
3479
|
create(siteName: string, data: V2ContentCreateParams): Promise<V2Content>;
|
|
3471
3480
|
update(siteName: string, id: string, data: V2ContentUpdateParams): Promise<V2Content>;
|
|
3472
3481
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3479,9 +3488,9 @@ declare class ContentV2Client extends BaseV2Client {
|
|
|
3479
3488
|
*/
|
|
3480
3489
|
|
|
3481
3490
|
declare class ProductsV2Client extends BaseV2Client {
|
|
3482
|
-
list(siteName: string, params?: V2ProductListParams): Promise<V2List<V2Product>>;
|
|
3491
|
+
list(siteName: string, params?: V2ProductListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Product>>;
|
|
3483
3492
|
listAutoPaginated(siteName: string, params?: Omit<V2ProductListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Product, void, unknown>;
|
|
3484
|
-
get(siteName: string, idOrSlug: string): Promise<V2Product>;
|
|
3493
|
+
get(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2Product>;
|
|
3485
3494
|
create(siteName: string, data: V2ProductCreateParams): Promise<V2Product>;
|
|
3486
3495
|
update(siteName: string, id: string, data: V2ProductUpdateParams): Promise<V2Product>;
|
|
3487
3496
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3494,8 +3503,8 @@ declare class ProductsV2Client extends BaseV2Client {
|
|
|
3494
3503
|
declare class CategoriesV2Client extends BaseV2Client {
|
|
3495
3504
|
list(siteName: string, params?: V2PaginationParams & {
|
|
3496
3505
|
type?: string;
|
|
3497
|
-
}): Promise<V2List<V2Category>>;
|
|
3498
|
-
get(siteName: string, id: string): Promise<V2Category>;
|
|
3506
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2Category>>;
|
|
3507
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Category>;
|
|
3499
3508
|
create(siteName: string, data: V2CategoryCreateParams): Promise<V2Category>;
|
|
3500
3509
|
update(siteName: string, id: string, data: V2CategoryUpdateParams): Promise<V2Category>;
|
|
3501
3510
|
del(siteName: string, id: string): Promise<V2Deleted>;
|
|
@@ -3526,9 +3535,9 @@ declare class CollectionsV2Client extends BaseV2Client {
|
|
|
3526
3535
|
*/
|
|
3527
3536
|
|
|
3528
3537
|
declare class OrdersV2Client extends BaseV2Client {
|
|
3529
|
-
list(siteName: string, params?: V2OrderListParams): Promise<V2List<V2Order>>;
|
|
3538
|
+
list(siteName: string, params?: V2OrderListParams, cachePolicy?: CachePolicy): Promise<V2List<V2Order>>;
|
|
3530
3539
|
listAutoPaginated(siteName: string, params?: Omit<V2OrderListParams, 'starting_after' | 'ending_before'>): AsyncGenerator<V2Order, void, unknown>;
|
|
3531
|
-
get(siteName: string, id: string): Promise<V2Order>;
|
|
3540
|
+
get(siteName: string, id: string, cachePolicy?: CachePolicy): Promise<V2Order>;
|
|
3532
3541
|
}
|
|
3533
3542
|
|
|
3534
3543
|
/**
|
|
@@ -3581,15 +3590,17 @@ declare class NewsletterV2Client extends BaseV2Client {
|
|
|
3581
3590
|
email?: string;
|
|
3582
3591
|
reason?: string;
|
|
3583
3592
|
}): Promise<V2NewsletterSubscription>;
|
|
3593
|
+
trackOpen(siteName: string, token: string): Promise<V2NewsletterTrackingResponse>;
|
|
3594
|
+
trackClick(siteName: string, token: string, url: string): Promise<V2NewsletterTrackingResponse>;
|
|
3584
3595
|
listSubscriptions(siteName: string, params?: V2PaginationParams & {
|
|
3585
3596
|
status?: string;
|
|
3586
|
-
}): Promise<V2List<V2NewsletterSubscription>>;
|
|
3587
|
-
getSubscription(siteName: string, id: string): Promise<V2NewsletterSubscription>;
|
|
3588
|
-
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>>;
|
|
3589
3600
|
listCampaigns(siteName: string, params?: V2PaginationParams & {
|
|
3590
3601
|
status?: string;
|
|
3591
|
-
}): Promise<V2List<V2NewsletterCampaign>>;
|
|
3592
|
-
getCampaign(siteName: string, idOrSlug: string): Promise<V2NewsletterCampaign>;
|
|
3602
|
+
}, cachePolicy?: CachePolicy): Promise<V2List<V2NewsletterCampaign>>;
|
|
3603
|
+
getCampaign(siteName: string, idOrSlug: string, cachePolicy?: CachePolicy): Promise<V2NewsletterCampaign>;
|
|
3593
3604
|
}
|
|
3594
3605
|
|
|
3595
3606
|
/**
|
|
@@ -3666,8 +3677,12 @@ declare class WebhooksV2Client extends BaseV2Client {
|
|
|
3666
3677
|
* const posts = await client.content.list('mysite', { type: 'post', limit: 10 });
|
|
3667
3678
|
*/
|
|
3668
3679
|
|
|
3680
|
+
interface PerspectApiV2Config extends PerspectApiConfig {
|
|
3681
|
+
cache?: CacheConfig;
|
|
3682
|
+
}
|
|
3669
3683
|
declare class PerspectApiV2Client {
|
|
3670
3684
|
private http;
|
|
3685
|
+
readonly cache: CacheManager;
|
|
3671
3686
|
readonly content: ContentV2Client;
|
|
3672
3687
|
readonly products: ProductsV2Client;
|
|
3673
3688
|
readonly categories: CategoriesV2Client;
|
|
@@ -3680,7 +3695,7 @@ declare class PerspectApiV2Client {
|
|
|
3680
3695
|
readonly sites: SitesV2Client;
|
|
3681
3696
|
readonly apiKeys: ApiKeysV2Client;
|
|
3682
3697
|
readonly webhooks: WebhooksV2Client;
|
|
3683
|
-
constructor(config:
|
|
3698
|
+
constructor(config: PerspectApiV2Config);
|
|
3684
3699
|
/** Update the JWT token for authenticated requests. */
|
|
3685
3700
|
setAuth(jwt: string): void;
|
|
3686
3701
|
/** Update the API key. */
|
|
@@ -3690,6 +3705,42 @@ declare class PerspectApiV2Client {
|
|
|
3690
3705
|
}
|
|
3691
3706
|
declare function createPerspectApiV2Client(config: PerspectApiConfig): PerspectApiV2Client;
|
|
3692
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
|
+
|
|
3693
3744
|
/**
|
|
3694
3745
|
* Simple in-memory cache adapter primarily suited for development and testing.
|
|
3695
3746
|
*/
|
|
@@ -4008,4 +4059,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
|
|
|
4008
4059
|
error: string;
|
|
4009
4060
|
}>;
|
|
4010
4061
|
|
|
4011
|
-
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 };
|