perspectapi-ts-sdk 3.0.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +167 -1
- package/dist/index.d.ts +167 -1
- package/dist/index.js +261 -0
- package/dist/index.mjs +260 -0
- package/package.json +1 -1
- package/src/client/bundles-client.ts +263 -0
- package/src/client/site-users-client.ts +115 -0
- package/src/index.ts +8 -0
- package/src/perspect-api-client.ts +3 -0
- package/src/types/index.ts +92 -0
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
ApiKeysClient: () => ApiKeysClient,
|
|
24
24
|
AuthClient: () => AuthClient,
|
|
25
25
|
BaseClient: () => BaseClient,
|
|
26
|
+
BundlesClient: () => BundlesClient,
|
|
26
27
|
CacheManager: () => CacheManager,
|
|
27
28
|
CategoriesClient: () => CategoriesClient,
|
|
28
29
|
CheckoutClient: () => CheckoutClient,
|
|
@@ -2473,6 +2474,51 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2473
2474
|
csrfToken
|
|
2474
2475
|
);
|
|
2475
2476
|
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Pause a subscription via Stripe pause_collection
|
|
2479
|
+
* @param siteName - The site name
|
|
2480
|
+
* @param subscriptionId - Subscription ID
|
|
2481
|
+
* @param csrfToken - CSRF token (required)
|
|
2482
|
+
* @param resumesAt - Optional ISO date string when subscription should auto-resume
|
|
2483
|
+
*/
|
|
2484
|
+
async pauseSubscription(siteName, subscriptionId, csrfToken, resumesAt) {
|
|
2485
|
+
const body = {};
|
|
2486
|
+
if (resumesAt) {
|
|
2487
|
+
body.resumes_at = resumesAt;
|
|
2488
|
+
}
|
|
2489
|
+
return this.create(
|
|
2490
|
+
this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(subscriptionId)}/pause`),
|
|
2491
|
+
body,
|
|
2492
|
+
csrfToken
|
|
2493
|
+
);
|
|
2494
|
+
}
|
|
2495
|
+
/**
|
|
2496
|
+
* Resume a paused subscription
|
|
2497
|
+
* @param siteName - The site name
|
|
2498
|
+
* @param subscriptionId - Subscription ID
|
|
2499
|
+
* @param csrfToken - CSRF token (required)
|
|
2500
|
+
*/
|
|
2501
|
+
async resumeSubscription(siteName, subscriptionId, csrfToken) {
|
|
2502
|
+
return this.create(
|
|
2503
|
+
this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(subscriptionId)}/resume`),
|
|
2504
|
+
{},
|
|
2505
|
+
csrfToken
|
|
2506
|
+
);
|
|
2507
|
+
}
|
|
2508
|
+
/**
|
|
2509
|
+
* Change subscription plan tier
|
|
2510
|
+
* @param siteName - The site name
|
|
2511
|
+
* @param subscriptionId - Subscription ID
|
|
2512
|
+
* @param productId - New product ID to switch to
|
|
2513
|
+
* @param csrfToken - CSRF token (required)
|
|
2514
|
+
*/
|
|
2515
|
+
async changeSubscriptionPlan(siteName, subscriptionId, productId, csrfToken) {
|
|
2516
|
+
return this.create(
|
|
2517
|
+
this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(subscriptionId)}/change-plan`),
|
|
2518
|
+
{ product_id: productId },
|
|
2519
|
+
csrfToken
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2476
2522
|
/**
|
|
2477
2523
|
* Get linked newsletter subscriptions
|
|
2478
2524
|
* @param siteName - The site name
|
|
@@ -2483,6 +2529,29 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2483
2529
|
);
|
|
2484
2530
|
}
|
|
2485
2531
|
// ============================================================================
|
|
2532
|
+
// CREDIT ENDPOINTS (site user JWT required)
|
|
2533
|
+
// ============================================================================
|
|
2534
|
+
/**
|
|
2535
|
+
* Get current credit balance
|
|
2536
|
+
* @param siteName - The site name
|
|
2537
|
+
*/
|
|
2538
|
+
async getCreditBalance(siteName) {
|
|
2539
|
+
return this.getSingle(
|
|
2540
|
+
this.siteUserEndpoint(siteName, "/users/me/credits/balance")
|
|
2541
|
+
);
|
|
2542
|
+
}
|
|
2543
|
+
/**
|
|
2544
|
+
* Get credit balance and paginated transactions
|
|
2545
|
+
* @param siteName - The site name
|
|
2546
|
+
* @param params - Pagination params
|
|
2547
|
+
*/
|
|
2548
|
+
async getCreditTransactions(siteName, params) {
|
|
2549
|
+
return this.http.get(
|
|
2550
|
+
this.buildPath(this.siteUserEndpoint(siteName, "/users/me/credits")),
|
|
2551
|
+
params
|
|
2552
|
+
);
|
|
2553
|
+
}
|
|
2554
|
+
// ============================================================================
|
|
2486
2555
|
// ADMIN ENDPOINTS (API key auth required)
|
|
2487
2556
|
// ============================================================================
|
|
2488
2557
|
/**
|
|
@@ -2520,6 +2589,195 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2520
2589
|
csrfToken
|
|
2521
2590
|
);
|
|
2522
2591
|
}
|
|
2592
|
+
/**
|
|
2593
|
+
* Grant credit to a user (admin only)
|
|
2594
|
+
* Adds credit to the user's ledger and Stripe Customer Balance.
|
|
2595
|
+
* @param siteName - The site name
|
|
2596
|
+
* @param userId - User ID
|
|
2597
|
+
* @param data - Amount in cents and description
|
|
2598
|
+
* @param csrfToken - CSRF token (required)
|
|
2599
|
+
*/
|
|
2600
|
+
async grantCredit(siteName, userId, data, csrfToken) {
|
|
2601
|
+
return this.create(
|
|
2602
|
+
this.siteUserEndpoint(siteName, `/users/${encodeURIComponent(userId)}/credits/grant`),
|
|
2603
|
+
data,
|
|
2604
|
+
csrfToken
|
|
2605
|
+
);
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
|
|
2609
|
+
// src/client/bundles-client.ts
|
|
2610
|
+
var BundlesClient = class extends BaseClient {
|
|
2611
|
+
constructor(http, cache) {
|
|
2612
|
+
super(http, "/api/v1", cache);
|
|
2613
|
+
}
|
|
2614
|
+
// ============================================================================
|
|
2615
|
+
// BUNDLE GROUPS (structural "pick N items" on a product)
|
|
2616
|
+
// ============================================================================
|
|
2617
|
+
async getBundleGroups(siteName, productId, cachePolicy) {
|
|
2618
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2619
|
+
siteName,
|
|
2620
|
+
`/products/${productId}/bundle-groups`,
|
|
2621
|
+
{ includeSitesSegment: false }
|
|
2622
|
+
);
|
|
2623
|
+
const path = this.buildPath(endpoint);
|
|
2624
|
+
return this.fetchWithCache(
|
|
2625
|
+
endpoint,
|
|
2626
|
+
void 0,
|
|
2627
|
+
this.buildBundleTags(siteName, [`bundles:product:${productId}`]),
|
|
2628
|
+
cachePolicy,
|
|
2629
|
+
() => this.http.get(path)
|
|
2630
|
+
);
|
|
2631
|
+
}
|
|
2632
|
+
async createBundleGroup(siteName, productId, data) {
|
|
2633
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2634
|
+
siteName,
|
|
2635
|
+
`/products/${productId}/bundle-groups`,
|
|
2636
|
+
{ includeSitesSegment: false }
|
|
2637
|
+
);
|
|
2638
|
+
return this.create(endpoint, data);
|
|
2639
|
+
}
|
|
2640
|
+
async updateBundleGroup(siteName, productId, bundleGroupId, data) {
|
|
2641
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2642
|
+
siteName,
|
|
2643
|
+
`/products/${productId}/bundle-groups/${bundleGroupId}`,
|
|
2644
|
+
{ includeSitesSegment: false }
|
|
2645
|
+
);
|
|
2646
|
+
return this.patch(endpoint, data);
|
|
2647
|
+
}
|
|
2648
|
+
async deleteBundleGroup(siteName, productId, bundleGroupId) {
|
|
2649
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2650
|
+
siteName,
|
|
2651
|
+
`/products/${productId}/bundle-groups/${bundleGroupId}`,
|
|
2652
|
+
{ includeSitesSegment: false }
|
|
2653
|
+
);
|
|
2654
|
+
return this.delete(endpoint);
|
|
2655
|
+
}
|
|
2656
|
+
// ============================================================================
|
|
2657
|
+
// BUNDLE COLLECTIONS (time-bounded, site-scoped sets of products)
|
|
2658
|
+
// ============================================================================
|
|
2659
|
+
async getCollections(siteName, cachePolicy) {
|
|
2660
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2661
|
+
siteName,
|
|
2662
|
+
"/collections",
|
|
2663
|
+
{ includeSitesSegment: false }
|
|
2664
|
+
);
|
|
2665
|
+
const path = this.buildPath(endpoint);
|
|
2666
|
+
return this.fetchWithCache(
|
|
2667
|
+
endpoint,
|
|
2668
|
+
void 0,
|
|
2669
|
+
this.buildCollectionTags(siteName, ["collections:list"]),
|
|
2670
|
+
cachePolicy,
|
|
2671
|
+
() => this.http.get(path)
|
|
2672
|
+
);
|
|
2673
|
+
}
|
|
2674
|
+
async getCurrentCollection(siteName, cachePolicy) {
|
|
2675
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2676
|
+
siteName,
|
|
2677
|
+
"/collections/current",
|
|
2678
|
+
{ includeSitesSegment: false }
|
|
2679
|
+
);
|
|
2680
|
+
const path = this.buildPath(endpoint);
|
|
2681
|
+
return this.fetchWithCache(
|
|
2682
|
+
endpoint,
|
|
2683
|
+
void 0,
|
|
2684
|
+
this.buildCollectionTags(siteName, ["collections:current"]),
|
|
2685
|
+
cachePolicy,
|
|
2686
|
+
() => this.http.get(path)
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2689
|
+
async getCollection(siteName, collectionId, cachePolicy) {
|
|
2690
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2691
|
+
siteName,
|
|
2692
|
+
`/collections/${collectionId}`,
|
|
2693
|
+
{ includeSitesSegment: false }
|
|
2694
|
+
);
|
|
2695
|
+
const path = this.buildPath(endpoint);
|
|
2696
|
+
return this.fetchWithCache(
|
|
2697
|
+
endpoint,
|
|
2698
|
+
void 0,
|
|
2699
|
+
this.buildCollectionTags(siteName, [`collections:id:${collectionId}`]),
|
|
2700
|
+
cachePolicy,
|
|
2701
|
+
() => this.http.get(path)
|
|
2702
|
+
);
|
|
2703
|
+
}
|
|
2704
|
+
async createCollection(siteName, data) {
|
|
2705
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2706
|
+
siteName,
|
|
2707
|
+
"/collections",
|
|
2708
|
+
{ includeSitesSegment: false }
|
|
2709
|
+
);
|
|
2710
|
+
return this.create(endpoint, data);
|
|
2711
|
+
}
|
|
2712
|
+
async updateCollection(siteName, collectionId, data) {
|
|
2713
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2714
|
+
siteName,
|
|
2715
|
+
`/collections/${collectionId}`,
|
|
2716
|
+
{ includeSitesSegment: false }
|
|
2717
|
+
);
|
|
2718
|
+
return this.patch(endpoint, data);
|
|
2719
|
+
}
|
|
2720
|
+
async deleteCollection(siteName, collectionId) {
|
|
2721
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2722
|
+
siteName,
|
|
2723
|
+
`/collections/${collectionId}`,
|
|
2724
|
+
{ includeSitesSegment: false }
|
|
2725
|
+
);
|
|
2726
|
+
return this.delete(endpoint);
|
|
2727
|
+
}
|
|
2728
|
+
// ============================================================================
|
|
2729
|
+
// COLLECTION ITEMS
|
|
2730
|
+
// ============================================================================
|
|
2731
|
+
async getCollectionItems(siteName, collectionId, cachePolicy) {
|
|
2732
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2733
|
+
siteName,
|
|
2734
|
+
`/collections/${collectionId}/items`,
|
|
2735
|
+
{ includeSitesSegment: false }
|
|
2736
|
+
);
|
|
2737
|
+
const path = this.buildPath(endpoint);
|
|
2738
|
+
return this.fetchWithCache(
|
|
2739
|
+
endpoint,
|
|
2740
|
+
void 0,
|
|
2741
|
+
this.buildCollectionTags(siteName, [`collections:items:${collectionId}`]),
|
|
2742
|
+
cachePolicy,
|
|
2743
|
+
() => this.http.get(path)
|
|
2744
|
+
);
|
|
2745
|
+
}
|
|
2746
|
+
async addCollectionItem(siteName, collectionId, data) {
|
|
2747
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2748
|
+
siteName,
|
|
2749
|
+
`/collections/${collectionId}/items`,
|
|
2750
|
+
{ includeSitesSegment: false }
|
|
2751
|
+
);
|
|
2752
|
+
return this.create(endpoint, data);
|
|
2753
|
+
}
|
|
2754
|
+
async removeCollectionItem(siteName, collectionId, itemId) {
|
|
2755
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2756
|
+
siteName,
|
|
2757
|
+
`/collections/${collectionId}/items/${itemId}`,
|
|
2758
|
+
{ includeSitesSegment: false }
|
|
2759
|
+
);
|
|
2760
|
+
return this.delete(endpoint);
|
|
2761
|
+
}
|
|
2762
|
+
// ============================================================================
|
|
2763
|
+
// CACHE TAGS
|
|
2764
|
+
// ============================================================================
|
|
2765
|
+
buildBundleTags(siteName, extraTags = []) {
|
|
2766
|
+
const tags = /* @__PURE__ */ new Set(["bundles"]);
|
|
2767
|
+
if (siteName) {
|
|
2768
|
+
tags.add(`bundles:site:${siteName}`);
|
|
2769
|
+
}
|
|
2770
|
+
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
2771
|
+
return Array.from(tags.values());
|
|
2772
|
+
}
|
|
2773
|
+
buildCollectionTags(siteName, extraTags = []) {
|
|
2774
|
+
const tags = /* @__PURE__ */ new Set(["collections"]);
|
|
2775
|
+
if (siteName) {
|
|
2776
|
+
tags.add(`collections:site:${siteName}`);
|
|
2777
|
+
}
|
|
2778
|
+
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
2779
|
+
return Array.from(tags.values());
|
|
2780
|
+
}
|
|
2523
2781
|
};
|
|
2524
2782
|
|
|
2525
2783
|
// src/perspect-api-client.ts
|
|
@@ -2539,6 +2797,7 @@ var PerspectApiClient = class {
|
|
|
2539
2797
|
contact;
|
|
2540
2798
|
newsletter;
|
|
2541
2799
|
siteUsers;
|
|
2800
|
+
bundles;
|
|
2542
2801
|
constructor(config) {
|
|
2543
2802
|
if (!config.baseUrl) {
|
|
2544
2803
|
throw new Error("baseUrl is required in PerspectApiConfig");
|
|
@@ -2557,6 +2816,7 @@ var PerspectApiClient = class {
|
|
|
2557
2816
|
this.contact = new ContactClient(this.http, this.cache);
|
|
2558
2817
|
this.newsletter = new NewsletterClient(this.http, this.cache);
|
|
2559
2818
|
this.siteUsers = new SiteUsersClient(this.http, this.cache);
|
|
2819
|
+
this.bundles = new BundlesClient(this.http, this.cache);
|
|
2560
2820
|
}
|
|
2561
2821
|
/**
|
|
2562
2822
|
* Update authentication token
|
|
@@ -3233,6 +3493,7 @@ async function createCheckoutSession(options) {
|
|
|
3233
3493
|
ApiKeysClient,
|
|
3234
3494
|
AuthClient,
|
|
3235
3495
|
BaseClient,
|
|
3496
|
+
BundlesClient,
|
|
3236
3497
|
CacheManager,
|
|
3237
3498
|
CategoriesClient,
|
|
3238
3499
|
CheckoutClient,
|
package/dist/index.mjs
CHANGED
|
@@ -2411,6 +2411,51 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2411
2411
|
csrfToken
|
|
2412
2412
|
);
|
|
2413
2413
|
}
|
|
2414
|
+
/**
|
|
2415
|
+
* Pause a subscription via Stripe pause_collection
|
|
2416
|
+
* @param siteName - The site name
|
|
2417
|
+
* @param subscriptionId - Subscription ID
|
|
2418
|
+
* @param csrfToken - CSRF token (required)
|
|
2419
|
+
* @param resumesAt - Optional ISO date string when subscription should auto-resume
|
|
2420
|
+
*/
|
|
2421
|
+
async pauseSubscription(siteName, subscriptionId, csrfToken, resumesAt) {
|
|
2422
|
+
const body = {};
|
|
2423
|
+
if (resumesAt) {
|
|
2424
|
+
body.resumes_at = resumesAt;
|
|
2425
|
+
}
|
|
2426
|
+
return this.create(
|
|
2427
|
+
this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(subscriptionId)}/pause`),
|
|
2428
|
+
body,
|
|
2429
|
+
csrfToken
|
|
2430
|
+
);
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* Resume a paused subscription
|
|
2434
|
+
* @param siteName - The site name
|
|
2435
|
+
* @param subscriptionId - Subscription ID
|
|
2436
|
+
* @param csrfToken - CSRF token (required)
|
|
2437
|
+
*/
|
|
2438
|
+
async resumeSubscription(siteName, subscriptionId, csrfToken) {
|
|
2439
|
+
return this.create(
|
|
2440
|
+
this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(subscriptionId)}/resume`),
|
|
2441
|
+
{},
|
|
2442
|
+
csrfToken
|
|
2443
|
+
);
|
|
2444
|
+
}
|
|
2445
|
+
/**
|
|
2446
|
+
* Change subscription plan tier
|
|
2447
|
+
* @param siteName - The site name
|
|
2448
|
+
* @param subscriptionId - Subscription ID
|
|
2449
|
+
* @param productId - New product ID to switch to
|
|
2450
|
+
* @param csrfToken - CSRF token (required)
|
|
2451
|
+
*/
|
|
2452
|
+
async changeSubscriptionPlan(siteName, subscriptionId, productId, csrfToken) {
|
|
2453
|
+
return this.create(
|
|
2454
|
+
this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(subscriptionId)}/change-plan`),
|
|
2455
|
+
{ product_id: productId },
|
|
2456
|
+
csrfToken
|
|
2457
|
+
);
|
|
2458
|
+
}
|
|
2414
2459
|
/**
|
|
2415
2460
|
* Get linked newsletter subscriptions
|
|
2416
2461
|
* @param siteName - The site name
|
|
@@ -2421,6 +2466,29 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2421
2466
|
);
|
|
2422
2467
|
}
|
|
2423
2468
|
// ============================================================================
|
|
2469
|
+
// CREDIT ENDPOINTS (site user JWT required)
|
|
2470
|
+
// ============================================================================
|
|
2471
|
+
/**
|
|
2472
|
+
* Get current credit balance
|
|
2473
|
+
* @param siteName - The site name
|
|
2474
|
+
*/
|
|
2475
|
+
async getCreditBalance(siteName) {
|
|
2476
|
+
return this.getSingle(
|
|
2477
|
+
this.siteUserEndpoint(siteName, "/users/me/credits/balance")
|
|
2478
|
+
);
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Get credit balance and paginated transactions
|
|
2482
|
+
* @param siteName - The site name
|
|
2483
|
+
* @param params - Pagination params
|
|
2484
|
+
*/
|
|
2485
|
+
async getCreditTransactions(siteName, params) {
|
|
2486
|
+
return this.http.get(
|
|
2487
|
+
this.buildPath(this.siteUserEndpoint(siteName, "/users/me/credits")),
|
|
2488
|
+
params
|
|
2489
|
+
);
|
|
2490
|
+
}
|
|
2491
|
+
// ============================================================================
|
|
2424
2492
|
// ADMIN ENDPOINTS (API key auth required)
|
|
2425
2493
|
// ============================================================================
|
|
2426
2494
|
/**
|
|
@@ -2458,6 +2526,195 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2458
2526
|
csrfToken
|
|
2459
2527
|
);
|
|
2460
2528
|
}
|
|
2529
|
+
/**
|
|
2530
|
+
* Grant credit to a user (admin only)
|
|
2531
|
+
* Adds credit to the user's ledger and Stripe Customer Balance.
|
|
2532
|
+
* @param siteName - The site name
|
|
2533
|
+
* @param userId - User ID
|
|
2534
|
+
* @param data - Amount in cents and description
|
|
2535
|
+
* @param csrfToken - CSRF token (required)
|
|
2536
|
+
*/
|
|
2537
|
+
async grantCredit(siteName, userId, data, csrfToken) {
|
|
2538
|
+
return this.create(
|
|
2539
|
+
this.siteUserEndpoint(siteName, `/users/${encodeURIComponent(userId)}/credits/grant`),
|
|
2540
|
+
data,
|
|
2541
|
+
csrfToken
|
|
2542
|
+
);
|
|
2543
|
+
}
|
|
2544
|
+
};
|
|
2545
|
+
|
|
2546
|
+
// src/client/bundles-client.ts
|
|
2547
|
+
var BundlesClient = class extends BaseClient {
|
|
2548
|
+
constructor(http, cache) {
|
|
2549
|
+
super(http, "/api/v1", cache);
|
|
2550
|
+
}
|
|
2551
|
+
// ============================================================================
|
|
2552
|
+
// BUNDLE GROUPS (structural "pick N items" on a product)
|
|
2553
|
+
// ============================================================================
|
|
2554
|
+
async getBundleGroups(siteName, productId, cachePolicy) {
|
|
2555
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2556
|
+
siteName,
|
|
2557
|
+
`/products/${productId}/bundle-groups`,
|
|
2558
|
+
{ includeSitesSegment: false }
|
|
2559
|
+
);
|
|
2560
|
+
const path = this.buildPath(endpoint);
|
|
2561
|
+
return this.fetchWithCache(
|
|
2562
|
+
endpoint,
|
|
2563
|
+
void 0,
|
|
2564
|
+
this.buildBundleTags(siteName, [`bundles:product:${productId}`]),
|
|
2565
|
+
cachePolicy,
|
|
2566
|
+
() => this.http.get(path)
|
|
2567
|
+
);
|
|
2568
|
+
}
|
|
2569
|
+
async createBundleGroup(siteName, productId, data) {
|
|
2570
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2571
|
+
siteName,
|
|
2572
|
+
`/products/${productId}/bundle-groups`,
|
|
2573
|
+
{ includeSitesSegment: false }
|
|
2574
|
+
);
|
|
2575
|
+
return this.create(endpoint, data);
|
|
2576
|
+
}
|
|
2577
|
+
async updateBundleGroup(siteName, productId, bundleGroupId, data) {
|
|
2578
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2579
|
+
siteName,
|
|
2580
|
+
`/products/${productId}/bundle-groups/${bundleGroupId}`,
|
|
2581
|
+
{ includeSitesSegment: false }
|
|
2582
|
+
);
|
|
2583
|
+
return this.patch(endpoint, data);
|
|
2584
|
+
}
|
|
2585
|
+
async deleteBundleGroup(siteName, productId, bundleGroupId) {
|
|
2586
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2587
|
+
siteName,
|
|
2588
|
+
`/products/${productId}/bundle-groups/${bundleGroupId}`,
|
|
2589
|
+
{ includeSitesSegment: false }
|
|
2590
|
+
);
|
|
2591
|
+
return this.delete(endpoint);
|
|
2592
|
+
}
|
|
2593
|
+
// ============================================================================
|
|
2594
|
+
// BUNDLE COLLECTIONS (time-bounded, site-scoped sets of products)
|
|
2595
|
+
// ============================================================================
|
|
2596
|
+
async getCollections(siteName, cachePolicy) {
|
|
2597
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2598
|
+
siteName,
|
|
2599
|
+
"/collections",
|
|
2600
|
+
{ includeSitesSegment: false }
|
|
2601
|
+
);
|
|
2602
|
+
const path = this.buildPath(endpoint);
|
|
2603
|
+
return this.fetchWithCache(
|
|
2604
|
+
endpoint,
|
|
2605
|
+
void 0,
|
|
2606
|
+
this.buildCollectionTags(siteName, ["collections:list"]),
|
|
2607
|
+
cachePolicy,
|
|
2608
|
+
() => this.http.get(path)
|
|
2609
|
+
);
|
|
2610
|
+
}
|
|
2611
|
+
async getCurrentCollection(siteName, cachePolicy) {
|
|
2612
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2613
|
+
siteName,
|
|
2614
|
+
"/collections/current",
|
|
2615
|
+
{ includeSitesSegment: false }
|
|
2616
|
+
);
|
|
2617
|
+
const path = this.buildPath(endpoint);
|
|
2618
|
+
return this.fetchWithCache(
|
|
2619
|
+
endpoint,
|
|
2620
|
+
void 0,
|
|
2621
|
+
this.buildCollectionTags(siteName, ["collections:current"]),
|
|
2622
|
+
cachePolicy,
|
|
2623
|
+
() => this.http.get(path)
|
|
2624
|
+
);
|
|
2625
|
+
}
|
|
2626
|
+
async getCollection(siteName, collectionId, cachePolicy) {
|
|
2627
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2628
|
+
siteName,
|
|
2629
|
+
`/collections/${collectionId}`,
|
|
2630
|
+
{ includeSitesSegment: false }
|
|
2631
|
+
);
|
|
2632
|
+
const path = this.buildPath(endpoint);
|
|
2633
|
+
return this.fetchWithCache(
|
|
2634
|
+
endpoint,
|
|
2635
|
+
void 0,
|
|
2636
|
+
this.buildCollectionTags(siteName, [`collections:id:${collectionId}`]),
|
|
2637
|
+
cachePolicy,
|
|
2638
|
+
() => this.http.get(path)
|
|
2639
|
+
);
|
|
2640
|
+
}
|
|
2641
|
+
async createCollection(siteName, data) {
|
|
2642
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2643
|
+
siteName,
|
|
2644
|
+
"/collections",
|
|
2645
|
+
{ includeSitesSegment: false }
|
|
2646
|
+
);
|
|
2647
|
+
return this.create(endpoint, data);
|
|
2648
|
+
}
|
|
2649
|
+
async updateCollection(siteName, collectionId, data) {
|
|
2650
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2651
|
+
siteName,
|
|
2652
|
+
`/collections/${collectionId}`,
|
|
2653
|
+
{ includeSitesSegment: false }
|
|
2654
|
+
);
|
|
2655
|
+
return this.patch(endpoint, data);
|
|
2656
|
+
}
|
|
2657
|
+
async deleteCollection(siteName, collectionId) {
|
|
2658
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2659
|
+
siteName,
|
|
2660
|
+
`/collections/${collectionId}`,
|
|
2661
|
+
{ includeSitesSegment: false }
|
|
2662
|
+
);
|
|
2663
|
+
return this.delete(endpoint);
|
|
2664
|
+
}
|
|
2665
|
+
// ============================================================================
|
|
2666
|
+
// COLLECTION ITEMS
|
|
2667
|
+
// ============================================================================
|
|
2668
|
+
async getCollectionItems(siteName, collectionId, cachePolicy) {
|
|
2669
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2670
|
+
siteName,
|
|
2671
|
+
`/collections/${collectionId}/items`,
|
|
2672
|
+
{ includeSitesSegment: false }
|
|
2673
|
+
);
|
|
2674
|
+
const path = this.buildPath(endpoint);
|
|
2675
|
+
return this.fetchWithCache(
|
|
2676
|
+
endpoint,
|
|
2677
|
+
void 0,
|
|
2678
|
+
this.buildCollectionTags(siteName, [`collections:items:${collectionId}`]),
|
|
2679
|
+
cachePolicy,
|
|
2680
|
+
() => this.http.get(path)
|
|
2681
|
+
);
|
|
2682
|
+
}
|
|
2683
|
+
async addCollectionItem(siteName, collectionId, data) {
|
|
2684
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2685
|
+
siteName,
|
|
2686
|
+
`/collections/${collectionId}/items`,
|
|
2687
|
+
{ includeSitesSegment: false }
|
|
2688
|
+
);
|
|
2689
|
+
return this.create(endpoint, data);
|
|
2690
|
+
}
|
|
2691
|
+
async removeCollectionItem(siteName, collectionId, itemId) {
|
|
2692
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2693
|
+
siteName,
|
|
2694
|
+
`/collections/${collectionId}/items/${itemId}`,
|
|
2695
|
+
{ includeSitesSegment: false }
|
|
2696
|
+
);
|
|
2697
|
+
return this.delete(endpoint);
|
|
2698
|
+
}
|
|
2699
|
+
// ============================================================================
|
|
2700
|
+
// CACHE TAGS
|
|
2701
|
+
// ============================================================================
|
|
2702
|
+
buildBundleTags(siteName, extraTags = []) {
|
|
2703
|
+
const tags = /* @__PURE__ */ new Set(["bundles"]);
|
|
2704
|
+
if (siteName) {
|
|
2705
|
+
tags.add(`bundles:site:${siteName}`);
|
|
2706
|
+
}
|
|
2707
|
+
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
2708
|
+
return Array.from(tags.values());
|
|
2709
|
+
}
|
|
2710
|
+
buildCollectionTags(siteName, extraTags = []) {
|
|
2711
|
+
const tags = /* @__PURE__ */ new Set(["collections"]);
|
|
2712
|
+
if (siteName) {
|
|
2713
|
+
tags.add(`collections:site:${siteName}`);
|
|
2714
|
+
}
|
|
2715
|
+
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
2716
|
+
return Array.from(tags.values());
|
|
2717
|
+
}
|
|
2461
2718
|
};
|
|
2462
2719
|
|
|
2463
2720
|
// src/perspect-api-client.ts
|
|
@@ -2477,6 +2734,7 @@ var PerspectApiClient = class {
|
|
|
2477
2734
|
contact;
|
|
2478
2735
|
newsletter;
|
|
2479
2736
|
siteUsers;
|
|
2737
|
+
bundles;
|
|
2480
2738
|
constructor(config) {
|
|
2481
2739
|
if (!config.baseUrl) {
|
|
2482
2740
|
throw new Error("baseUrl is required in PerspectApiConfig");
|
|
@@ -2495,6 +2753,7 @@ var PerspectApiClient = class {
|
|
|
2495
2753
|
this.contact = new ContactClient(this.http, this.cache);
|
|
2496
2754
|
this.newsletter = new NewsletterClient(this.http, this.cache);
|
|
2497
2755
|
this.siteUsers = new SiteUsersClient(this.http, this.cache);
|
|
2756
|
+
this.bundles = new BundlesClient(this.http, this.cache);
|
|
2498
2757
|
}
|
|
2499
2758
|
/**
|
|
2500
2759
|
* Update authentication token
|
|
@@ -3170,6 +3429,7 @@ export {
|
|
|
3170
3429
|
ApiKeysClient,
|
|
3171
3430
|
AuthClient,
|
|
3172
3431
|
BaseClient,
|
|
3432
|
+
BundlesClient,
|
|
3173
3433
|
CacheManager,
|
|
3174
3434
|
CategoriesClient,
|
|
3175
3435
|
CheckoutClient,
|