perspectapi-ts-sdk 3.7.0 → 5.0.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.js CHANGED
@@ -33,9 +33,12 @@ __export(index_exports, {
33
33
  HttpClient: () => HttpClient,
34
34
  InMemoryCacheAdapter: () => InMemoryCacheAdapter,
35
35
  NewsletterClient: () => NewsletterClient,
36
+ NewsletterManagementClient: () => NewsletterManagementClient,
36
37
  NoopCacheAdapter: () => NoopCacheAdapter,
37
38
  OrganizationsClient: () => OrganizationsClient,
38
39
  PerspectApiClient: () => PerspectApiClient,
40
+ PerspectApiV2Client: () => PerspectApiV2Client,
41
+ PerspectV2Error: () => PerspectV2Error,
39
42
  ProductsClient: () => ProductsClient,
40
43
  SiteUsersClient: () => SiteUsersClient,
41
44
  SitesClient: () => SitesClient,
@@ -44,6 +47,7 @@ __export(index_exports, {
44
47
  createApiError: () => createApiError,
45
48
  createCheckoutSession: () => createCheckoutSession,
46
49
  createPerspectApiClient: () => createPerspectApiClient,
50
+ createPerspectApiV2Client: () => createPerspectApiV2Client,
47
51
  default: () => perspect_api_client_default,
48
52
  generateResponsiveImageHtml: () => generateResponsiveImageHtml,
49
53
  generateResponsiveUrls: () => generateResponsiveUrls,
@@ -2221,112 +2225,6 @@ var NewsletterClient = class extends BaseClient {
2221
2225
  { email }
2222
2226
  );
2223
2227
  }
2224
- // Admin methods (require authentication)
2225
- /**
2226
- * Get all newsletter subscriptions (admin only)
2227
- */
2228
- async getSubscriptions(siteName, params) {
2229
- return this.getPaginated(
2230
- this.newsletterEndpoint(siteName, "/newsletter/subscriptions"),
2231
- params
2232
- );
2233
- }
2234
- /**
2235
- * Get subscription by ID (admin only)
2236
- */
2237
- async getSubscriptionById(siteName, id) {
2238
- return this.getSingle(
2239
- this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`)
2240
- );
2241
- }
2242
- /**
2243
- * Update subscription status (admin only)
2244
- */
2245
- async updateSubscriptionStatus(siteName, id, status, notes) {
2246
- return this.patch(
2247
- this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`),
2248
- { status, notes }
2249
- );
2250
- }
2251
- /**
2252
- * Delete subscription (admin only)
2253
- */
2254
- async deleteSubscription(siteName, id) {
2255
- return this.delete(
2256
- this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`)
2257
- );
2258
- }
2259
- /**
2260
- * Bulk update subscriptions (admin only)
2261
- */
2262
- async bulkUpdateSubscriptions(siteName, data) {
2263
- return this.create(
2264
- this.newsletterEndpoint(siteName, "/newsletter/subscriptions/bulk-update"),
2265
- data
2266
- );
2267
- }
2268
- /**
2269
- * Create newsletter list (admin only)
2270
- */
2271
- async createList(siteName, data) {
2272
- return this.create(
2273
- this.newsletterEndpoint(siteName, "/newsletter/lists"),
2274
- data
2275
- );
2276
- }
2277
- /**
2278
- * Update newsletter list (admin only)
2279
- */
2280
- async updateList(siteName, listId, data) {
2281
- return this.update(
2282
- this.newsletterEndpoint(siteName, `/newsletter/lists/${encodeURIComponent(listId)}`),
2283
- data
2284
- );
2285
- }
2286
- /**
2287
- * Delete newsletter list (admin only)
2288
- */
2289
- async deleteList(siteName, listId) {
2290
- return this.delete(
2291
- this.newsletterEndpoint(siteName, `/newsletter/lists/${encodeURIComponent(listId)}`)
2292
- );
2293
- }
2294
- /**
2295
- * Get newsletter statistics (admin only)
2296
- */
2297
- async getStatistics(siteName, params) {
2298
- return this.http.get(
2299
- this.buildPath(this.newsletterEndpoint(siteName, "/newsletter/statistics")),
2300
- params
2301
- );
2302
- }
2303
- /**
2304
- * Export newsletter subscriptions (admin only)
2305
- */
2306
- async exportSubscriptions(siteName, params) {
2307
- return this.create(
2308
- this.newsletterEndpoint(siteName, "/newsletter/export"),
2309
- params || {}
2310
- );
2311
- }
2312
- /**
2313
- * Import newsletter subscriptions (admin only)
2314
- */
2315
- async importSubscriptions(siteName, data) {
2316
- return this.create(
2317
- this.newsletterEndpoint(siteName, "/newsletter/import"),
2318
- data
2319
- );
2320
- }
2321
- /**
2322
- * Send test newsletter (admin only)
2323
- */
2324
- async sendTestNewsletter(siteName, data) {
2325
- return this.create(
2326
- this.newsletterEndpoint(siteName, "/newsletter/test"),
2327
- data
2328
- );
2329
- }
2330
2228
  // ============================================
2331
2229
  // Tracking methods (for first-party tracking)
2332
2230
  // ============================================
@@ -2510,6 +2408,181 @@ var NewsletterClient = class extends BaseClient {
2510
2408
  }
2511
2409
  };
2512
2410
 
2411
+ // src/client/newsletter-management-client.ts
2412
+ var NewsletterManagementClient = class extends BaseClient {
2413
+ constructor(http, cache) {
2414
+ super(http, "/api/v1", cache);
2415
+ }
2416
+ managementEndpoint(siteName, endpoint) {
2417
+ return this.siteScopedEndpoint(
2418
+ siteName,
2419
+ `/newsletter/management${endpoint}`,
2420
+ { includeSitesSegment: false }
2421
+ );
2422
+ }
2423
+ async listSubscriptions(siteName, params) {
2424
+ return this.http.get(
2425
+ this.buildPath(this.managementEndpoint(siteName, "/subscriptions")),
2426
+ params
2427
+ );
2428
+ }
2429
+ async getSubscriptionById(siteName, subscriptionId) {
2430
+ return this.getSingle(
2431
+ this.managementEndpoint(
2432
+ siteName,
2433
+ `/subscriptions/${encodeURIComponent(subscriptionId)}`
2434
+ )
2435
+ );
2436
+ }
2437
+ async getSubscriptionByEmail(siteName, email) {
2438
+ return this.http.get(
2439
+ this.buildPath(this.managementEndpoint(siteName, "/subscriptions/by-email")),
2440
+ { email }
2441
+ );
2442
+ }
2443
+ async syncSubscription(siteName, data) {
2444
+ return this.create(this.managementEndpoint(siteName, "/subscriptions/sync"), data);
2445
+ }
2446
+ async updateSubscription(siteName, subscriptionId, data) {
2447
+ return this.patch(
2448
+ this.managementEndpoint(
2449
+ siteName,
2450
+ `/subscriptions/${encodeURIComponent(subscriptionId)}`
2451
+ ),
2452
+ data
2453
+ );
2454
+ }
2455
+ async deleteSubscription(siteName, subscriptionId) {
2456
+ return this.delete(
2457
+ this.managementEndpoint(
2458
+ siteName,
2459
+ `/subscriptions/${encodeURIComponent(subscriptionId)}`
2460
+ )
2461
+ );
2462
+ }
2463
+ async bulkUpdateSubscriptions(siteName, data) {
2464
+ return this.create(this.managementEndpoint(siteName, "/subscriptions/bulk"), data);
2465
+ }
2466
+ async updateSubscriptionListMembership(siteName, subscriptionId, data) {
2467
+ return this.create(
2468
+ this.managementEndpoint(
2469
+ siteName,
2470
+ `/subscriptions/${encodeURIComponent(subscriptionId)}/list-membership`
2471
+ ),
2472
+ data
2473
+ );
2474
+ }
2475
+ async importSubscriptions(siteName, data) {
2476
+ return this.create(
2477
+ this.managementEndpoint(siteName, "/subscriptions/import"),
2478
+ data
2479
+ );
2480
+ }
2481
+ async listLists(siteName, params) {
2482
+ return this.http.get(
2483
+ this.buildPath(this.managementEndpoint(siteName, "/lists")),
2484
+ params
2485
+ );
2486
+ }
2487
+ async getListById(siteName, listId) {
2488
+ return this.getSingle(
2489
+ this.managementEndpoint(siteName, `/lists/${encodeURIComponent(listId)}`)
2490
+ );
2491
+ }
2492
+ async createList(siteName, data) {
2493
+ return this.create(this.managementEndpoint(siteName, "/lists"), data);
2494
+ }
2495
+ async updateList(siteName, listId, data) {
2496
+ return this.update(
2497
+ this.managementEndpoint(siteName, `/lists/${encodeURIComponent(listId)}`),
2498
+ data
2499
+ );
2500
+ }
2501
+ async deleteList(siteName, listId) {
2502
+ return this.delete(
2503
+ this.managementEndpoint(siteName, `/lists/${encodeURIComponent(listId)}`)
2504
+ );
2505
+ }
2506
+ async listSeries(siteName, params) {
2507
+ return this.http.get(
2508
+ this.buildPath(this.managementEndpoint(siteName, "/series")),
2509
+ params
2510
+ );
2511
+ }
2512
+ async getSeriesById(siteName, seriesId) {
2513
+ return this.getSingle(
2514
+ this.managementEndpoint(siteName, `/series/${encodeURIComponent(seriesId)}`)
2515
+ );
2516
+ }
2517
+ async createSeries(siteName, data) {
2518
+ return this.create(this.managementEndpoint(siteName, "/series"), data);
2519
+ }
2520
+ async updateSeries(siteName, seriesId, data) {
2521
+ return this.update(
2522
+ this.managementEndpoint(siteName, `/series/${encodeURIComponent(seriesId)}`),
2523
+ data
2524
+ );
2525
+ }
2526
+ async deleteSeries(siteName, seriesId) {
2527
+ return this.delete(
2528
+ this.managementEndpoint(siteName, `/series/${encodeURIComponent(seriesId)}`)
2529
+ );
2530
+ }
2531
+ async listCampaigns(siteName, params) {
2532
+ return this.http.get(
2533
+ this.buildPath(this.managementEndpoint(siteName, "/campaigns")),
2534
+ params
2535
+ );
2536
+ }
2537
+ async getCampaignById(siteName, campaignId) {
2538
+ return this.getSingle(
2539
+ this.managementEndpoint(siteName, `/campaigns/${encodeURIComponent(campaignId)}`)
2540
+ );
2541
+ }
2542
+ async createCampaign(siteName, data) {
2543
+ return this.create(this.managementEndpoint(siteName, "/campaigns"), data);
2544
+ }
2545
+ async updateCampaign(siteName, campaignId, data) {
2546
+ return this.update(
2547
+ this.managementEndpoint(siteName, `/campaigns/${encodeURIComponent(campaignId)}`),
2548
+ data
2549
+ );
2550
+ }
2551
+ async deleteCampaign(siteName, campaignId) {
2552
+ return this.delete(
2553
+ this.managementEndpoint(siteName, `/campaigns/${encodeURIComponent(campaignId)}`)
2554
+ );
2555
+ }
2556
+ async sendCampaignTest(siteName, campaignId, data) {
2557
+ return this.create(
2558
+ this.managementEndpoint(
2559
+ siteName,
2560
+ `/campaigns/${encodeURIComponent(campaignId)}/test-send`
2561
+ ),
2562
+ data
2563
+ );
2564
+ }
2565
+ async getStats(siteName, params) {
2566
+ return this.http.get(
2567
+ this.buildPath(this.managementEndpoint(siteName, "/stats")),
2568
+ params
2569
+ );
2570
+ }
2571
+ async createExport(siteName, data) {
2572
+ return this.create(
2573
+ this.managementEndpoint(siteName, "/exports"),
2574
+ data
2575
+ );
2576
+ }
2577
+ async downloadExport(siteName, exportId) {
2578
+ return this.http.get(
2579
+ this.buildPath(
2580
+ this.managementEndpoint(siteName, `/exports/${encodeURIComponent(exportId)}/download`)
2581
+ )
2582
+ );
2583
+ }
2584
+ };
2585
+
2513
2586
  // src/client/site-users-client.ts
2514
2587
  var SiteUsersClient = class extends BaseClient {
2515
2588
  constructor(http, cache) {
@@ -2714,15 +2787,16 @@ var SiteUsersClient = class extends BaseClient {
2714
2787
  );
2715
2788
  }
2716
2789
  /**
2717
- * Cancel a subscription (marks for cancellation at period end)
2790
+ * Cancel a subscription.
2718
2791
  * @param siteName - The site name
2719
2792
  * @param id - Subscription ID
2720
2793
  * @param csrfToken - CSRF token (required)
2794
+ * @param options - Cancellation mode/details
2721
2795
  */
2722
- async cancelSubscription(siteName, id, csrfToken) {
2796
+ async cancelSubscription(siteName, id, csrfToken, options) {
2723
2797
  return this.create(
2724
2798
  this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(id)}/cancel`),
2725
- {},
2799
+ options ?? {},
2726
2800
  csrfToken
2727
2801
  );
2728
2802
  }
@@ -2952,11 +3026,12 @@ var SiteUsersClient = class extends BaseClient {
2952
3026
  * @param siteName - The site name
2953
3027
  * @param userId - User ID
2954
3028
  * @param subscriptionId - Subscription ID
3029
+ * @param options - Cancellation mode/details
2955
3030
  */
2956
- async cancelUserSubscription(siteName, userId, subscriptionId) {
3031
+ async cancelUserSubscription(siteName, userId, subscriptionId, options) {
2957
3032
  return this.create(
2958
3033
  this.siteUserEndpoint(siteName, `/users/${encodeURIComponent(userId)}/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`),
2959
- {}
3034
+ options ?? {}
2960
3035
  );
2961
3036
  }
2962
3037
  /**
@@ -3161,6 +3236,7 @@ var PerspectApiClient = class {
3161
3236
  checkout;
3162
3237
  contact;
3163
3238
  newsletter;
3239
+ newsletterManagement;
3164
3240
  siteUsers;
3165
3241
  bundles;
3166
3242
  constructor(config) {
@@ -3180,6 +3256,7 @@ var PerspectApiClient = class {
3180
3256
  this.checkout = new CheckoutClient(this.http, this.cache);
3181
3257
  this.contact = new ContactClient(this.http, this.cache);
3182
3258
  this.newsletter = new NewsletterClient(this.http, this.cache);
3259
+ this.newsletterManagement = new NewsletterManagementClient(this.http, this.cache);
3183
3260
  this.siteUsers = new SiteUsersClient(this.http, this.cache);
3184
3261
  this.bundles = new BundlesClient(this.http, this.cache);
3185
3262
  }
@@ -3247,6 +3324,440 @@ function createPerspectApiClient(config) {
3247
3324
  }
3248
3325
  var perspect_api_client_default = PerspectApiClient;
3249
3326
 
3327
+ // src/v2/client/base-v2-client.ts
3328
+ var PerspectV2Error = class extends Error {
3329
+ type;
3330
+ code;
3331
+ param;
3332
+ status;
3333
+ constructor(error, status) {
3334
+ super(error.message);
3335
+ this.name = "PerspectV2Error";
3336
+ this.type = error.type;
3337
+ this.code = error.code;
3338
+ this.param = error.param;
3339
+ this.status = status;
3340
+ }
3341
+ };
3342
+ var BaseV2Client = class {
3343
+ http;
3344
+ basePath;
3345
+ constructor(http, basePath) {
3346
+ this.http = http;
3347
+ this.basePath = basePath;
3348
+ }
3349
+ buildPath(endpoint) {
3350
+ const clean = endpoint.replace(/^\//, "");
3351
+ return clean ? `${this.basePath}/${clean}` : this.basePath;
3352
+ }
3353
+ sitePath(siteName, resource, suffix = "") {
3354
+ const encoded = encodeURIComponent(siteName.trim());
3355
+ const cleanSuffix = suffix.replace(/^\//, "");
3356
+ const end = cleanSuffix ? `/${cleanSuffix}` : "";
3357
+ return `/sites/${encoded}/${resource}${end}`;
3358
+ }
3359
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3360
+ toParams(params) {
3361
+ if (!params) return void 0;
3362
+ const out = {};
3363
+ for (const [k, v] of Object.entries(params)) {
3364
+ if (v !== void 0 && v !== null) out[k] = String(v);
3365
+ }
3366
+ return Object.keys(out).length > 0 ? out : void 0;
3367
+ }
3368
+ /** GET a single resource. */
3369
+ async getOne(path, params) {
3370
+ const response = await this.http.get(path, this.toParams(params));
3371
+ if (!response.success) {
3372
+ throw this.toError(response);
3373
+ }
3374
+ return response.data;
3375
+ }
3376
+ /** GET a list of resources with cursor pagination. */
3377
+ async getList(path, params) {
3378
+ const response = await this.http.get(path, this.toParams(params));
3379
+ if (!response.success) {
3380
+ throw this.toError(response);
3381
+ }
3382
+ return response.data;
3383
+ }
3384
+ /** POST to create a resource. */
3385
+ async post(path, body) {
3386
+ const response = await this.http.post(path, body);
3387
+ if (!response.success) {
3388
+ throw this.toError(response);
3389
+ }
3390
+ return response.data;
3391
+ }
3392
+ /** PATCH to update a resource. */
3393
+ async patchOne(path, body) {
3394
+ const response = await this.http.patch(path, body);
3395
+ if (!response.success) {
3396
+ throw this.toError(response);
3397
+ }
3398
+ return response.data;
3399
+ }
3400
+ /** DELETE a resource. */
3401
+ async deleteOne(path) {
3402
+ const response = await this.http.delete(path);
3403
+ if (!response.success) {
3404
+ throw this.toError(response);
3405
+ }
3406
+ return response.data;
3407
+ }
3408
+ /**
3409
+ * Auto-paginating async generator.
3410
+ * Yields every item across all pages.
3411
+ *
3412
+ * Usage:
3413
+ * for await (const item of client.listAutoPaginate(path, params)) { ... }
3414
+ */
3415
+ async *listAutoPaginate(path, params) {
3416
+ let startingAfter;
3417
+ let hasMore = true;
3418
+ while (hasMore) {
3419
+ const queryParams = { ...params };
3420
+ if (startingAfter) queryParams.starting_after = startingAfter;
3421
+ const page = await this.getList(path, queryParams);
3422
+ for (const item of page.data) {
3423
+ yield item;
3424
+ }
3425
+ hasMore = page.has_more;
3426
+ if (page.data.length > 0) {
3427
+ startingAfter = page.data[page.data.length - 1].id;
3428
+ } else {
3429
+ hasMore = false;
3430
+ }
3431
+ }
3432
+ }
3433
+ toError(response) {
3434
+ const data = response.data;
3435
+ const errorObj = data?.error ?? response.error;
3436
+ if (errorObj && typeof errorObj === "object" && "type" in errorObj) {
3437
+ return new PerspectV2Error(errorObj, 400);
3438
+ }
3439
+ return new PerspectV2Error(
3440
+ { type: "api_error", code: "unknown", message: response.message ?? "Unknown error" },
3441
+ 500
3442
+ );
3443
+ }
3444
+ };
3445
+
3446
+ // src/v2/client/content-client.ts
3447
+ var ContentV2Client = class extends BaseV2Client {
3448
+ async list(siteName, params) {
3449
+ return this.getList(this.sitePath(siteName, "content"), params);
3450
+ }
3451
+ async *listAutoPaginated(siteName, params) {
3452
+ yield* this.listAutoPaginate(this.sitePath(siteName, "content"), params);
3453
+ }
3454
+ async get(siteName, idOrSlug) {
3455
+ return this.getOne(this.sitePath(siteName, "content", idOrSlug));
3456
+ }
3457
+ async create(siteName, data) {
3458
+ return this.post(this.sitePath(siteName, "content"), data);
3459
+ }
3460
+ async update(siteName, id, data) {
3461
+ return this.patchOne(this.sitePath(siteName, "content", id), data);
3462
+ }
3463
+ async del(siteName, id) {
3464
+ return this.deleteOne(this.sitePath(siteName, "content", id));
3465
+ }
3466
+ async publish(siteName, id) {
3467
+ return this.post(this.sitePath(siteName, "content", `${id}/publish`));
3468
+ }
3469
+ async unpublish(siteName, id) {
3470
+ return this.post(this.sitePath(siteName, "content", `${id}/unpublish`));
3471
+ }
3472
+ };
3473
+
3474
+ // src/v2/client/products-client.ts
3475
+ var ProductsV2Client = class extends BaseV2Client {
3476
+ async list(siteName, params) {
3477
+ return this.getList(this.sitePath(siteName, "products"), params);
3478
+ }
3479
+ async *listAutoPaginated(siteName, params) {
3480
+ yield* this.listAutoPaginate(this.sitePath(siteName, "products"), params);
3481
+ }
3482
+ async get(siteName, idOrSlug) {
3483
+ return this.getOne(this.sitePath(siteName, "products", idOrSlug));
3484
+ }
3485
+ async create(siteName, data) {
3486
+ return this.post(this.sitePath(siteName, "products"), data);
3487
+ }
3488
+ async update(siteName, id, data) {
3489
+ return this.patchOne(this.sitePath(siteName, "products", id), data);
3490
+ }
3491
+ async del(siteName, id) {
3492
+ return this.deleteOne(this.sitePath(siteName, "products", id));
3493
+ }
3494
+ };
3495
+
3496
+ // src/v2/client/categories-client.ts
3497
+ var CategoriesV2Client = class extends BaseV2Client {
3498
+ async list(siteName, params) {
3499
+ return this.getList(this.sitePath(siteName, "categories"), params);
3500
+ }
3501
+ async get(siteName, id) {
3502
+ return this.getOne(this.sitePath(siteName, "categories", id));
3503
+ }
3504
+ async create(siteName, data) {
3505
+ return this.post(this.sitePath(siteName, "categories"), data);
3506
+ }
3507
+ async update(siteName, id, data) {
3508
+ return this.patchOne(this.sitePath(siteName, "categories", id), data);
3509
+ }
3510
+ async del(siteName, id) {
3511
+ return this.deleteOne(this.sitePath(siteName, "categories", id));
3512
+ }
3513
+ };
3514
+
3515
+ // src/v2/client/collections-client.ts
3516
+ var CollectionsV2Client = class extends BaseV2Client {
3517
+ async list(siteName, params) {
3518
+ return this.getList(this.sitePath(siteName, "collections"), params);
3519
+ }
3520
+ async getCurrent(siteName) {
3521
+ const result = await this.getOne(
3522
+ this.sitePath(siteName, "collections", "current")
3523
+ );
3524
+ return result ?? null;
3525
+ }
3526
+ async get(siteName, id) {
3527
+ return this.getOne(this.sitePath(siteName, "collections", id));
3528
+ }
3529
+ async create(siteName, data) {
3530
+ return this.post(this.sitePath(siteName, "collections"), data);
3531
+ }
3532
+ async update(siteName, id, data) {
3533
+ return this.patchOne(this.sitePath(siteName, "collections", id), data);
3534
+ }
3535
+ async del(siteName, id) {
3536
+ return this.deleteOne(this.sitePath(siteName, "collections", id));
3537
+ }
3538
+ // --- Items ---
3539
+ async listItems(siteName, collectionId) {
3540
+ return this.getList(
3541
+ this.sitePath(siteName, "collections", `${collectionId}/items`)
3542
+ );
3543
+ }
3544
+ async addItem(siteName, collectionId, data) {
3545
+ return this.post(
3546
+ this.sitePath(siteName, "collections", `${collectionId}/items`),
3547
+ data
3548
+ );
3549
+ }
3550
+ async removeItem(siteName, collectionId, itemId) {
3551
+ return this.deleteOne(
3552
+ this.sitePath(siteName, "collections", `${collectionId}/items/${itemId}`)
3553
+ );
3554
+ }
3555
+ };
3556
+
3557
+ // src/v2/client/orders-client.ts
3558
+ var OrdersV2Client = class extends BaseV2Client {
3559
+ async list(siteName, params) {
3560
+ return this.getList(this.sitePath(siteName, "orders"), params);
3561
+ }
3562
+ async *listAutoPaginated(siteName, params) {
3563
+ yield* this.listAutoPaginate(this.sitePath(siteName, "orders"), params);
3564
+ }
3565
+ async get(siteName, id) {
3566
+ return this.getOne(this.sitePath(siteName, "orders", id));
3567
+ }
3568
+ };
3569
+
3570
+ // src/v2/client/site-users-client.ts
3571
+ var SiteUsersV2Client = class extends BaseV2Client {
3572
+ // --- OTP Auth ---
3573
+ async requestOtp(siteName, data) {
3574
+ return this.post(this.sitePath(siteName, "users", "request-otp"), data);
3575
+ }
3576
+ async verifyOtp(siteName, data) {
3577
+ return this.post(this.sitePath(siteName, "users", "verify-otp"), data);
3578
+ }
3579
+ // --- Admin ---
3580
+ async list(siteName, params) {
3581
+ return this.getList(this.sitePath(siteName, "users"), params);
3582
+ }
3583
+ async *listAutoPaginated(siteName, params) {
3584
+ yield* this.listAutoPaginate(this.sitePath(siteName, "users"), params);
3585
+ }
3586
+ async get(siteName, id) {
3587
+ return this.getOne(this.sitePath(siteName, "users", id));
3588
+ }
3589
+ async update(siteName, id, data) {
3590
+ return this.patchOne(this.sitePath(siteName, "users", id), data);
3591
+ }
3592
+ };
3593
+
3594
+ // src/v2/client/newsletter-client.ts
3595
+ var NewsletterV2Client = class extends BaseV2Client {
3596
+ // --- Subscribe / Unsubscribe ---
3597
+ async subscribe(siteName, data) {
3598
+ return this.post(
3599
+ this.sitePath(siteName, "newsletter", "subscribe"),
3600
+ data
3601
+ );
3602
+ }
3603
+ async confirm(siteName, token) {
3604
+ return this.getOne(
3605
+ this.sitePath(siteName, "newsletter", `confirm/${token}`)
3606
+ );
3607
+ }
3608
+ async unsubscribe(siteName, data) {
3609
+ return this.post(
3610
+ this.sitePath(siteName, "newsletter", "unsubscribe"),
3611
+ data
3612
+ );
3613
+ }
3614
+ // --- Subscriptions (admin) ---
3615
+ async listSubscriptions(siteName, params) {
3616
+ return this.getList(
3617
+ this.sitePath(siteName, "newsletter", "subscriptions"),
3618
+ params
3619
+ );
3620
+ }
3621
+ async getSubscription(siteName, id) {
3622
+ return this.getOne(
3623
+ this.sitePath(siteName, "newsletter", `subscriptions/${id}`)
3624
+ );
3625
+ }
3626
+ // --- Lists ---
3627
+ async listLists(siteName) {
3628
+ return this.getList(
3629
+ this.sitePath(siteName, "newsletter", "lists")
3630
+ );
3631
+ }
3632
+ // --- Campaigns ---
3633
+ async listCampaigns(siteName, params) {
3634
+ return this.getList(
3635
+ this.sitePath(siteName, "newsletter", "campaigns"),
3636
+ params
3637
+ );
3638
+ }
3639
+ async getCampaign(siteName, idOrSlug) {
3640
+ return this.getOne(
3641
+ this.sitePath(siteName, "newsletter", `campaigns/${idOrSlug}`)
3642
+ );
3643
+ }
3644
+ };
3645
+
3646
+ // src/v2/client/contacts-client.ts
3647
+ var ContactsV2Client = class extends BaseV2Client {
3648
+ async submit(siteName, data) {
3649
+ return this.post(this.sitePath(siteName, "contacts"), data);
3650
+ }
3651
+ async list(siteName, params) {
3652
+ return this.getList(this.sitePath(siteName, "contacts"), params);
3653
+ }
3654
+ async get(siteName, id) {
3655
+ return this.getOne(this.sitePath(siteName, "contacts", id));
3656
+ }
3657
+ };
3658
+
3659
+ // src/v2/client/organizations-client.ts
3660
+ var OrganizationsV2Client = class extends BaseV2Client {
3661
+ async list() {
3662
+ return this.getList("/organizations");
3663
+ }
3664
+ async get(id) {
3665
+ return this.getOne(`/organizations/${id}`);
3666
+ }
3667
+ };
3668
+
3669
+ // src/v2/client/sites-client.ts
3670
+ var SitesV2Client = class extends BaseV2Client {
3671
+ async list(params) {
3672
+ return this.getList("/sites", params);
3673
+ }
3674
+ async get(name) {
3675
+ return this.getOne(`/sites/${encodeURIComponent(name)}`);
3676
+ }
3677
+ };
3678
+
3679
+ // src/v2/client/api-keys-client.ts
3680
+ var ApiKeysV2Client = class extends BaseV2Client {
3681
+ async list(params) {
3682
+ return this.getList("/api-keys", params);
3683
+ }
3684
+ async get(id) {
3685
+ return this.getOne(`/api-keys/${id}`);
3686
+ }
3687
+ async del(id) {
3688
+ return this.deleteOne(`/api-keys/${id}`);
3689
+ }
3690
+ };
3691
+
3692
+ // src/v2/client/webhooks-client.ts
3693
+ var WebhooksV2Client = class extends BaseV2Client {
3694
+ async list(siteName, params) {
3695
+ return this.getList(this.sitePath(siteName, "webhooks"), params);
3696
+ }
3697
+ async get(siteName, id) {
3698
+ return this.getOne(this.sitePath(siteName, "webhooks", id));
3699
+ }
3700
+ async create(siteName, data) {
3701
+ return this.post(this.sitePath(siteName, "webhooks"), data);
3702
+ }
3703
+ async update(siteName, id, data) {
3704
+ return this.patchOne(this.sitePath(siteName, "webhooks", id), data);
3705
+ }
3706
+ async del(siteName, id) {
3707
+ return this.deleteOne(this.sitePath(siteName, "webhooks", id));
3708
+ }
3709
+ };
3710
+
3711
+ // src/v2/index.ts
3712
+ var PerspectApiV2Client = class {
3713
+ http;
3714
+ content;
3715
+ products;
3716
+ categories;
3717
+ collections;
3718
+ orders;
3719
+ siteUsers;
3720
+ newsletter;
3721
+ contacts;
3722
+ organizations;
3723
+ sites;
3724
+ apiKeys;
3725
+ webhooks;
3726
+ constructor(config) {
3727
+ const baseUrl = config.baseUrl.replace(/\/+$/, "");
3728
+ const v2BaseUrl = baseUrl.endsWith("/api/v2") ? baseUrl : `${baseUrl}/api/v2`;
3729
+ this.http = new HttpClient({ ...config, baseUrl: v2BaseUrl });
3730
+ const basePath = "";
3731
+ this.content = new ContentV2Client(this.http, basePath);
3732
+ this.products = new ProductsV2Client(this.http, basePath);
3733
+ this.categories = new CategoriesV2Client(this.http, basePath);
3734
+ this.collections = new CollectionsV2Client(this.http, basePath);
3735
+ this.orders = new OrdersV2Client(this.http, basePath);
3736
+ this.siteUsers = new SiteUsersV2Client(this.http, basePath);
3737
+ this.newsletter = new NewsletterV2Client(this.http, basePath);
3738
+ this.contacts = new ContactsV2Client(this.http, basePath);
3739
+ this.organizations = new OrganizationsV2Client(this.http, basePath);
3740
+ this.sites = new SitesV2Client(this.http, basePath);
3741
+ this.apiKeys = new ApiKeysV2Client(this.http, basePath);
3742
+ this.webhooks = new WebhooksV2Client(this.http, basePath);
3743
+ }
3744
+ /** Update the JWT token for authenticated requests. */
3745
+ setAuth(jwt) {
3746
+ this.http.setAuth(jwt);
3747
+ }
3748
+ /** Update the API key. */
3749
+ setApiKey(apiKey) {
3750
+ this.http.setApiKey(apiKey);
3751
+ }
3752
+ /** Clear authentication. */
3753
+ clearAuth() {
3754
+ this.http.clearAuth();
3755
+ }
3756
+ };
3757
+ function createPerspectApiV2Client(config) {
3758
+ return new PerspectApiV2Client(config);
3759
+ }
3760
+
3250
3761
  // src/utils/image-transform.ts
3251
3762
  var DEFAULT_IMAGE_SIZES = {
3252
3763
  thumbnail: {
@@ -3868,9 +4379,12 @@ async function createCheckoutSession(options) {
3868
4379
  HttpClient,
3869
4380
  InMemoryCacheAdapter,
3870
4381
  NewsletterClient,
4382
+ NewsletterManagementClient,
3871
4383
  NoopCacheAdapter,
3872
4384
  OrganizationsClient,
3873
4385
  PerspectApiClient,
4386
+ PerspectApiV2Client,
4387
+ PerspectV2Error,
3874
4388
  ProductsClient,
3875
4389
  SiteUsersClient,
3876
4390
  SitesClient,
@@ -3879,6 +4393,7 @@ async function createCheckoutSession(options) {
3879
4393
  createApiError,
3880
4394
  createCheckoutSession,
3881
4395
  createPerspectApiClient,
4396
+ createPerspectApiV2Client,
3882
4397
  generateResponsiveImageHtml,
3883
4398
  generateResponsiveUrls,
3884
4399
  generateSizesAttribute,