perspectapi-ts-sdk 3.0.2 → 3.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 +151 -1
- package/dist/index.d.ts +151 -1
- package/dist/index.js +246 -0
- package/dist/index.mjs +245 -0
- package/package.json +1 -1
- package/src/client/bundles-client.ts +263 -0
- package/src/client/site-users-client.ts +93 -0
- package/src/index.ts +8 -0
- package/src/perspect-api-client.ts +3 -0
- package/src/types/index.ts +87 -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
|
/**
|
|
@@ -2522,6 +2591,180 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2522
2591
|
}
|
|
2523
2592
|
};
|
|
2524
2593
|
|
|
2594
|
+
// src/client/bundles-client.ts
|
|
2595
|
+
var BundlesClient = class extends BaseClient {
|
|
2596
|
+
constructor(http, cache) {
|
|
2597
|
+
super(http, "/api/v1", cache);
|
|
2598
|
+
}
|
|
2599
|
+
// ============================================================================
|
|
2600
|
+
// BUNDLE GROUPS (structural "pick N items" on a product)
|
|
2601
|
+
// ============================================================================
|
|
2602
|
+
async getBundleGroups(siteName, productId, cachePolicy) {
|
|
2603
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2604
|
+
siteName,
|
|
2605
|
+
`/products/${productId}/bundle-groups`,
|
|
2606
|
+
{ includeSitesSegment: false }
|
|
2607
|
+
);
|
|
2608
|
+
const path = this.buildPath(endpoint);
|
|
2609
|
+
return this.fetchWithCache(
|
|
2610
|
+
endpoint,
|
|
2611
|
+
void 0,
|
|
2612
|
+
this.buildBundleTags(siteName, [`bundles:product:${productId}`]),
|
|
2613
|
+
cachePolicy,
|
|
2614
|
+
() => this.http.get(path)
|
|
2615
|
+
);
|
|
2616
|
+
}
|
|
2617
|
+
async createBundleGroup(siteName, productId, data) {
|
|
2618
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2619
|
+
siteName,
|
|
2620
|
+
`/products/${productId}/bundle-groups`,
|
|
2621
|
+
{ includeSitesSegment: false }
|
|
2622
|
+
);
|
|
2623
|
+
return this.create(endpoint, data);
|
|
2624
|
+
}
|
|
2625
|
+
async updateBundleGroup(siteName, productId, bundleGroupId, data) {
|
|
2626
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2627
|
+
siteName,
|
|
2628
|
+
`/products/${productId}/bundle-groups/${bundleGroupId}`,
|
|
2629
|
+
{ includeSitesSegment: false }
|
|
2630
|
+
);
|
|
2631
|
+
return this.patch(endpoint, data);
|
|
2632
|
+
}
|
|
2633
|
+
async deleteBundleGroup(siteName, productId, bundleGroupId) {
|
|
2634
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2635
|
+
siteName,
|
|
2636
|
+
`/products/${productId}/bundle-groups/${bundleGroupId}`,
|
|
2637
|
+
{ includeSitesSegment: false }
|
|
2638
|
+
);
|
|
2639
|
+
return this.delete(endpoint);
|
|
2640
|
+
}
|
|
2641
|
+
// ============================================================================
|
|
2642
|
+
// BUNDLE COLLECTIONS (time-bounded, site-scoped sets of products)
|
|
2643
|
+
// ============================================================================
|
|
2644
|
+
async getCollections(siteName, cachePolicy) {
|
|
2645
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2646
|
+
siteName,
|
|
2647
|
+
"/collections",
|
|
2648
|
+
{ includeSitesSegment: false }
|
|
2649
|
+
);
|
|
2650
|
+
const path = this.buildPath(endpoint);
|
|
2651
|
+
return this.fetchWithCache(
|
|
2652
|
+
endpoint,
|
|
2653
|
+
void 0,
|
|
2654
|
+
this.buildCollectionTags(siteName, ["collections:list"]),
|
|
2655
|
+
cachePolicy,
|
|
2656
|
+
() => this.http.get(path)
|
|
2657
|
+
);
|
|
2658
|
+
}
|
|
2659
|
+
async getCurrentCollection(siteName, cachePolicy) {
|
|
2660
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2661
|
+
siteName,
|
|
2662
|
+
"/collections/current",
|
|
2663
|
+
{ includeSitesSegment: false }
|
|
2664
|
+
);
|
|
2665
|
+
const path = this.buildPath(endpoint);
|
|
2666
|
+
return this.fetchWithCache(
|
|
2667
|
+
endpoint,
|
|
2668
|
+
void 0,
|
|
2669
|
+
this.buildCollectionTags(siteName, ["collections:current"]),
|
|
2670
|
+
cachePolicy,
|
|
2671
|
+
() => this.http.get(path)
|
|
2672
|
+
);
|
|
2673
|
+
}
|
|
2674
|
+
async getCollection(siteName, collectionId, cachePolicy) {
|
|
2675
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2676
|
+
siteName,
|
|
2677
|
+
`/collections/${collectionId}`,
|
|
2678
|
+
{ includeSitesSegment: false }
|
|
2679
|
+
);
|
|
2680
|
+
const path = this.buildPath(endpoint);
|
|
2681
|
+
return this.fetchWithCache(
|
|
2682
|
+
endpoint,
|
|
2683
|
+
void 0,
|
|
2684
|
+
this.buildCollectionTags(siteName, [`collections:id:${collectionId}`]),
|
|
2685
|
+
cachePolicy,
|
|
2686
|
+
() => this.http.get(path)
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2689
|
+
async createCollection(siteName, data) {
|
|
2690
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2691
|
+
siteName,
|
|
2692
|
+
"/collections",
|
|
2693
|
+
{ includeSitesSegment: false }
|
|
2694
|
+
);
|
|
2695
|
+
return this.create(endpoint, data);
|
|
2696
|
+
}
|
|
2697
|
+
async updateCollection(siteName, collectionId, data) {
|
|
2698
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2699
|
+
siteName,
|
|
2700
|
+
`/collections/${collectionId}`,
|
|
2701
|
+
{ includeSitesSegment: false }
|
|
2702
|
+
);
|
|
2703
|
+
return this.patch(endpoint, data);
|
|
2704
|
+
}
|
|
2705
|
+
async deleteCollection(siteName, collectionId) {
|
|
2706
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2707
|
+
siteName,
|
|
2708
|
+
`/collections/${collectionId}`,
|
|
2709
|
+
{ includeSitesSegment: false }
|
|
2710
|
+
);
|
|
2711
|
+
return this.delete(endpoint);
|
|
2712
|
+
}
|
|
2713
|
+
// ============================================================================
|
|
2714
|
+
// COLLECTION ITEMS
|
|
2715
|
+
// ============================================================================
|
|
2716
|
+
async getCollectionItems(siteName, collectionId, cachePolicy) {
|
|
2717
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2718
|
+
siteName,
|
|
2719
|
+
`/collections/${collectionId}/items`,
|
|
2720
|
+
{ includeSitesSegment: false }
|
|
2721
|
+
);
|
|
2722
|
+
const path = this.buildPath(endpoint);
|
|
2723
|
+
return this.fetchWithCache(
|
|
2724
|
+
endpoint,
|
|
2725
|
+
void 0,
|
|
2726
|
+
this.buildCollectionTags(siteName, [`collections:items:${collectionId}`]),
|
|
2727
|
+
cachePolicy,
|
|
2728
|
+
() => this.http.get(path)
|
|
2729
|
+
);
|
|
2730
|
+
}
|
|
2731
|
+
async addCollectionItem(siteName, collectionId, data) {
|
|
2732
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2733
|
+
siteName,
|
|
2734
|
+
`/collections/${collectionId}/items`,
|
|
2735
|
+
{ includeSitesSegment: false }
|
|
2736
|
+
);
|
|
2737
|
+
return this.create(endpoint, data);
|
|
2738
|
+
}
|
|
2739
|
+
async removeCollectionItem(siteName, collectionId, itemId) {
|
|
2740
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2741
|
+
siteName,
|
|
2742
|
+
`/collections/${collectionId}/items/${itemId}`,
|
|
2743
|
+
{ includeSitesSegment: false }
|
|
2744
|
+
);
|
|
2745
|
+
return this.delete(endpoint);
|
|
2746
|
+
}
|
|
2747
|
+
// ============================================================================
|
|
2748
|
+
// CACHE TAGS
|
|
2749
|
+
// ============================================================================
|
|
2750
|
+
buildBundleTags(siteName, extraTags = []) {
|
|
2751
|
+
const tags = /* @__PURE__ */ new Set(["bundles"]);
|
|
2752
|
+
if (siteName) {
|
|
2753
|
+
tags.add(`bundles:site:${siteName}`);
|
|
2754
|
+
}
|
|
2755
|
+
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
2756
|
+
return Array.from(tags.values());
|
|
2757
|
+
}
|
|
2758
|
+
buildCollectionTags(siteName, extraTags = []) {
|
|
2759
|
+
const tags = /* @__PURE__ */ new Set(["collections"]);
|
|
2760
|
+
if (siteName) {
|
|
2761
|
+
tags.add(`collections:site:${siteName}`);
|
|
2762
|
+
}
|
|
2763
|
+
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
2764
|
+
return Array.from(tags.values());
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
|
|
2525
2768
|
// src/perspect-api-client.ts
|
|
2526
2769
|
var PerspectApiClient = class {
|
|
2527
2770
|
http;
|
|
@@ -2539,6 +2782,7 @@ var PerspectApiClient = class {
|
|
|
2539
2782
|
contact;
|
|
2540
2783
|
newsletter;
|
|
2541
2784
|
siteUsers;
|
|
2785
|
+
bundles;
|
|
2542
2786
|
constructor(config) {
|
|
2543
2787
|
if (!config.baseUrl) {
|
|
2544
2788
|
throw new Error("baseUrl is required in PerspectApiConfig");
|
|
@@ -2557,6 +2801,7 @@ var PerspectApiClient = class {
|
|
|
2557
2801
|
this.contact = new ContactClient(this.http, this.cache);
|
|
2558
2802
|
this.newsletter = new NewsletterClient(this.http, this.cache);
|
|
2559
2803
|
this.siteUsers = new SiteUsersClient(this.http, this.cache);
|
|
2804
|
+
this.bundles = new BundlesClient(this.http, this.cache);
|
|
2560
2805
|
}
|
|
2561
2806
|
/**
|
|
2562
2807
|
* Update authentication token
|
|
@@ -3233,6 +3478,7 @@ async function createCheckoutSession(options) {
|
|
|
3233
3478
|
ApiKeysClient,
|
|
3234
3479
|
AuthClient,
|
|
3235
3480
|
BaseClient,
|
|
3481
|
+
BundlesClient,
|
|
3236
3482
|
CacheManager,
|
|
3237
3483
|
CategoriesClient,
|
|
3238
3484
|
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
|
/**
|
|
@@ -2460,6 +2528,180 @@ var SiteUsersClient = class extends BaseClient {
|
|
|
2460
2528
|
}
|
|
2461
2529
|
};
|
|
2462
2530
|
|
|
2531
|
+
// src/client/bundles-client.ts
|
|
2532
|
+
var BundlesClient = class extends BaseClient {
|
|
2533
|
+
constructor(http, cache) {
|
|
2534
|
+
super(http, "/api/v1", cache);
|
|
2535
|
+
}
|
|
2536
|
+
// ============================================================================
|
|
2537
|
+
// BUNDLE GROUPS (structural "pick N items" on a product)
|
|
2538
|
+
// ============================================================================
|
|
2539
|
+
async getBundleGroups(siteName, productId, cachePolicy) {
|
|
2540
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2541
|
+
siteName,
|
|
2542
|
+
`/products/${productId}/bundle-groups`,
|
|
2543
|
+
{ includeSitesSegment: false }
|
|
2544
|
+
);
|
|
2545
|
+
const path = this.buildPath(endpoint);
|
|
2546
|
+
return this.fetchWithCache(
|
|
2547
|
+
endpoint,
|
|
2548
|
+
void 0,
|
|
2549
|
+
this.buildBundleTags(siteName, [`bundles:product:${productId}`]),
|
|
2550
|
+
cachePolicy,
|
|
2551
|
+
() => this.http.get(path)
|
|
2552
|
+
);
|
|
2553
|
+
}
|
|
2554
|
+
async createBundleGroup(siteName, productId, data) {
|
|
2555
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2556
|
+
siteName,
|
|
2557
|
+
`/products/${productId}/bundle-groups`,
|
|
2558
|
+
{ includeSitesSegment: false }
|
|
2559
|
+
);
|
|
2560
|
+
return this.create(endpoint, data);
|
|
2561
|
+
}
|
|
2562
|
+
async updateBundleGroup(siteName, productId, bundleGroupId, data) {
|
|
2563
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2564
|
+
siteName,
|
|
2565
|
+
`/products/${productId}/bundle-groups/${bundleGroupId}`,
|
|
2566
|
+
{ includeSitesSegment: false }
|
|
2567
|
+
);
|
|
2568
|
+
return this.patch(endpoint, data);
|
|
2569
|
+
}
|
|
2570
|
+
async deleteBundleGroup(siteName, productId, bundleGroupId) {
|
|
2571
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2572
|
+
siteName,
|
|
2573
|
+
`/products/${productId}/bundle-groups/${bundleGroupId}`,
|
|
2574
|
+
{ includeSitesSegment: false }
|
|
2575
|
+
);
|
|
2576
|
+
return this.delete(endpoint);
|
|
2577
|
+
}
|
|
2578
|
+
// ============================================================================
|
|
2579
|
+
// BUNDLE COLLECTIONS (time-bounded, site-scoped sets of products)
|
|
2580
|
+
// ============================================================================
|
|
2581
|
+
async getCollections(siteName, cachePolicy) {
|
|
2582
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2583
|
+
siteName,
|
|
2584
|
+
"/collections",
|
|
2585
|
+
{ includeSitesSegment: false }
|
|
2586
|
+
);
|
|
2587
|
+
const path = this.buildPath(endpoint);
|
|
2588
|
+
return this.fetchWithCache(
|
|
2589
|
+
endpoint,
|
|
2590
|
+
void 0,
|
|
2591
|
+
this.buildCollectionTags(siteName, ["collections:list"]),
|
|
2592
|
+
cachePolicy,
|
|
2593
|
+
() => this.http.get(path)
|
|
2594
|
+
);
|
|
2595
|
+
}
|
|
2596
|
+
async getCurrentCollection(siteName, cachePolicy) {
|
|
2597
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2598
|
+
siteName,
|
|
2599
|
+
"/collections/current",
|
|
2600
|
+
{ includeSitesSegment: false }
|
|
2601
|
+
);
|
|
2602
|
+
const path = this.buildPath(endpoint);
|
|
2603
|
+
return this.fetchWithCache(
|
|
2604
|
+
endpoint,
|
|
2605
|
+
void 0,
|
|
2606
|
+
this.buildCollectionTags(siteName, ["collections:current"]),
|
|
2607
|
+
cachePolicy,
|
|
2608
|
+
() => this.http.get(path)
|
|
2609
|
+
);
|
|
2610
|
+
}
|
|
2611
|
+
async getCollection(siteName, collectionId, cachePolicy) {
|
|
2612
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2613
|
+
siteName,
|
|
2614
|
+
`/collections/${collectionId}`,
|
|
2615
|
+
{ includeSitesSegment: false }
|
|
2616
|
+
);
|
|
2617
|
+
const path = this.buildPath(endpoint);
|
|
2618
|
+
return this.fetchWithCache(
|
|
2619
|
+
endpoint,
|
|
2620
|
+
void 0,
|
|
2621
|
+
this.buildCollectionTags(siteName, [`collections:id:${collectionId}`]),
|
|
2622
|
+
cachePolicy,
|
|
2623
|
+
() => this.http.get(path)
|
|
2624
|
+
);
|
|
2625
|
+
}
|
|
2626
|
+
async createCollection(siteName, data) {
|
|
2627
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2628
|
+
siteName,
|
|
2629
|
+
"/collections",
|
|
2630
|
+
{ includeSitesSegment: false }
|
|
2631
|
+
);
|
|
2632
|
+
return this.create(endpoint, data);
|
|
2633
|
+
}
|
|
2634
|
+
async updateCollection(siteName, collectionId, data) {
|
|
2635
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2636
|
+
siteName,
|
|
2637
|
+
`/collections/${collectionId}`,
|
|
2638
|
+
{ includeSitesSegment: false }
|
|
2639
|
+
);
|
|
2640
|
+
return this.patch(endpoint, data);
|
|
2641
|
+
}
|
|
2642
|
+
async deleteCollection(siteName, collectionId) {
|
|
2643
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2644
|
+
siteName,
|
|
2645
|
+
`/collections/${collectionId}`,
|
|
2646
|
+
{ includeSitesSegment: false }
|
|
2647
|
+
);
|
|
2648
|
+
return this.delete(endpoint);
|
|
2649
|
+
}
|
|
2650
|
+
// ============================================================================
|
|
2651
|
+
// COLLECTION ITEMS
|
|
2652
|
+
// ============================================================================
|
|
2653
|
+
async getCollectionItems(siteName, collectionId, cachePolicy) {
|
|
2654
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2655
|
+
siteName,
|
|
2656
|
+
`/collections/${collectionId}/items`,
|
|
2657
|
+
{ includeSitesSegment: false }
|
|
2658
|
+
);
|
|
2659
|
+
const path = this.buildPath(endpoint);
|
|
2660
|
+
return this.fetchWithCache(
|
|
2661
|
+
endpoint,
|
|
2662
|
+
void 0,
|
|
2663
|
+
this.buildCollectionTags(siteName, [`collections:items:${collectionId}`]),
|
|
2664
|
+
cachePolicy,
|
|
2665
|
+
() => this.http.get(path)
|
|
2666
|
+
);
|
|
2667
|
+
}
|
|
2668
|
+
async addCollectionItem(siteName, collectionId, data) {
|
|
2669
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2670
|
+
siteName,
|
|
2671
|
+
`/collections/${collectionId}/items`,
|
|
2672
|
+
{ includeSitesSegment: false }
|
|
2673
|
+
);
|
|
2674
|
+
return this.create(endpoint, data);
|
|
2675
|
+
}
|
|
2676
|
+
async removeCollectionItem(siteName, collectionId, itemId) {
|
|
2677
|
+
const endpoint = this.siteScopedEndpoint(
|
|
2678
|
+
siteName,
|
|
2679
|
+
`/collections/${collectionId}/items/${itemId}`,
|
|
2680
|
+
{ includeSitesSegment: false }
|
|
2681
|
+
);
|
|
2682
|
+
return this.delete(endpoint);
|
|
2683
|
+
}
|
|
2684
|
+
// ============================================================================
|
|
2685
|
+
// CACHE TAGS
|
|
2686
|
+
// ============================================================================
|
|
2687
|
+
buildBundleTags(siteName, extraTags = []) {
|
|
2688
|
+
const tags = /* @__PURE__ */ new Set(["bundles"]);
|
|
2689
|
+
if (siteName) {
|
|
2690
|
+
tags.add(`bundles:site:${siteName}`);
|
|
2691
|
+
}
|
|
2692
|
+
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
2693
|
+
return Array.from(tags.values());
|
|
2694
|
+
}
|
|
2695
|
+
buildCollectionTags(siteName, extraTags = []) {
|
|
2696
|
+
const tags = /* @__PURE__ */ new Set(["collections"]);
|
|
2697
|
+
if (siteName) {
|
|
2698
|
+
tags.add(`collections:site:${siteName}`);
|
|
2699
|
+
}
|
|
2700
|
+
extraTags.filter(Boolean).forEach((tag) => tags.add(tag));
|
|
2701
|
+
return Array.from(tags.values());
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
|
|
2463
2705
|
// src/perspect-api-client.ts
|
|
2464
2706
|
var PerspectApiClient = class {
|
|
2465
2707
|
http;
|
|
@@ -2477,6 +2719,7 @@ var PerspectApiClient = class {
|
|
|
2477
2719
|
contact;
|
|
2478
2720
|
newsletter;
|
|
2479
2721
|
siteUsers;
|
|
2722
|
+
bundles;
|
|
2480
2723
|
constructor(config) {
|
|
2481
2724
|
if (!config.baseUrl) {
|
|
2482
2725
|
throw new Error("baseUrl is required in PerspectApiConfig");
|
|
@@ -2495,6 +2738,7 @@ var PerspectApiClient = class {
|
|
|
2495
2738
|
this.contact = new ContactClient(this.http, this.cache);
|
|
2496
2739
|
this.newsletter = new NewsletterClient(this.http, this.cache);
|
|
2497
2740
|
this.siteUsers = new SiteUsersClient(this.http, this.cache);
|
|
2741
|
+
this.bundles = new BundlesClient(this.http, this.cache);
|
|
2498
2742
|
}
|
|
2499
2743
|
/**
|
|
2500
2744
|
* Update authentication token
|
|
@@ -3170,6 +3414,7 @@ export {
|
|
|
3170
3414
|
ApiKeysClient,
|
|
3171
3415
|
AuthClient,
|
|
3172
3416
|
BaseClient,
|
|
3417
|
+
BundlesClient,
|
|
3173
3418
|
CacheManager,
|
|
3174
3419
|
CategoriesClient,
|
|
3175
3420
|
CheckoutClient,
|