perspectapi-ts-sdk 7.2.3 → 7.2.6
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/{chunk-TFN5IR35.mjs → chunk-WD62IBI5.mjs} +49 -6
- package/dist/{index-hSqTwbPy.d.mts → index-BbTVcEl5.d.mts} +15 -0
- package/dist/{index-hSqTwbPy.d.ts → index-BbTVcEl5.d.ts} +15 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +49 -6
- package/dist/index.mjs +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.d.ts +1 -1
- package/dist/v2/index.js +49 -6
- package/dist/v2/index.mjs +1 -1
- package/package.json +1 -1
- package/src/v2/client/base-v2-client.ts +49 -6
- package/src/v2/client/subscriptions-client.ts +13 -0
|
@@ -580,7 +580,9 @@ var BaseV2Client = class {
|
|
|
580
580
|
/** GET a single resource, with optional caching. */
|
|
581
581
|
async getOne(path, params, cachePolicy) {
|
|
582
582
|
const fetcher = async () => {
|
|
583
|
-
const response = await this.
|
|
583
|
+
const response = await this.runRequest(
|
|
584
|
+
() => this.http.get(path, this.toParams(params))
|
|
585
|
+
);
|
|
584
586
|
return this.extractData(response);
|
|
585
587
|
};
|
|
586
588
|
return this.fetchWithCache(path, params, cachePolicy, fetcher);
|
|
@@ -588,29 +590,31 @@ var BaseV2Client = class {
|
|
|
588
590
|
/** GET a list of resources with cursor pagination, with optional caching. */
|
|
589
591
|
async getList(path, params, cachePolicy) {
|
|
590
592
|
const fetcher = async () => {
|
|
591
|
-
const response = await this.
|
|
593
|
+
const response = await this.runRequest(
|
|
594
|
+
() => this.http.get(path, this.toParams(params))
|
|
595
|
+
);
|
|
592
596
|
return this.extractData(response);
|
|
593
597
|
};
|
|
594
598
|
return this.fetchWithCache(path, params, cachePolicy, fetcher);
|
|
595
599
|
}
|
|
596
600
|
/** POST to create a resource. */
|
|
597
601
|
async post(path, body) {
|
|
598
|
-
const response = await this.http.post(path, body);
|
|
602
|
+
const response = await this.runRequest(() => this.http.post(path, body));
|
|
599
603
|
return this.extractData(response);
|
|
600
604
|
}
|
|
601
605
|
/** PATCH to update a resource. */
|
|
602
606
|
async patchOne(path, body) {
|
|
603
|
-
const response = await this.http.patch(path, body);
|
|
607
|
+
const response = await this.runRequest(() => this.http.patch(path, body));
|
|
604
608
|
return this.extractData(response);
|
|
605
609
|
}
|
|
606
610
|
/** PUT to upsert a resource. */
|
|
607
611
|
async putOne(path, body) {
|
|
608
|
-
const response = await this.http.put(path, body);
|
|
612
|
+
const response = await this.runRequest(() => this.http.put(path, body));
|
|
609
613
|
return this.extractData(response);
|
|
610
614
|
}
|
|
611
615
|
/** DELETE a resource. */
|
|
612
616
|
async deleteOne(path) {
|
|
613
|
-
const response = await this.http.delete(path);
|
|
617
|
+
const response = await this.runRequest(() => this.http.delete(path));
|
|
614
618
|
return this.extractData(response);
|
|
615
619
|
}
|
|
616
620
|
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
@@ -666,6 +670,38 @@ var BaseV2Client = class {
|
|
|
666
670
|
}
|
|
667
671
|
}
|
|
668
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* Run an HttpClient call and convert v2 error responses to PerspectV2Error.
|
|
675
|
+
*
|
|
676
|
+
* `HttpClient` throws `PerspectApiError` on any non-2xx, with the parsed
|
|
677
|
+
* body on `.details` and the HTTP status on `.status`. For v2 endpoints
|
|
678
|
+
* that body is `{ error: { type, code, message, param? } }` — the
|
|
679
|
+
* documented `PerspectV2Error` shape. Anything else (network failures,
|
|
680
|
+
* non-JSON bodies, malformed envelopes) is rethrown unchanged so callers
|
|
681
|
+
* still see the original error. Named `runRequest` rather than `send` to
|
|
682
|
+
* avoid colliding with subclass domain methods (e.g. EmailV2Client.send).
|
|
683
|
+
*/
|
|
684
|
+
async runRequest(call) {
|
|
685
|
+
try {
|
|
686
|
+
return await call();
|
|
687
|
+
} catch (err) {
|
|
688
|
+
const v2 = this.toV2ErrorFromThrown(err);
|
|
689
|
+
if (v2) throw v2;
|
|
690
|
+
throw err;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
toV2ErrorFromThrown(err) {
|
|
694
|
+
if (!err || typeof err !== "object") return void 0;
|
|
695
|
+
const e = err;
|
|
696
|
+
const details = e.details;
|
|
697
|
+
if (!details || typeof details !== "object") return void 0;
|
|
698
|
+
const envelope = details.error;
|
|
699
|
+
if (!envelope || typeof envelope !== "object" || !("type" in envelope) || !("message" in envelope)) {
|
|
700
|
+
return void 0;
|
|
701
|
+
}
|
|
702
|
+
const status = typeof e.status === "number" ? e.status : 500;
|
|
703
|
+
return new PerspectV2Error(envelope, status);
|
|
704
|
+
}
|
|
669
705
|
toError(response) {
|
|
670
706
|
const data = response.data;
|
|
671
707
|
const errorObj = data?.error ?? response.error;
|
|
@@ -1359,6 +1395,13 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1359
1395
|
params ?? {}
|
|
1360
1396
|
);
|
|
1361
1397
|
}
|
|
1398
|
+
/** Change the plan (price) of a user's subscription (admin). */
|
|
1399
|
+
async changeUserSubscriptionPlan(siteName, userId, subId, params) {
|
|
1400
|
+
return this.post(
|
|
1401
|
+
this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/change-plan`),
|
|
1402
|
+
params
|
|
1403
|
+
);
|
|
1404
|
+
}
|
|
1362
1405
|
/** Charge a user's subscription once (admin). */
|
|
1363
1406
|
async chargeUserSubscription(siteName, userId, subId, params) {
|
|
1364
1407
|
return this.post(
|
|
@@ -1950,6 +1950,19 @@ declare abstract class BaseV2Client {
|
|
|
1950
1950
|
protected listAutoPaginate<T extends {
|
|
1951
1951
|
id: string;
|
|
1952
1952
|
}>(path: string, params?: object): AsyncGenerator<T, void, unknown>;
|
|
1953
|
+
/**
|
|
1954
|
+
* Run an HttpClient call and convert v2 error responses to PerspectV2Error.
|
|
1955
|
+
*
|
|
1956
|
+
* `HttpClient` throws `PerspectApiError` on any non-2xx, with the parsed
|
|
1957
|
+
* body on `.details` and the HTTP status on `.status`. For v2 endpoints
|
|
1958
|
+
* that body is `{ error: { type, code, message, param? } }` — the
|
|
1959
|
+
* documented `PerspectV2Error` shape. Anything else (network failures,
|
|
1960
|
+
* non-JSON bodies, malformed envelopes) is rethrown unchanged so callers
|
|
1961
|
+
* still see the original error. Named `runRequest` rather than `send` to
|
|
1962
|
+
* avoid colliding with subclass domain methods (e.g. EmailV2Client.send).
|
|
1963
|
+
*/
|
|
1964
|
+
private runRequest;
|
|
1965
|
+
private toV2ErrorFromThrown;
|
|
1953
1966
|
private toError;
|
|
1954
1967
|
}
|
|
1955
1968
|
|
|
@@ -2266,6 +2279,8 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2266
2279
|
resumeUserSubscription(siteName: string, userId: string, subId: string): Promise<V2SiteUserSubscription>;
|
|
2267
2280
|
/** Cancel a user's subscription (admin). */
|
|
2268
2281
|
cancelUserSubscription(siteName: string, userId: string, subId: string, params?: V2SubscriptionCancelParams): Promise<V2CancelSubscriptionResult>;
|
|
2282
|
+
/** Change the plan (price) of a user's subscription (admin). */
|
|
2283
|
+
changeUserSubscriptionPlan(siteName: string, userId: string, subId: string, params: V2SubscriptionChangePlanParams): Promise<V2SiteUserSubscription>;
|
|
2269
2284
|
/** Charge a user's subscription once (admin). */
|
|
2270
2285
|
chargeUserSubscription(siteName: string, userId: string, subId: string, params: V2SubscriptionChargeParams): Promise<V2SubscriptionChargeResult>;
|
|
2271
2286
|
}
|
|
@@ -1950,6 +1950,19 @@ declare abstract class BaseV2Client {
|
|
|
1950
1950
|
protected listAutoPaginate<T extends {
|
|
1951
1951
|
id: string;
|
|
1952
1952
|
}>(path: string, params?: object): AsyncGenerator<T, void, unknown>;
|
|
1953
|
+
/**
|
|
1954
|
+
* Run an HttpClient call and convert v2 error responses to PerspectV2Error.
|
|
1955
|
+
*
|
|
1956
|
+
* `HttpClient` throws `PerspectApiError` on any non-2xx, with the parsed
|
|
1957
|
+
* body on `.details` and the HTTP status on `.status`. For v2 endpoints
|
|
1958
|
+
* that body is `{ error: { type, code, message, param? } }` — the
|
|
1959
|
+
* documented `PerspectV2Error` shape. Anything else (network failures,
|
|
1960
|
+
* non-JSON bodies, malformed envelopes) is rethrown unchanged so callers
|
|
1961
|
+
* still see the original error. Named `runRequest` rather than `send` to
|
|
1962
|
+
* avoid colliding with subclass domain methods (e.g. EmailV2Client.send).
|
|
1963
|
+
*/
|
|
1964
|
+
private runRequest;
|
|
1965
|
+
private toV2ErrorFromThrown;
|
|
1953
1966
|
private toError;
|
|
1954
1967
|
}
|
|
1955
1968
|
|
|
@@ -2266,6 +2279,8 @@ declare class SubscriptionsV2Client extends BaseV2Client {
|
|
|
2266
2279
|
resumeUserSubscription(siteName: string, userId: string, subId: string): Promise<V2SiteUserSubscription>;
|
|
2267
2280
|
/** Cancel a user's subscription (admin). */
|
|
2268
2281
|
cancelUserSubscription(siteName: string, userId: string, subId: string, params?: V2SubscriptionCancelParams): Promise<V2CancelSubscriptionResult>;
|
|
2282
|
+
/** Change the plan (price) of a user's subscription (admin). */
|
|
2283
|
+
changeUserSubscriptionPlan(siteName: string, userId: string, subId: string, params: V2SubscriptionChangePlanParams): Promise<V2SiteUserSubscription>;
|
|
2269
2284
|
/** Charge a user's subscription once (admin). */
|
|
2270
2285
|
chargeUserSubscription(siteName: string, userId: string, subId: string, params: V2SubscriptionChargeParams): Promise<V2SubscriptionChargeResult>;
|
|
2271
2286
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HttpClient, C as CacheManager, A as ApiResponse, a as CachePolicy, b as CacheInvalidateOptions, U as User, c as ContentQueryParams, P as PaginatedResponse, d as Content, e as ContentCategoryResponse, f as CreateContentRequest, g as UpdateContentRequest, h as ApiKey, i as CreateApiKeyRequest, j as UpdateApiKeyRequest, O as Organization, k as CreateOrganizationRequest, S as Site, l as CreateSiteRequest, m as ProductQueryParams, n as Product, o as CreateProductRequest, p as ProductSku, q as CreateProductSkuRequest, r as Category, s as CreateCategoryRequest, W as Webhook, t as CreateWebhookRequest, u as CreateCheckoutSessionRequest, v as CheckoutSession, w as CreateContactRequest, x as ContactSubmitResponse, y as ContactStatusResponse, z as ContactSubmission, B as CreateNewsletterSubscriptionRequest, N as NewsletterSubscribeResponse, D as NewsletterConfirmResponse, E as NewsletterUnsubscribeRequest, F as NewsletterUnsubscribeResponse, G as NewsletterPreferences, I as NewsletterList, J as NewsletterCampaignListResponse, K as NewsletterCampaignDetail, L as NewsletterStatusResponse, M as NewsletterManagementSubscriptionsListResponse, Q as NewsletterManagementSubscription, R as NewsletterSubscriptionSyncRequest, T as NewsletterSubscriptionSyncResponse, V as NewsletterSubscriptionsBulkUpdateRequest, X as NewsletterSubscriptionsBulkUpdateResponse, Y as NewsletterSubscriptionMembershipUpdateRequest, Z as NewsletterSubscriptionsImportRequest, _ as NewsletterSubscriptionsImportResponse, $ as NewsletterManagementList, a0 as NewsletterManagementSeries, a1 as NewsletterManagementCampaignListResponse, a2 as NewsletterManagementCampaign, a3 as NewsletterCampaignTestSendRequest, a4 as NewsletterCampaignTestSendResponse, a5 as NewsletterManagementStatsResponse, a6 as NewsletterExportCreateRequest, a7 as NewsletterExportCreateResponse, a8 as RequestOtpRequest, a9 as VerifyOtpRequest, aa as VerifyOtpResponse, ab as SiteUser, ac as SiteUserProfile, ad as UpdateSiteUserRequest, ae as SiteUserOrder, af as SiteUserSubscription, ag as CancelSubscriptionRequest, ah as CancelSubscriptionResponse, ai as CreditBalance, aj as CreditBalanceWithTransactions, ak as GrantCreditRequest, al as ProductBundleGroup, am as CreateBundleGroupRequest, an as BundleCollection, ao as BundleCollectionItemWithProduct, ap as CreateBundleCollectionRequest, aq as AddCollectionItemRequest, ar as BundleCollectionItem, as as PerspectApiConfig, at as CacheAdapter, au as BlogPost, av as CheckoutMetadata, aw as CheckoutAddress, ax as CheckoutTaxRequest } from './index-
|
|
2
|
-
export { aE as ApiError, aD as CacheConfig, aG as CategorySummary, c4 as CheckoutMetadataValue, c9 as CheckoutSessionTax, c8 as CheckoutTaxBreakdownItem, c7 as CheckoutTaxCustomerExemptionRequest, c6 as CheckoutTaxExemptionStatus, c5 as CheckoutTaxStrategy, b_ as ContentStatus, b$ as ContentType, c2 as CreatePaymentGatewayRequest, cb as CreditTransaction, cc as HttpMethod, aF as MediaItem, aJ as NewsletterCampaignSummary, aK as NewsletterManagementListMembership, aP as NewsletterManagementPagination, aI as NewsletterSubscription, aN as NewsletterSubscriptionImportRowRequest, aL as NewsletterSubscriptionsBulkAction, aM as NewsletterSubscriptionsBulkOutcome, aO as NewsletterSubscriptionsImportRowResult, bZ as PaginationParams, aH as PaymentGateway, aC as PerspectApiError, ay as PerspectApiV2Client, aA as PerspectV2Error, c0 as ProductSkuMediaItem, c1 as ProductSkuOption, cd as RequestOptions, aQ as SetProfileValueRequest, ca as SubscriptionCancellationMode, bH as V2ApiKey, bS as V2CancelSubscriptionResult, b4 as V2Category, b5 as V2CategoryCreateParams, b6 as V2CategoryUpdateParams, b7 as V2Collection, b9 as V2CollectionCreateParams, b8 as V2CollectionItem, ba as V2CollectionUpdateParams, bE as V2ContactSubmission, aY as V2Content, aZ as V2ContentCreateParams, a$ as V2ContentListParams, a_ as V2ContentUpdateParams, bU as V2CreditBalance, bT as V2CreditTransaction, aT as V2Deleted, bX as V2EmailSendParams, bY as V2EmailSendResult, aU as V2Error, aV as V2ErrorType, bV as V2GrantCreditParams, bW as V2GrantCreditResult, aS as V2List, aX as V2Media, bv as V2NewsletterCampaign, bC as V2NewsletterImportRequest, bD as V2NewsletterImportResult, bu as V2NewsletterList, bx as V2NewsletterListCreateParams, by as V2NewsletterListUpdateParams, bt as V2NewsletterSubscription, bB as V2NewsletterSubscriptionListMembershipUpdate, bz as V2NewsletterSyncInput, bA as V2NewsletterSyncResult, bw as V2NewsletterTrackingResponse, aR as V2Object, bb as V2Order, bf as V2OrderAddress, bh as V2OrderCreateParams, bm as V2OrderCreateResult, bj as V2OrderFulfillmentNotificationLineItem, bk as V2OrderFulfillmentNotificationParams, bl as V2OrderFulfillmentNotificationResult, bi as V2OrderFulfillmentUpdate, be as V2OrderLineItem, bd as V2OrderLineItemPriceData, bc as V2OrderListParams, bg as V2OrderTaxRequest, bF as V2Organization, aW as V2PaginationParams, b0 as V2Product, b1 as V2ProductCreateParams, b3 as V2ProductListParams, b2 as V2ProductUpdateParams, bG as V2Site, bn as V2SiteUser, bq as V2SiteUserListParams, bp as V2SiteUserMeUpdateParams, bs as V2SiteUserProfile, bM as V2SiteUserSubscription, bo as V2SiteUserUpdateParams, br as V2SiteUserWithProfile, bO as V2SubscriptionCancelParams, bP as V2SubscriptionChangePlanParams, bQ as V2SubscriptionChargeParams, bR as V2SubscriptionChargeResult, bN as V2SubscriptionPauseParams, bJ as V2Webhook, bK as V2WebhookCreateParams, bI as V2WebhookEventType, bL as V2WebhookUpdateParams, c3 as WebhookEventType, aB as createApiError, az as createPerspectApiV2Client } from './index-
|
|
1
|
+
import { H as HttpClient, C as CacheManager, A as ApiResponse, a as CachePolicy, b as CacheInvalidateOptions, U as User, c as ContentQueryParams, P as PaginatedResponse, d as Content, e as ContentCategoryResponse, f as CreateContentRequest, g as UpdateContentRequest, h as ApiKey, i as CreateApiKeyRequest, j as UpdateApiKeyRequest, O as Organization, k as CreateOrganizationRequest, S as Site, l as CreateSiteRequest, m as ProductQueryParams, n as Product, o as CreateProductRequest, p as ProductSku, q as CreateProductSkuRequest, r as Category, s as CreateCategoryRequest, W as Webhook, t as CreateWebhookRequest, u as CreateCheckoutSessionRequest, v as CheckoutSession, w as CreateContactRequest, x as ContactSubmitResponse, y as ContactStatusResponse, z as ContactSubmission, B as CreateNewsletterSubscriptionRequest, N as NewsletterSubscribeResponse, D as NewsletterConfirmResponse, E as NewsletterUnsubscribeRequest, F as NewsletterUnsubscribeResponse, G as NewsletterPreferences, I as NewsletterList, J as NewsletterCampaignListResponse, K as NewsletterCampaignDetail, L as NewsletterStatusResponse, M as NewsletterManagementSubscriptionsListResponse, Q as NewsletterManagementSubscription, R as NewsletterSubscriptionSyncRequest, T as NewsletterSubscriptionSyncResponse, V as NewsletterSubscriptionsBulkUpdateRequest, X as NewsletterSubscriptionsBulkUpdateResponse, Y as NewsletterSubscriptionMembershipUpdateRequest, Z as NewsletterSubscriptionsImportRequest, _ as NewsletterSubscriptionsImportResponse, $ as NewsletterManagementList, a0 as NewsletterManagementSeries, a1 as NewsletterManagementCampaignListResponse, a2 as NewsletterManagementCampaign, a3 as NewsletterCampaignTestSendRequest, a4 as NewsletterCampaignTestSendResponse, a5 as NewsletterManagementStatsResponse, a6 as NewsletterExportCreateRequest, a7 as NewsletterExportCreateResponse, a8 as RequestOtpRequest, a9 as VerifyOtpRequest, aa as VerifyOtpResponse, ab as SiteUser, ac as SiteUserProfile, ad as UpdateSiteUserRequest, ae as SiteUserOrder, af as SiteUserSubscription, ag as CancelSubscriptionRequest, ah as CancelSubscriptionResponse, ai as CreditBalance, aj as CreditBalanceWithTransactions, ak as GrantCreditRequest, al as ProductBundleGroup, am as CreateBundleGroupRequest, an as BundleCollection, ao as BundleCollectionItemWithProduct, ap as CreateBundleCollectionRequest, aq as AddCollectionItemRequest, ar as BundleCollectionItem, as as PerspectApiConfig, at as CacheAdapter, au as BlogPost, av as CheckoutMetadata, aw as CheckoutAddress, ax as CheckoutTaxRequest } from './index-BbTVcEl5.mjs';
|
|
2
|
+
export { aE as ApiError, aD as CacheConfig, aG as CategorySummary, c4 as CheckoutMetadataValue, c9 as CheckoutSessionTax, c8 as CheckoutTaxBreakdownItem, c7 as CheckoutTaxCustomerExemptionRequest, c6 as CheckoutTaxExemptionStatus, c5 as CheckoutTaxStrategy, b_ as ContentStatus, b$ as ContentType, c2 as CreatePaymentGatewayRequest, cb as CreditTransaction, cc as HttpMethod, aF as MediaItem, aJ as NewsletterCampaignSummary, aK as NewsletterManagementListMembership, aP as NewsletterManagementPagination, aI as NewsletterSubscription, aN as NewsletterSubscriptionImportRowRequest, aL as NewsletterSubscriptionsBulkAction, aM as NewsletterSubscriptionsBulkOutcome, aO as NewsletterSubscriptionsImportRowResult, bZ as PaginationParams, aH as PaymentGateway, aC as PerspectApiError, ay as PerspectApiV2Client, aA as PerspectV2Error, c0 as ProductSkuMediaItem, c1 as ProductSkuOption, cd as RequestOptions, aQ as SetProfileValueRequest, ca as SubscriptionCancellationMode, bH as V2ApiKey, bS as V2CancelSubscriptionResult, b4 as V2Category, b5 as V2CategoryCreateParams, b6 as V2CategoryUpdateParams, b7 as V2Collection, b9 as V2CollectionCreateParams, b8 as V2CollectionItem, ba as V2CollectionUpdateParams, bE as V2ContactSubmission, aY as V2Content, aZ as V2ContentCreateParams, a$ as V2ContentListParams, a_ as V2ContentUpdateParams, bU as V2CreditBalance, bT as V2CreditTransaction, aT as V2Deleted, bX as V2EmailSendParams, bY as V2EmailSendResult, aU as V2Error, aV as V2ErrorType, bV as V2GrantCreditParams, bW as V2GrantCreditResult, aS as V2List, aX as V2Media, bv as V2NewsletterCampaign, bC as V2NewsletterImportRequest, bD as V2NewsletterImportResult, bu as V2NewsletterList, bx as V2NewsletterListCreateParams, by as V2NewsletterListUpdateParams, bt as V2NewsletterSubscription, bB as V2NewsletterSubscriptionListMembershipUpdate, bz as V2NewsletterSyncInput, bA as V2NewsletterSyncResult, bw as V2NewsletterTrackingResponse, aR as V2Object, bb as V2Order, bf as V2OrderAddress, bh as V2OrderCreateParams, bm as V2OrderCreateResult, bj as V2OrderFulfillmentNotificationLineItem, bk as V2OrderFulfillmentNotificationParams, bl as V2OrderFulfillmentNotificationResult, bi as V2OrderFulfillmentUpdate, be as V2OrderLineItem, bd as V2OrderLineItemPriceData, bc as V2OrderListParams, bg as V2OrderTaxRequest, bF as V2Organization, aW as V2PaginationParams, b0 as V2Product, b1 as V2ProductCreateParams, b3 as V2ProductListParams, b2 as V2ProductUpdateParams, bG as V2Site, bn as V2SiteUser, bq as V2SiteUserListParams, bp as V2SiteUserMeUpdateParams, bs as V2SiteUserProfile, bM as V2SiteUserSubscription, bo as V2SiteUserUpdateParams, br as V2SiteUserWithProfile, bO as V2SubscriptionCancelParams, bP as V2SubscriptionChangePlanParams, bQ as V2SubscriptionChargeParams, bR as V2SubscriptionChargeResult, bN as V2SubscriptionPauseParams, bJ as V2Webhook, bK as V2WebhookCreateParams, bI as V2WebhookEventType, bL as V2WebhookUpdateParams, c3 as WebhookEventType, aB as createApiError, az as createPerspectApiV2Client } from './index-BbTVcEl5.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* v1 deprecation constants — kept in sync with the backend's
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HttpClient, C as CacheManager, A as ApiResponse, a as CachePolicy, b as CacheInvalidateOptions, U as User, c as ContentQueryParams, P as PaginatedResponse, d as Content, e as ContentCategoryResponse, f as CreateContentRequest, g as UpdateContentRequest, h as ApiKey, i as CreateApiKeyRequest, j as UpdateApiKeyRequest, O as Organization, k as CreateOrganizationRequest, S as Site, l as CreateSiteRequest, m as ProductQueryParams, n as Product, o as CreateProductRequest, p as ProductSku, q as CreateProductSkuRequest, r as Category, s as CreateCategoryRequest, W as Webhook, t as CreateWebhookRequest, u as CreateCheckoutSessionRequest, v as CheckoutSession, w as CreateContactRequest, x as ContactSubmitResponse, y as ContactStatusResponse, z as ContactSubmission, B as CreateNewsletterSubscriptionRequest, N as NewsletterSubscribeResponse, D as NewsletterConfirmResponse, E as NewsletterUnsubscribeRequest, F as NewsletterUnsubscribeResponse, G as NewsletterPreferences, I as NewsletterList, J as NewsletterCampaignListResponse, K as NewsletterCampaignDetail, L as NewsletterStatusResponse, M as NewsletterManagementSubscriptionsListResponse, Q as NewsletterManagementSubscription, R as NewsletterSubscriptionSyncRequest, T as NewsletterSubscriptionSyncResponse, V as NewsletterSubscriptionsBulkUpdateRequest, X as NewsletterSubscriptionsBulkUpdateResponse, Y as NewsletterSubscriptionMembershipUpdateRequest, Z as NewsletterSubscriptionsImportRequest, _ as NewsletterSubscriptionsImportResponse, $ as NewsletterManagementList, a0 as NewsletterManagementSeries, a1 as NewsletterManagementCampaignListResponse, a2 as NewsletterManagementCampaign, a3 as NewsletterCampaignTestSendRequest, a4 as NewsletterCampaignTestSendResponse, a5 as NewsletterManagementStatsResponse, a6 as NewsletterExportCreateRequest, a7 as NewsletterExportCreateResponse, a8 as RequestOtpRequest, a9 as VerifyOtpRequest, aa as VerifyOtpResponse, ab as SiteUser, ac as SiteUserProfile, ad as UpdateSiteUserRequest, ae as SiteUserOrder, af as SiteUserSubscription, ag as CancelSubscriptionRequest, ah as CancelSubscriptionResponse, ai as CreditBalance, aj as CreditBalanceWithTransactions, ak as GrantCreditRequest, al as ProductBundleGroup, am as CreateBundleGroupRequest, an as BundleCollection, ao as BundleCollectionItemWithProduct, ap as CreateBundleCollectionRequest, aq as AddCollectionItemRequest, ar as BundleCollectionItem, as as PerspectApiConfig, at as CacheAdapter, au as BlogPost, av as CheckoutMetadata, aw as CheckoutAddress, ax as CheckoutTaxRequest } from './index-
|
|
2
|
-
export { aE as ApiError, aD as CacheConfig, aG as CategorySummary, c4 as CheckoutMetadataValue, c9 as CheckoutSessionTax, c8 as CheckoutTaxBreakdownItem, c7 as CheckoutTaxCustomerExemptionRequest, c6 as CheckoutTaxExemptionStatus, c5 as CheckoutTaxStrategy, b_ as ContentStatus, b$ as ContentType, c2 as CreatePaymentGatewayRequest, cb as CreditTransaction, cc as HttpMethod, aF as MediaItem, aJ as NewsletterCampaignSummary, aK as NewsletterManagementListMembership, aP as NewsletterManagementPagination, aI as NewsletterSubscription, aN as NewsletterSubscriptionImportRowRequest, aL as NewsletterSubscriptionsBulkAction, aM as NewsletterSubscriptionsBulkOutcome, aO as NewsletterSubscriptionsImportRowResult, bZ as PaginationParams, aH as PaymentGateway, aC as PerspectApiError, ay as PerspectApiV2Client, aA as PerspectV2Error, c0 as ProductSkuMediaItem, c1 as ProductSkuOption, cd as RequestOptions, aQ as SetProfileValueRequest, ca as SubscriptionCancellationMode, bH as V2ApiKey, bS as V2CancelSubscriptionResult, b4 as V2Category, b5 as V2CategoryCreateParams, b6 as V2CategoryUpdateParams, b7 as V2Collection, b9 as V2CollectionCreateParams, b8 as V2CollectionItem, ba as V2CollectionUpdateParams, bE as V2ContactSubmission, aY as V2Content, aZ as V2ContentCreateParams, a$ as V2ContentListParams, a_ as V2ContentUpdateParams, bU as V2CreditBalance, bT as V2CreditTransaction, aT as V2Deleted, bX as V2EmailSendParams, bY as V2EmailSendResult, aU as V2Error, aV as V2ErrorType, bV as V2GrantCreditParams, bW as V2GrantCreditResult, aS as V2List, aX as V2Media, bv as V2NewsletterCampaign, bC as V2NewsletterImportRequest, bD as V2NewsletterImportResult, bu as V2NewsletterList, bx as V2NewsletterListCreateParams, by as V2NewsletterListUpdateParams, bt as V2NewsletterSubscription, bB as V2NewsletterSubscriptionListMembershipUpdate, bz as V2NewsletterSyncInput, bA as V2NewsletterSyncResult, bw as V2NewsletterTrackingResponse, aR as V2Object, bb as V2Order, bf as V2OrderAddress, bh as V2OrderCreateParams, bm as V2OrderCreateResult, bj as V2OrderFulfillmentNotificationLineItem, bk as V2OrderFulfillmentNotificationParams, bl as V2OrderFulfillmentNotificationResult, bi as V2OrderFulfillmentUpdate, be as V2OrderLineItem, bd as V2OrderLineItemPriceData, bc as V2OrderListParams, bg as V2OrderTaxRequest, bF as V2Organization, aW as V2PaginationParams, b0 as V2Product, b1 as V2ProductCreateParams, b3 as V2ProductListParams, b2 as V2ProductUpdateParams, bG as V2Site, bn as V2SiteUser, bq as V2SiteUserListParams, bp as V2SiteUserMeUpdateParams, bs as V2SiteUserProfile, bM as V2SiteUserSubscription, bo as V2SiteUserUpdateParams, br as V2SiteUserWithProfile, bO as V2SubscriptionCancelParams, bP as V2SubscriptionChangePlanParams, bQ as V2SubscriptionChargeParams, bR as V2SubscriptionChargeResult, bN as V2SubscriptionPauseParams, bJ as V2Webhook, bK as V2WebhookCreateParams, bI as V2WebhookEventType, bL as V2WebhookUpdateParams, c3 as WebhookEventType, aB as createApiError, az as createPerspectApiV2Client } from './index-
|
|
1
|
+
import { H as HttpClient, C as CacheManager, A as ApiResponse, a as CachePolicy, b as CacheInvalidateOptions, U as User, c as ContentQueryParams, P as PaginatedResponse, d as Content, e as ContentCategoryResponse, f as CreateContentRequest, g as UpdateContentRequest, h as ApiKey, i as CreateApiKeyRequest, j as UpdateApiKeyRequest, O as Organization, k as CreateOrganizationRequest, S as Site, l as CreateSiteRequest, m as ProductQueryParams, n as Product, o as CreateProductRequest, p as ProductSku, q as CreateProductSkuRequest, r as Category, s as CreateCategoryRequest, W as Webhook, t as CreateWebhookRequest, u as CreateCheckoutSessionRequest, v as CheckoutSession, w as CreateContactRequest, x as ContactSubmitResponse, y as ContactStatusResponse, z as ContactSubmission, B as CreateNewsletterSubscriptionRequest, N as NewsletterSubscribeResponse, D as NewsletterConfirmResponse, E as NewsletterUnsubscribeRequest, F as NewsletterUnsubscribeResponse, G as NewsletterPreferences, I as NewsletterList, J as NewsletterCampaignListResponse, K as NewsletterCampaignDetail, L as NewsletterStatusResponse, M as NewsletterManagementSubscriptionsListResponse, Q as NewsletterManagementSubscription, R as NewsletterSubscriptionSyncRequest, T as NewsletterSubscriptionSyncResponse, V as NewsletterSubscriptionsBulkUpdateRequest, X as NewsletterSubscriptionsBulkUpdateResponse, Y as NewsletterSubscriptionMembershipUpdateRequest, Z as NewsletterSubscriptionsImportRequest, _ as NewsletterSubscriptionsImportResponse, $ as NewsletterManagementList, a0 as NewsletterManagementSeries, a1 as NewsletterManagementCampaignListResponse, a2 as NewsletterManagementCampaign, a3 as NewsletterCampaignTestSendRequest, a4 as NewsletterCampaignTestSendResponse, a5 as NewsletterManagementStatsResponse, a6 as NewsletterExportCreateRequest, a7 as NewsletterExportCreateResponse, a8 as RequestOtpRequest, a9 as VerifyOtpRequest, aa as VerifyOtpResponse, ab as SiteUser, ac as SiteUserProfile, ad as UpdateSiteUserRequest, ae as SiteUserOrder, af as SiteUserSubscription, ag as CancelSubscriptionRequest, ah as CancelSubscriptionResponse, ai as CreditBalance, aj as CreditBalanceWithTransactions, ak as GrantCreditRequest, al as ProductBundleGroup, am as CreateBundleGroupRequest, an as BundleCollection, ao as BundleCollectionItemWithProduct, ap as CreateBundleCollectionRequest, aq as AddCollectionItemRequest, ar as BundleCollectionItem, as as PerspectApiConfig, at as CacheAdapter, au as BlogPost, av as CheckoutMetadata, aw as CheckoutAddress, ax as CheckoutTaxRequest } from './index-BbTVcEl5.js';
|
|
2
|
+
export { aE as ApiError, aD as CacheConfig, aG as CategorySummary, c4 as CheckoutMetadataValue, c9 as CheckoutSessionTax, c8 as CheckoutTaxBreakdownItem, c7 as CheckoutTaxCustomerExemptionRequest, c6 as CheckoutTaxExemptionStatus, c5 as CheckoutTaxStrategy, b_ as ContentStatus, b$ as ContentType, c2 as CreatePaymentGatewayRequest, cb as CreditTransaction, cc as HttpMethod, aF as MediaItem, aJ as NewsletterCampaignSummary, aK as NewsletterManagementListMembership, aP as NewsletterManagementPagination, aI as NewsletterSubscription, aN as NewsletterSubscriptionImportRowRequest, aL as NewsletterSubscriptionsBulkAction, aM as NewsletterSubscriptionsBulkOutcome, aO as NewsletterSubscriptionsImportRowResult, bZ as PaginationParams, aH as PaymentGateway, aC as PerspectApiError, ay as PerspectApiV2Client, aA as PerspectV2Error, c0 as ProductSkuMediaItem, c1 as ProductSkuOption, cd as RequestOptions, aQ as SetProfileValueRequest, ca as SubscriptionCancellationMode, bH as V2ApiKey, bS as V2CancelSubscriptionResult, b4 as V2Category, b5 as V2CategoryCreateParams, b6 as V2CategoryUpdateParams, b7 as V2Collection, b9 as V2CollectionCreateParams, b8 as V2CollectionItem, ba as V2CollectionUpdateParams, bE as V2ContactSubmission, aY as V2Content, aZ as V2ContentCreateParams, a$ as V2ContentListParams, a_ as V2ContentUpdateParams, bU as V2CreditBalance, bT as V2CreditTransaction, aT as V2Deleted, bX as V2EmailSendParams, bY as V2EmailSendResult, aU as V2Error, aV as V2ErrorType, bV as V2GrantCreditParams, bW as V2GrantCreditResult, aS as V2List, aX as V2Media, bv as V2NewsletterCampaign, bC as V2NewsletterImportRequest, bD as V2NewsletterImportResult, bu as V2NewsletterList, bx as V2NewsletterListCreateParams, by as V2NewsletterListUpdateParams, bt as V2NewsletterSubscription, bB as V2NewsletterSubscriptionListMembershipUpdate, bz as V2NewsletterSyncInput, bA as V2NewsletterSyncResult, bw as V2NewsletterTrackingResponse, aR as V2Object, bb as V2Order, bf as V2OrderAddress, bh as V2OrderCreateParams, bm as V2OrderCreateResult, bj as V2OrderFulfillmentNotificationLineItem, bk as V2OrderFulfillmentNotificationParams, bl as V2OrderFulfillmentNotificationResult, bi as V2OrderFulfillmentUpdate, be as V2OrderLineItem, bd as V2OrderLineItemPriceData, bc as V2OrderListParams, bg as V2OrderTaxRequest, bF as V2Organization, aW as V2PaginationParams, b0 as V2Product, b1 as V2ProductCreateParams, b3 as V2ProductListParams, b2 as V2ProductUpdateParams, bG as V2Site, bn as V2SiteUser, bq as V2SiteUserListParams, bp as V2SiteUserMeUpdateParams, bs as V2SiteUserProfile, bM as V2SiteUserSubscription, bo as V2SiteUserUpdateParams, br as V2SiteUserWithProfile, bO as V2SubscriptionCancelParams, bP as V2SubscriptionChangePlanParams, bQ as V2SubscriptionChargeParams, bR as V2SubscriptionChargeResult, bN as V2SubscriptionPauseParams, bJ as V2Webhook, bK as V2WebhookCreateParams, bI as V2WebhookEventType, bL as V2WebhookUpdateParams, c3 as WebhookEventType, aB as createApiError, az as createPerspectApiV2Client } from './index-BbTVcEl5.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* v1 deprecation constants — kept in sync with the backend's
|
package/dist/index.js
CHANGED
|
@@ -666,7 +666,9 @@ var BaseV2Client = class {
|
|
|
666
666
|
/** GET a single resource, with optional caching. */
|
|
667
667
|
async getOne(path, params, cachePolicy) {
|
|
668
668
|
const fetcher = async () => {
|
|
669
|
-
const response = await this.
|
|
669
|
+
const response = await this.runRequest(
|
|
670
|
+
() => this.http.get(path, this.toParams(params))
|
|
671
|
+
);
|
|
670
672
|
return this.extractData(response);
|
|
671
673
|
};
|
|
672
674
|
return this.fetchWithCache(path, params, cachePolicy, fetcher);
|
|
@@ -674,29 +676,31 @@ var BaseV2Client = class {
|
|
|
674
676
|
/** GET a list of resources with cursor pagination, with optional caching. */
|
|
675
677
|
async getList(path, params, cachePolicy) {
|
|
676
678
|
const fetcher = async () => {
|
|
677
|
-
const response = await this.
|
|
679
|
+
const response = await this.runRequest(
|
|
680
|
+
() => this.http.get(path, this.toParams(params))
|
|
681
|
+
);
|
|
678
682
|
return this.extractData(response);
|
|
679
683
|
};
|
|
680
684
|
return this.fetchWithCache(path, params, cachePolicy, fetcher);
|
|
681
685
|
}
|
|
682
686
|
/** POST to create a resource. */
|
|
683
687
|
async post(path, body) {
|
|
684
|
-
const response = await this.http.post(path, body);
|
|
688
|
+
const response = await this.runRequest(() => this.http.post(path, body));
|
|
685
689
|
return this.extractData(response);
|
|
686
690
|
}
|
|
687
691
|
/** PATCH to update a resource. */
|
|
688
692
|
async patchOne(path, body) {
|
|
689
|
-
const response = await this.http.patch(path, body);
|
|
693
|
+
const response = await this.runRequest(() => this.http.patch(path, body));
|
|
690
694
|
return this.extractData(response);
|
|
691
695
|
}
|
|
692
696
|
/** PUT to upsert a resource. */
|
|
693
697
|
async putOne(path, body) {
|
|
694
|
-
const response = await this.http.put(path, body);
|
|
698
|
+
const response = await this.runRequest(() => this.http.put(path, body));
|
|
695
699
|
return this.extractData(response);
|
|
696
700
|
}
|
|
697
701
|
/** DELETE a resource. */
|
|
698
702
|
async deleteOne(path) {
|
|
699
|
-
const response = await this.http.delete(path);
|
|
703
|
+
const response = await this.runRequest(() => this.http.delete(path));
|
|
700
704
|
return this.extractData(response);
|
|
701
705
|
}
|
|
702
706
|
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
@@ -752,6 +756,38 @@ var BaseV2Client = class {
|
|
|
752
756
|
}
|
|
753
757
|
}
|
|
754
758
|
}
|
|
759
|
+
/**
|
|
760
|
+
* Run an HttpClient call and convert v2 error responses to PerspectV2Error.
|
|
761
|
+
*
|
|
762
|
+
* `HttpClient` throws `PerspectApiError` on any non-2xx, with the parsed
|
|
763
|
+
* body on `.details` and the HTTP status on `.status`. For v2 endpoints
|
|
764
|
+
* that body is `{ error: { type, code, message, param? } }` — the
|
|
765
|
+
* documented `PerspectV2Error` shape. Anything else (network failures,
|
|
766
|
+
* non-JSON bodies, malformed envelopes) is rethrown unchanged so callers
|
|
767
|
+
* still see the original error. Named `runRequest` rather than `send` to
|
|
768
|
+
* avoid colliding with subclass domain methods (e.g. EmailV2Client.send).
|
|
769
|
+
*/
|
|
770
|
+
async runRequest(call) {
|
|
771
|
+
try {
|
|
772
|
+
return await call();
|
|
773
|
+
} catch (err) {
|
|
774
|
+
const v2 = this.toV2ErrorFromThrown(err);
|
|
775
|
+
if (v2) throw v2;
|
|
776
|
+
throw err;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
toV2ErrorFromThrown(err) {
|
|
780
|
+
if (!err || typeof err !== "object") return void 0;
|
|
781
|
+
const e = err;
|
|
782
|
+
const details = e.details;
|
|
783
|
+
if (!details || typeof details !== "object") return void 0;
|
|
784
|
+
const envelope = details.error;
|
|
785
|
+
if (!envelope || typeof envelope !== "object" || !("type" in envelope) || !("message" in envelope)) {
|
|
786
|
+
return void 0;
|
|
787
|
+
}
|
|
788
|
+
const status = typeof e.status === "number" ? e.status : 500;
|
|
789
|
+
return new PerspectV2Error(envelope, status);
|
|
790
|
+
}
|
|
755
791
|
toError(response) {
|
|
756
792
|
const data = response.data;
|
|
757
793
|
const errorObj = data?.error ?? response.error;
|
|
@@ -1445,6 +1481,13 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1445
1481
|
params ?? {}
|
|
1446
1482
|
);
|
|
1447
1483
|
}
|
|
1484
|
+
/** Change the plan (price) of a user's subscription (admin). */
|
|
1485
|
+
async changeUserSubscriptionPlan(siteName, userId, subId, params) {
|
|
1486
|
+
return this.post(
|
|
1487
|
+
this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/change-plan`),
|
|
1488
|
+
params
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1448
1491
|
/** Charge a user's subscription once (admin). */
|
|
1449
1492
|
async chargeUserSubscription(siteName, userId, subId, params) {
|
|
1450
1493
|
return this.post(
|
package/dist/index.mjs
CHANGED
package/dist/v2/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { cq as ApiKeysV2Client, cf as BaseV2Client, ci as CategoriesV2Client, cj as CollectionsV2Client, cn as ContactsV2Client, cg as ContentV2Client, ct as CreditsV2Client, cu as EmailV2Client, cm as NewsletterV2Client, ck as OrdersV2Client, co as OrganizationsV2Client, ay as PerspectApiV2Client, ce as PerspectApiV2Config, aA as PerspectV2Error, ch as ProductsV2Client, cl as SiteUsersV2Client, cp as SitesV2Client, cs as SubscriptionsV2Client, bH as V2ApiKey, bS as V2CancelSubscriptionResult, b4 as V2Category, b5 as V2CategoryCreateParams, b6 as V2CategoryUpdateParams, b7 as V2Collection, b9 as V2CollectionCreateParams, b8 as V2CollectionItem, ba as V2CollectionUpdateParams, bE as V2ContactSubmission, aY as V2Content, aZ as V2ContentCreateParams, a$ as V2ContentListParams, a_ as V2ContentUpdateParams, bU as V2CreditBalance, bT as V2CreditTransaction, aT as V2Deleted, bX as V2EmailSendParams, bY as V2EmailSendResult, aU as V2Error, aV as V2ErrorType, bV as V2GrantCreditParams, bW as V2GrantCreditResult, aS as V2List, aX as V2Media, bv as V2NewsletterCampaign, bC as V2NewsletterImportRequest, bD as V2NewsletterImportResult, bu as V2NewsletterList, bx as V2NewsletterListCreateParams, by as V2NewsletterListUpdateParams, bt as V2NewsletterSubscription, bB as V2NewsletterSubscriptionListMembershipUpdate, bz as V2NewsletterSyncInput, bA as V2NewsletterSyncResult, bw as V2NewsletterTrackingResponse, aR as V2Object, bb as V2Order, bf as V2OrderAddress, bh as V2OrderCreateParams, bm as V2OrderCreateResult, bj as V2OrderFulfillmentNotificationLineItem, bk as V2OrderFulfillmentNotificationParams, bl as V2OrderFulfillmentNotificationResult, bi as V2OrderFulfillmentUpdate, be as V2OrderLineItem, bd as V2OrderLineItemPriceData, bc as V2OrderListParams, bg as V2OrderTaxRequest, bF as V2Organization, aW as V2PaginationParams, b0 as V2Product, b1 as V2ProductCreateParams, b3 as V2ProductListParams, b2 as V2ProductUpdateParams, bG as V2Site, bn as V2SiteUser, bq as V2SiteUserListParams, bp as V2SiteUserMeUpdateParams, bs as V2SiteUserProfile, bM as V2SiteUserSubscription, bo as V2SiteUserUpdateParams, br as V2SiteUserWithProfile, bO as V2SubscriptionCancelParams, bP as V2SubscriptionChangePlanParams, bQ as V2SubscriptionChargeParams, bR as V2SubscriptionChargeResult, bN as V2SubscriptionPauseParams, bJ as V2Webhook, bK as V2WebhookCreateParams, bI as V2WebhookEventType, bL as V2WebhookUpdateParams, cr as WebhooksV2Client, az as createPerspectApiV2Client } from '../index-
|
|
1
|
+
export { cq as ApiKeysV2Client, cf as BaseV2Client, ci as CategoriesV2Client, cj as CollectionsV2Client, cn as ContactsV2Client, cg as ContentV2Client, ct as CreditsV2Client, cu as EmailV2Client, cm as NewsletterV2Client, ck as OrdersV2Client, co as OrganizationsV2Client, ay as PerspectApiV2Client, ce as PerspectApiV2Config, aA as PerspectV2Error, ch as ProductsV2Client, cl as SiteUsersV2Client, cp as SitesV2Client, cs as SubscriptionsV2Client, bH as V2ApiKey, bS as V2CancelSubscriptionResult, b4 as V2Category, b5 as V2CategoryCreateParams, b6 as V2CategoryUpdateParams, b7 as V2Collection, b9 as V2CollectionCreateParams, b8 as V2CollectionItem, ba as V2CollectionUpdateParams, bE as V2ContactSubmission, aY as V2Content, aZ as V2ContentCreateParams, a$ as V2ContentListParams, a_ as V2ContentUpdateParams, bU as V2CreditBalance, bT as V2CreditTransaction, aT as V2Deleted, bX as V2EmailSendParams, bY as V2EmailSendResult, aU as V2Error, aV as V2ErrorType, bV as V2GrantCreditParams, bW as V2GrantCreditResult, aS as V2List, aX as V2Media, bv as V2NewsletterCampaign, bC as V2NewsletterImportRequest, bD as V2NewsletterImportResult, bu as V2NewsletterList, bx as V2NewsletterListCreateParams, by as V2NewsletterListUpdateParams, bt as V2NewsletterSubscription, bB as V2NewsletterSubscriptionListMembershipUpdate, bz as V2NewsletterSyncInput, bA as V2NewsletterSyncResult, bw as V2NewsletterTrackingResponse, aR as V2Object, bb as V2Order, bf as V2OrderAddress, bh as V2OrderCreateParams, bm as V2OrderCreateResult, bj as V2OrderFulfillmentNotificationLineItem, bk as V2OrderFulfillmentNotificationParams, bl as V2OrderFulfillmentNotificationResult, bi as V2OrderFulfillmentUpdate, be as V2OrderLineItem, bd as V2OrderLineItemPriceData, bc as V2OrderListParams, bg as V2OrderTaxRequest, bF as V2Organization, aW as V2PaginationParams, b0 as V2Product, b1 as V2ProductCreateParams, b3 as V2ProductListParams, b2 as V2ProductUpdateParams, bG as V2Site, bn as V2SiteUser, bq as V2SiteUserListParams, bp as V2SiteUserMeUpdateParams, bs as V2SiteUserProfile, bM as V2SiteUserSubscription, bo as V2SiteUserUpdateParams, br as V2SiteUserWithProfile, bO as V2SubscriptionCancelParams, bP as V2SubscriptionChangePlanParams, bQ as V2SubscriptionChargeParams, bR as V2SubscriptionChargeResult, bN as V2SubscriptionPauseParams, bJ as V2Webhook, bK as V2WebhookCreateParams, bI as V2WebhookEventType, bL as V2WebhookUpdateParams, cr as WebhooksV2Client, az as createPerspectApiV2Client } from '../index-BbTVcEl5.mjs';
|
package/dist/v2/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { cq as ApiKeysV2Client, cf as BaseV2Client, ci as CategoriesV2Client, cj as CollectionsV2Client, cn as ContactsV2Client, cg as ContentV2Client, ct as CreditsV2Client, cu as EmailV2Client, cm as NewsletterV2Client, ck as OrdersV2Client, co as OrganizationsV2Client, ay as PerspectApiV2Client, ce as PerspectApiV2Config, aA as PerspectV2Error, ch as ProductsV2Client, cl as SiteUsersV2Client, cp as SitesV2Client, cs as SubscriptionsV2Client, bH as V2ApiKey, bS as V2CancelSubscriptionResult, b4 as V2Category, b5 as V2CategoryCreateParams, b6 as V2CategoryUpdateParams, b7 as V2Collection, b9 as V2CollectionCreateParams, b8 as V2CollectionItem, ba as V2CollectionUpdateParams, bE as V2ContactSubmission, aY as V2Content, aZ as V2ContentCreateParams, a$ as V2ContentListParams, a_ as V2ContentUpdateParams, bU as V2CreditBalance, bT as V2CreditTransaction, aT as V2Deleted, bX as V2EmailSendParams, bY as V2EmailSendResult, aU as V2Error, aV as V2ErrorType, bV as V2GrantCreditParams, bW as V2GrantCreditResult, aS as V2List, aX as V2Media, bv as V2NewsletterCampaign, bC as V2NewsletterImportRequest, bD as V2NewsletterImportResult, bu as V2NewsletterList, bx as V2NewsletterListCreateParams, by as V2NewsletterListUpdateParams, bt as V2NewsletterSubscription, bB as V2NewsletterSubscriptionListMembershipUpdate, bz as V2NewsletterSyncInput, bA as V2NewsletterSyncResult, bw as V2NewsletterTrackingResponse, aR as V2Object, bb as V2Order, bf as V2OrderAddress, bh as V2OrderCreateParams, bm as V2OrderCreateResult, bj as V2OrderFulfillmentNotificationLineItem, bk as V2OrderFulfillmentNotificationParams, bl as V2OrderFulfillmentNotificationResult, bi as V2OrderFulfillmentUpdate, be as V2OrderLineItem, bd as V2OrderLineItemPriceData, bc as V2OrderListParams, bg as V2OrderTaxRequest, bF as V2Organization, aW as V2PaginationParams, b0 as V2Product, b1 as V2ProductCreateParams, b3 as V2ProductListParams, b2 as V2ProductUpdateParams, bG as V2Site, bn as V2SiteUser, bq as V2SiteUserListParams, bp as V2SiteUserMeUpdateParams, bs as V2SiteUserProfile, bM as V2SiteUserSubscription, bo as V2SiteUserUpdateParams, br as V2SiteUserWithProfile, bO as V2SubscriptionCancelParams, bP as V2SubscriptionChangePlanParams, bQ as V2SubscriptionChargeParams, bR as V2SubscriptionChargeResult, bN as V2SubscriptionPauseParams, bJ as V2Webhook, bK as V2WebhookCreateParams, bI as V2WebhookEventType, bL as V2WebhookUpdateParams, cr as WebhooksV2Client, az as createPerspectApiV2Client } from '../index-
|
|
1
|
+
export { cq as ApiKeysV2Client, cf as BaseV2Client, ci as CategoriesV2Client, cj as CollectionsV2Client, cn as ContactsV2Client, cg as ContentV2Client, ct as CreditsV2Client, cu as EmailV2Client, cm as NewsletterV2Client, ck as OrdersV2Client, co as OrganizationsV2Client, ay as PerspectApiV2Client, ce as PerspectApiV2Config, aA as PerspectV2Error, ch as ProductsV2Client, cl as SiteUsersV2Client, cp as SitesV2Client, cs as SubscriptionsV2Client, bH as V2ApiKey, bS as V2CancelSubscriptionResult, b4 as V2Category, b5 as V2CategoryCreateParams, b6 as V2CategoryUpdateParams, b7 as V2Collection, b9 as V2CollectionCreateParams, b8 as V2CollectionItem, ba as V2CollectionUpdateParams, bE as V2ContactSubmission, aY as V2Content, aZ as V2ContentCreateParams, a$ as V2ContentListParams, a_ as V2ContentUpdateParams, bU as V2CreditBalance, bT as V2CreditTransaction, aT as V2Deleted, bX as V2EmailSendParams, bY as V2EmailSendResult, aU as V2Error, aV as V2ErrorType, bV as V2GrantCreditParams, bW as V2GrantCreditResult, aS as V2List, aX as V2Media, bv as V2NewsletterCampaign, bC as V2NewsletterImportRequest, bD as V2NewsletterImportResult, bu as V2NewsletterList, bx as V2NewsletterListCreateParams, by as V2NewsletterListUpdateParams, bt as V2NewsletterSubscription, bB as V2NewsletterSubscriptionListMembershipUpdate, bz as V2NewsletterSyncInput, bA as V2NewsletterSyncResult, bw as V2NewsletterTrackingResponse, aR as V2Object, bb as V2Order, bf as V2OrderAddress, bh as V2OrderCreateParams, bm as V2OrderCreateResult, bj as V2OrderFulfillmentNotificationLineItem, bk as V2OrderFulfillmentNotificationParams, bl as V2OrderFulfillmentNotificationResult, bi as V2OrderFulfillmentUpdate, be as V2OrderLineItem, bd as V2OrderLineItemPriceData, bc as V2OrderListParams, bg as V2OrderTaxRequest, bF as V2Organization, aW as V2PaginationParams, b0 as V2Product, b1 as V2ProductCreateParams, b3 as V2ProductListParams, b2 as V2ProductUpdateParams, bG as V2Site, bn as V2SiteUser, bq as V2SiteUserListParams, bp as V2SiteUserMeUpdateParams, bs as V2SiteUserProfile, bM as V2SiteUserSubscription, bo as V2SiteUserUpdateParams, br as V2SiteUserWithProfile, bO as V2SubscriptionCancelParams, bP as V2SubscriptionChangePlanParams, bQ as V2SubscriptionChargeParams, bR as V2SubscriptionChargeResult, bN as V2SubscriptionPauseParams, bJ as V2Webhook, bK as V2WebhookCreateParams, bI as V2WebhookEventType, bL as V2WebhookUpdateParams, cr as WebhooksV2Client, az as createPerspectApiV2Client } from '../index-BbTVcEl5.js';
|
package/dist/v2/index.js
CHANGED
|
@@ -612,7 +612,9 @@ var BaseV2Client = class {
|
|
|
612
612
|
/** GET a single resource, with optional caching. */
|
|
613
613
|
async getOne(path, params, cachePolicy) {
|
|
614
614
|
const fetcher = async () => {
|
|
615
|
-
const response = await this.
|
|
615
|
+
const response = await this.runRequest(
|
|
616
|
+
() => this.http.get(path, this.toParams(params))
|
|
617
|
+
);
|
|
616
618
|
return this.extractData(response);
|
|
617
619
|
};
|
|
618
620
|
return this.fetchWithCache(path, params, cachePolicy, fetcher);
|
|
@@ -620,29 +622,31 @@ var BaseV2Client = class {
|
|
|
620
622
|
/** GET a list of resources with cursor pagination, with optional caching. */
|
|
621
623
|
async getList(path, params, cachePolicy) {
|
|
622
624
|
const fetcher = async () => {
|
|
623
|
-
const response = await this.
|
|
625
|
+
const response = await this.runRequest(
|
|
626
|
+
() => this.http.get(path, this.toParams(params))
|
|
627
|
+
);
|
|
624
628
|
return this.extractData(response);
|
|
625
629
|
};
|
|
626
630
|
return this.fetchWithCache(path, params, cachePolicy, fetcher);
|
|
627
631
|
}
|
|
628
632
|
/** POST to create a resource. */
|
|
629
633
|
async post(path, body) {
|
|
630
|
-
const response = await this.http.post(path, body);
|
|
634
|
+
const response = await this.runRequest(() => this.http.post(path, body));
|
|
631
635
|
return this.extractData(response);
|
|
632
636
|
}
|
|
633
637
|
/** PATCH to update a resource. */
|
|
634
638
|
async patchOne(path, body) {
|
|
635
|
-
const response = await this.http.patch(path, body);
|
|
639
|
+
const response = await this.runRequest(() => this.http.patch(path, body));
|
|
636
640
|
return this.extractData(response);
|
|
637
641
|
}
|
|
638
642
|
/** PUT to upsert a resource. */
|
|
639
643
|
async putOne(path, body) {
|
|
640
|
-
const response = await this.http.put(path, body);
|
|
644
|
+
const response = await this.runRequest(() => this.http.put(path, body));
|
|
641
645
|
return this.extractData(response);
|
|
642
646
|
}
|
|
643
647
|
/** DELETE a resource. */
|
|
644
648
|
async deleteOne(path) {
|
|
645
|
-
const response = await this.http.delete(path);
|
|
649
|
+
const response = await this.runRequest(() => this.http.delete(path));
|
|
646
650
|
return this.extractData(response);
|
|
647
651
|
}
|
|
648
652
|
/** Fetch with optional cache. Bypasses cache for writes or when no cache is configured. */
|
|
@@ -698,6 +702,38 @@ var BaseV2Client = class {
|
|
|
698
702
|
}
|
|
699
703
|
}
|
|
700
704
|
}
|
|
705
|
+
/**
|
|
706
|
+
* Run an HttpClient call and convert v2 error responses to PerspectV2Error.
|
|
707
|
+
*
|
|
708
|
+
* `HttpClient` throws `PerspectApiError` on any non-2xx, with the parsed
|
|
709
|
+
* body on `.details` and the HTTP status on `.status`. For v2 endpoints
|
|
710
|
+
* that body is `{ error: { type, code, message, param? } }` — the
|
|
711
|
+
* documented `PerspectV2Error` shape. Anything else (network failures,
|
|
712
|
+
* non-JSON bodies, malformed envelopes) is rethrown unchanged so callers
|
|
713
|
+
* still see the original error. Named `runRequest` rather than `send` to
|
|
714
|
+
* avoid colliding with subclass domain methods (e.g. EmailV2Client.send).
|
|
715
|
+
*/
|
|
716
|
+
async runRequest(call) {
|
|
717
|
+
try {
|
|
718
|
+
return await call();
|
|
719
|
+
} catch (err) {
|
|
720
|
+
const v2 = this.toV2ErrorFromThrown(err);
|
|
721
|
+
if (v2) throw v2;
|
|
722
|
+
throw err;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
toV2ErrorFromThrown(err) {
|
|
726
|
+
if (!err || typeof err !== "object") return void 0;
|
|
727
|
+
const e = err;
|
|
728
|
+
const details = e.details;
|
|
729
|
+
if (!details || typeof details !== "object") return void 0;
|
|
730
|
+
const envelope = details.error;
|
|
731
|
+
if (!envelope || typeof envelope !== "object" || !("type" in envelope) || !("message" in envelope)) {
|
|
732
|
+
return void 0;
|
|
733
|
+
}
|
|
734
|
+
const status = typeof e.status === "number" ? e.status : 500;
|
|
735
|
+
return new PerspectV2Error(envelope, status);
|
|
736
|
+
}
|
|
701
737
|
toError(response) {
|
|
702
738
|
const data = response.data;
|
|
703
739
|
const errorObj = data?.error ?? response.error;
|
|
@@ -1391,6 +1427,13 @@ var SubscriptionsV2Client = class extends BaseV2Client {
|
|
|
1391
1427
|
params ?? {}
|
|
1392
1428
|
);
|
|
1393
1429
|
}
|
|
1430
|
+
/** Change the plan (price) of a user's subscription (admin). */
|
|
1431
|
+
async changeUserSubscriptionPlan(siteName, userId, subId, params) {
|
|
1432
|
+
return this.post(
|
|
1433
|
+
this.sitePath(siteName, "users", `${userId}/subscriptions/${subId}/change-plan`),
|
|
1434
|
+
params
|
|
1435
|
+
);
|
|
1436
|
+
}
|
|
1394
1437
|
/** Charge a user's subscription once (admin). */
|
|
1395
1438
|
async chargeUserSubscription(siteName, userId, subId, params) {
|
|
1396
1439
|
return this.post(
|
package/dist/v2/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -98,7 +98,9 @@ export abstract class BaseV2Client {
|
|
|
98
98
|
/** GET a single resource, with optional caching. */
|
|
99
99
|
protected async getOne<T>(path: string, params?: object, cachePolicy?: CachePolicy): Promise<T> {
|
|
100
100
|
const fetcher = async () => {
|
|
101
|
-
const response = await this.
|
|
101
|
+
const response = await this.runRequest(() =>
|
|
102
|
+
this.http.get<T>(path, this.toParams(params)),
|
|
103
|
+
);
|
|
102
104
|
return this.extractData<T>(response);
|
|
103
105
|
};
|
|
104
106
|
return this.fetchWithCache(path, params, cachePolicy, fetcher);
|
|
@@ -111,7 +113,9 @@ export abstract class BaseV2Client {
|
|
|
111
113
|
cachePolicy?: CachePolicy,
|
|
112
114
|
): Promise<V2List<T>> {
|
|
113
115
|
const fetcher = async () => {
|
|
114
|
-
const response = await this.
|
|
116
|
+
const response = await this.runRequest(() =>
|
|
117
|
+
this.http.get<V2List<T>>(path, this.toParams(params)),
|
|
118
|
+
);
|
|
115
119
|
return this.extractData<V2List<T>>(response);
|
|
116
120
|
};
|
|
117
121
|
return this.fetchWithCache(path, params, cachePolicy, fetcher);
|
|
@@ -119,25 +123,25 @@ export abstract class BaseV2Client {
|
|
|
119
123
|
|
|
120
124
|
/** POST to create a resource. */
|
|
121
125
|
protected async post<T>(path: string, body?: unknown): Promise<T> {
|
|
122
|
-
const response = await this.http.post<T>(path, body);
|
|
126
|
+
const response = await this.runRequest(() => this.http.post<T>(path, body));
|
|
123
127
|
return this.extractData<T>(response);
|
|
124
128
|
}
|
|
125
129
|
|
|
126
130
|
/** PATCH to update a resource. */
|
|
127
131
|
protected async patchOne<T>(path: string, body?: unknown): Promise<T> {
|
|
128
|
-
const response = await this.http.patch<T>(path, body);
|
|
132
|
+
const response = await this.runRequest(() => this.http.patch<T>(path, body));
|
|
129
133
|
return this.extractData<T>(response);
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
/** PUT to upsert a resource. */
|
|
133
137
|
protected async putOne<T>(path: string, body?: unknown): Promise<T> {
|
|
134
|
-
const response = await this.http.put<T>(path, body);
|
|
138
|
+
const response = await this.runRequest(() => this.http.put<T>(path, body));
|
|
135
139
|
return this.extractData<T>(response);
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
/** DELETE a resource. */
|
|
139
143
|
protected async deleteOne(path: string): Promise<V2Deleted> {
|
|
140
|
-
const response = await this.http.delete<V2Deleted>(path);
|
|
144
|
+
const response = await this.runRequest(() => this.http.delete<V2Deleted>(path));
|
|
141
145
|
return this.extractData<V2Deleted>(response);
|
|
142
146
|
}
|
|
143
147
|
|
|
@@ -209,6 +213,45 @@ export abstract class BaseV2Client {
|
|
|
209
213
|
}
|
|
210
214
|
}
|
|
211
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Run an HttpClient call and convert v2 error responses to PerspectV2Error.
|
|
218
|
+
*
|
|
219
|
+
* `HttpClient` throws `PerspectApiError` on any non-2xx, with the parsed
|
|
220
|
+
* body on `.details` and the HTTP status on `.status`. For v2 endpoints
|
|
221
|
+
* that body is `{ error: { type, code, message, param? } }` — the
|
|
222
|
+
* documented `PerspectV2Error` shape. Anything else (network failures,
|
|
223
|
+
* non-JSON bodies, malformed envelopes) is rethrown unchanged so callers
|
|
224
|
+
* still see the original error. Named `runRequest` rather than `send` to
|
|
225
|
+
* avoid colliding with subclass domain methods (e.g. EmailV2Client.send).
|
|
226
|
+
*/
|
|
227
|
+
private async runRequest<R>(call: () => Promise<R>): Promise<R> {
|
|
228
|
+
try {
|
|
229
|
+
return await call();
|
|
230
|
+
} catch (err) {
|
|
231
|
+
const v2 = this.toV2ErrorFromThrown(err);
|
|
232
|
+
if (v2) throw v2;
|
|
233
|
+
throw err;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private toV2ErrorFromThrown(err: unknown): PerspectV2Error | undefined {
|
|
238
|
+
if (!err || typeof err !== 'object') return undefined;
|
|
239
|
+
const e = err as { status?: unknown; details?: unknown };
|
|
240
|
+
const details = e.details;
|
|
241
|
+
if (!details || typeof details !== 'object') return undefined;
|
|
242
|
+
const envelope = (details as { error?: unknown }).error;
|
|
243
|
+
if (
|
|
244
|
+
!envelope ||
|
|
245
|
+
typeof envelope !== 'object' ||
|
|
246
|
+
!('type' in envelope) ||
|
|
247
|
+
!('message' in envelope)
|
|
248
|
+
) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
const status = typeof e.status === 'number' ? e.status : 500;
|
|
252
|
+
return new PerspectV2Error(envelope as V2Error['error'], status);
|
|
253
|
+
}
|
|
254
|
+
|
|
212
255
|
private toError(response: { data?: unknown; error?: unknown; message?: string }): PerspectV2Error {
|
|
213
256
|
const data = response.data as Record<string, unknown> | undefined;
|
|
214
257
|
const errorObj = (data?.error ?? response.error) as V2Error['error'] | undefined;
|
|
@@ -133,6 +133,19 @@ export class SubscriptionsV2Client extends BaseV2Client {
|
|
|
133
133
|
);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
/** Change the plan (price) of a user's subscription (admin). */
|
|
137
|
+
async changeUserSubscriptionPlan(
|
|
138
|
+
siteName: string,
|
|
139
|
+
userId: string,
|
|
140
|
+
subId: string,
|
|
141
|
+
params: V2SubscriptionChangePlanParams,
|
|
142
|
+
): Promise<V2SiteUserSubscription> {
|
|
143
|
+
return this.post<V2SiteUserSubscription>(
|
|
144
|
+
this.sitePath(siteName, 'users', `${userId}/subscriptions/${subId}/change-plan`),
|
|
145
|
+
params,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
136
149
|
/** Charge a user's subscription once (admin). */
|
|
137
150
|
async chargeUserSubscription(
|
|
138
151
|
siteName: string,
|