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.mjs CHANGED
@@ -2158,112 +2158,6 @@ var NewsletterClient = class extends BaseClient {
2158
2158
  { email }
2159
2159
  );
2160
2160
  }
2161
- // Admin methods (require authentication)
2162
- /**
2163
- * Get all newsletter subscriptions (admin only)
2164
- */
2165
- async getSubscriptions(siteName, params) {
2166
- return this.getPaginated(
2167
- this.newsletterEndpoint(siteName, "/newsletter/subscriptions"),
2168
- params
2169
- );
2170
- }
2171
- /**
2172
- * Get subscription by ID (admin only)
2173
- */
2174
- async getSubscriptionById(siteName, id) {
2175
- return this.getSingle(
2176
- this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`)
2177
- );
2178
- }
2179
- /**
2180
- * Update subscription status (admin only)
2181
- */
2182
- async updateSubscriptionStatus(siteName, id, status, notes) {
2183
- return this.patch(
2184
- this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`),
2185
- { status, notes }
2186
- );
2187
- }
2188
- /**
2189
- * Delete subscription (admin only)
2190
- */
2191
- async deleteSubscription(siteName, id) {
2192
- return this.delete(
2193
- this.newsletterEndpoint(siteName, `/newsletter/subscriptions/${encodeURIComponent(id)}`)
2194
- );
2195
- }
2196
- /**
2197
- * Bulk update subscriptions (admin only)
2198
- */
2199
- async bulkUpdateSubscriptions(siteName, data) {
2200
- return this.create(
2201
- this.newsletterEndpoint(siteName, "/newsletter/subscriptions/bulk-update"),
2202
- data
2203
- );
2204
- }
2205
- /**
2206
- * Create newsletter list (admin only)
2207
- */
2208
- async createList(siteName, data) {
2209
- return this.create(
2210
- this.newsletterEndpoint(siteName, "/newsletter/lists"),
2211
- data
2212
- );
2213
- }
2214
- /**
2215
- * Update newsletter list (admin only)
2216
- */
2217
- async updateList(siteName, listId, data) {
2218
- return this.update(
2219
- this.newsletterEndpoint(siteName, `/newsletter/lists/${encodeURIComponent(listId)}`),
2220
- data
2221
- );
2222
- }
2223
- /**
2224
- * Delete newsletter list (admin only)
2225
- */
2226
- async deleteList(siteName, listId) {
2227
- return this.delete(
2228
- this.newsletterEndpoint(siteName, `/newsletter/lists/${encodeURIComponent(listId)}`)
2229
- );
2230
- }
2231
- /**
2232
- * Get newsletter statistics (admin only)
2233
- */
2234
- async getStatistics(siteName, params) {
2235
- return this.http.get(
2236
- this.buildPath(this.newsletterEndpoint(siteName, "/newsletter/statistics")),
2237
- params
2238
- );
2239
- }
2240
- /**
2241
- * Export newsletter subscriptions (admin only)
2242
- */
2243
- async exportSubscriptions(siteName, params) {
2244
- return this.create(
2245
- this.newsletterEndpoint(siteName, "/newsletter/export"),
2246
- params || {}
2247
- );
2248
- }
2249
- /**
2250
- * Import newsletter subscriptions (admin only)
2251
- */
2252
- async importSubscriptions(siteName, data) {
2253
- return this.create(
2254
- this.newsletterEndpoint(siteName, "/newsletter/import"),
2255
- data
2256
- );
2257
- }
2258
- /**
2259
- * Send test newsletter (admin only)
2260
- */
2261
- async sendTestNewsletter(siteName, data) {
2262
- return this.create(
2263
- this.newsletterEndpoint(siteName, "/newsletter/test"),
2264
- data
2265
- );
2266
- }
2267
2161
  // ============================================
2268
2162
  // Tracking methods (for first-party tracking)
2269
2163
  // ============================================
@@ -2447,6 +2341,181 @@ var NewsletterClient = class extends BaseClient {
2447
2341
  }
2448
2342
  };
2449
2343
 
2344
+ // src/client/newsletter-management-client.ts
2345
+ var NewsletterManagementClient = class extends BaseClient {
2346
+ constructor(http, cache) {
2347
+ super(http, "/api/v1", cache);
2348
+ }
2349
+ managementEndpoint(siteName, endpoint) {
2350
+ return this.siteScopedEndpoint(
2351
+ siteName,
2352
+ `/newsletter/management${endpoint}`,
2353
+ { includeSitesSegment: false }
2354
+ );
2355
+ }
2356
+ async listSubscriptions(siteName, params) {
2357
+ return this.http.get(
2358
+ this.buildPath(this.managementEndpoint(siteName, "/subscriptions")),
2359
+ params
2360
+ );
2361
+ }
2362
+ async getSubscriptionById(siteName, subscriptionId) {
2363
+ return this.getSingle(
2364
+ this.managementEndpoint(
2365
+ siteName,
2366
+ `/subscriptions/${encodeURIComponent(subscriptionId)}`
2367
+ )
2368
+ );
2369
+ }
2370
+ async getSubscriptionByEmail(siteName, email) {
2371
+ return this.http.get(
2372
+ this.buildPath(this.managementEndpoint(siteName, "/subscriptions/by-email")),
2373
+ { email }
2374
+ );
2375
+ }
2376
+ async syncSubscription(siteName, data) {
2377
+ return this.create(this.managementEndpoint(siteName, "/subscriptions/sync"), data);
2378
+ }
2379
+ async updateSubscription(siteName, subscriptionId, data) {
2380
+ return this.patch(
2381
+ this.managementEndpoint(
2382
+ siteName,
2383
+ `/subscriptions/${encodeURIComponent(subscriptionId)}`
2384
+ ),
2385
+ data
2386
+ );
2387
+ }
2388
+ async deleteSubscription(siteName, subscriptionId) {
2389
+ return this.delete(
2390
+ this.managementEndpoint(
2391
+ siteName,
2392
+ `/subscriptions/${encodeURIComponent(subscriptionId)}`
2393
+ )
2394
+ );
2395
+ }
2396
+ async bulkUpdateSubscriptions(siteName, data) {
2397
+ return this.create(this.managementEndpoint(siteName, "/subscriptions/bulk"), data);
2398
+ }
2399
+ async updateSubscriptionListMembership(siteName, subscriptionId, data) {
2400
+ return this.create(
2401
+ this.managementEndpoint(
2402
+ siteName,
2403
+ `/subscriptions/${encodeURIComponent(subscriptionId)}/list-membership`
2404
+ ),
2405
+ data
2406
+ );
2407
+ }
2408
+ async importSubscriptions(siteName, data) {
2409
+ return this.create(
2410
+ this.managementEndpoint(siteName, "/subscriptions/import"),
2411
+ data
2412
+ );
2413
+ }
2414
+ async listLists(siteName, params) {
2415
+ return this.http.get(
2416
+ this.buildPath(this.managementEndpoint(siteName, "/lists")),
2417
+ params
2418
+ );
2419
+ }
2420
+ async getListById(siteName, listId) {
2421
+ return this.getSingle(
2422
+ this.managementEndpoint(siteName, `/lists/${encodeURIComponent(listId)}`)
2423
+ );
2424
+ }
2425
+ async createList(siteName, data) {
2426
+ return this.create(this.managementEndpoint(siteName, "/lists"), data);
2427
+ }
2428
+ async updateList(siteName, listId, data) {
2429
+ return this.update(
2430
+ this.managementEndpoint(siteName, `/lists/${encodeURIComponent(listId)}`),
2431
+ data
2432
+ );
2433
+ }
2434
+ async deleteList(siteName, listId) {
2435
+ return this.delete(
2436
+ this.managementEndpoint(siteName, `/lists/${encodeURIComponent(listId)}`)
2437
+ );
2438
+ }
2439
+ async listSeries(siteName, params) {
2440
+ return this.http.get(
2441
+ this.buildPath(this.managementEndpoint(siteName, "/series")),
2442
+ params
2443
+ );
2444
+ }
2445
+ async getSeriesById(siteName, seriesId) {
2446
+ return this.getSingle(
2447
+ this.managementEndpoint(siteName, `/series/${encodeURIComponent(seriesId)}`)
2448
+ );
2449
+ }
2450
+ async createSeries(siteName, data) {
2451
+ return this.create(this.managementEndpoint(siteName, "/series"), data);
2452
+ }
2453
+ async updateSeries(siteName, seriesId, data) {
2454
+ return this.update(
2455
+ this.managementEndpoint(siteName, `/series/${encodeURIComponent(seriesId)}`),
2456
+ data
2457
+ );
2458
+ }
2459
+ async deleteSeries(siteName, seriesId) {
2460
+ return this.delete(
2461
+ this.managementEndpoint(siteName, `/series/${encodeURIComponent(seriesId)}`)
2462
+ );
2463
+ }
2464
+ async listCampaigns(siteName, params) {
2465
+ return this.http.get(
2466
+ this.buildPath(this.managementEndpoint(siteName, "/campaigns")),
2467
+ params
2468
+ );
2469
+ }
2470
+ async getCampaignById(siteName, campaignId) {
2471
+ return this.getSingle(
2472
+ this.managementEndpoint(siteName, `/campaigns/${encodeURIComponent(campaignId)}`)
2473
+ );
2474
+ }
2475
+ async createCampaign(siteName, data) {
2476
+ return this.create(this.managementEndpoint(siteName, "/campaigns"), data);
2477
+ }
2478
+ async updateCampaign(siteName, campaignId, data) {
2479
+ return this.update(
2480
+ this.managementEndpoint(siteName, `/campaigns/${encodeURIComponent(campaignId)}`),
2481
+ data
2482
+ );
2483
+ }
2484
+ async deleteCampaign(siteName, campaignId) {
2485
+ return this.delete(
2486
+ this.managementEndpoint(siteName, `/campaigns/${encodeURIComponent(campaignId)}`)
2487
+ );
2488
+ }
2489
+ async sendCampaignTest(siteName, campaignId, data) {
2490
+ return this.create(
2491
+ this.managementEndpoint(
2492
+ siteName,
2493
+ `/campaigns/${encodeURIComponent(campaignId)}/test-send`
2494
+ ),
2495
+ data
2496
+ );
2497
+ }
2498
+ async getStats(siteName, params) {
2499
+ return this.http.get(
2500
+ this.buildPath(this.managementEndpoint(siteName, "/stats")),
2501
+ params
2502
+ );
2503
+ }
2504
+ async createExport(siteName, data) {
2505
+ return this.create(
2506
+ this.managementEndpoint(siteName, "/exports"),
2507
+ data
2508
+ );
2509
+ }
2510
+ async downloadExport(siteName, exportId) {
2511
+ return this.http.get(
2512
+ this.buildPath(
2513
+ this.managementEndpoint(siteName, `/exports/${encodeURIComponent(exportId)}/download`)
2514
+ )
2515
+ );
2516
+ }
2517
+ };
2518
+
2450
2519
  // src/client/site-users-client.ts
2451
2520
  var SiteUsersClient = class extends BaseClient {
2452
2521
  constructor(http, cache) {
@@ -2651,15 +2720,16 @@ var SiteUsersClient = class extends BaseClient {
2651
2720
  );
2652
2721
  }
2653
2722
  /**
2654
- * Cancel a subscription (marks for cancellation at period end)
2723
+ * Cancel a subscription.
2655
2724
  * @param siteName - The site name
2656
2725
  * @param id - Subscription ID
2657
2726
  * @param csrfToken - CSRF token (required)
2727
+ * @param options - Cancellation mode/details
2658
2728
  */
2659
- async cancelSubscription(siteName, id, csrfToken) {
2729
+ async cancelSubscription(siteName, id, csrfToken, options) {
2660
2730
  return this.create(
2661
2731
  this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(id)}/cancel`),
2662
- {},
2732
+ options ?? {},
2663
2733
  csrfToken
2664
2734
  );
2665
2735
  }
@@ -2889,11 +2959,12 @@ var SiteUsersClient = class extends BaseClient {
2889
2959
  * @param siteName - The site name
2890
2960
  * @param userId - User ID
2891
2961
  * @param subscriptionId - Subscription ID
2962
+ * @param options - Cancellation mode/details
2892
2963
  */
2893
- async cancelUserSubscription(siteName, userId, subscriptionId) {
2964
+ async cancelUserSubscription(siteName, userId, subscriptionId, options) {
2894
2965
  return this.create(
2895
2966
  this.siteUserEndpoint(siteName, `/users/${encodeURIComponent(userId)}/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`),
2896
- {}
2967
+ options ?? {}
2897
2968
  );
2898
2969
  }
2899
2970
  /**
@@ -3098,6 +3169,7 @@ var PerspectApiClient = class {
3098
3169
  checkout;
3099
3170
  contact;
3100
3171
  newsletter;
3172
+ newsletterManagement;
3101
3173
  siteUsers;
3102
3174
  bundles;
3103
3175
  constructor(config) {
@@ -3117,6 +3189,7 @@ var PerspectApiClient = class {
3117
3189
  this.checkout = new CheckoutClient(this.http, this.cache);
3118
3190
  this.contact = new ContactClient(this.http, this.cache);
3119
3191
  this.newsletter = new NewsletterClient(this.http, this.cache);
3192
+ this.newsletterManagement = new NewsletterManagementClient(this.http, this.cache);
3120
3193
  this.siteUsers = new SiteUsersClient(this.http, this.cache);
3121
3194
  this.bundles = new BundlesClient(this.http, this.cache);
3122
3195
  }
@@ -3184,6 +3257,440 @@ function createPerspectApiClient(config) {
3184
3257
  }
3185
3258
  var perspect_api_client_default = PerspectApiClient;
3186
3259
 
3260
+ // src/v2/client/base-v2-client.ts
3261
+ var PerspectV2Error = class extends Error {
3262
+ type;
3263
+ code;
3264
+ param;
3265
+ status;
3266
+ constructor(error, status) {
3267
+ super(error.message);
3268
+ this.name = "PerspectV2Error";
3269
+ this.type = error.type;
3270
+ this.code = error.code;
3271
+ this.param = error.param;
3272
+ this.status = status;
3273
+ }
3274
+ };
3275
+ var BaseV2Client = class {
3276
+ http;
3277
+ basePath;
3278
+ constructor(http, basePath) {
3279
+ this.http = http;
3280
+ this.basePath = basePath;
3281
+ }
3282
+ buildPath(endpoint) {
3283
+ const clean = endpoint.replace(/^\//, "");
3284
+ return clean ? `${this.basePath}/${clean}` : this.basePath;
3285
+ }
3286
+ sitePath(siteName, resource, suffix = "") {
3287
+ const encoded = encodeURIComponent(siteName.trim());
3288
+ const cleanSuffix = suffix.replace(/^\//, "");
3289
+ const end = cleanSuffix ? `/${cleanSuffix}` : "";
3290
+ return `/sites/${encoded}/${resource}${end}`;
3291
+ }
3292
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3293
+ toParams(params) {
3294
+ if (!params) return void 0;
3295
+ const out = {};
3296
+ for (const [k, v] of Object.entries(params)) {
3297
+ if (v !== void 0 && v !== null) out[k] = String(v);
3298
+ }
3299
+ return Object.keys(out).length > 0 ? out : void 0;
3300
+ }
3301
+ /** GET a single resource. */
3302
+ async getOne(path, params) {
3303
+ const response = await this.http.get(path, this.toParams(params));
3304
+ if (!response.success) {
3305
+ throw this.toError(response);
3306
+ }
3307
+ return response.data;
3308
+ }
3309
+ /** GET a list of resources with cursor pagination. */
3310
+ async getList(path, params) {
3311
+ const response = await this.http.get(path, this.toParams(params));
3312
+ if (!response.success) {
3313
+ throw this.toError(response);
3314
+ }
3315
+ return response.data;
3316
+ }
3317
+ /** POST to create a resource. */
3318
+ async post(path, body) {
3319
+ const response = await this.http.post(path, body);
3320
+ if (!response.success) {
3321
+ throw this.toError(response);
3322
+ }
3323
+ return response.data;
3324
+ }
3325
+ /** PATCH to update a resource. */
3326
+ async patchOne(path, body) {
3327
+ const response = await this.http.patch(path, body);
3328
+ if (!response.success) {
3329
+ throw this.toError(response);
3330
+ }
3331
+ return response.data;
3332
+ }
3333
+ /** DELETE a resource. */
3334
+ async deleteOne(path) {
3335
+ const response = await this.http.delete(path);
3336
+ if (!response.success) {
3337
+ throw this.toError(response);
3338
+ }
3339
+ return response.data;
3340
+ }
3341
+ /**
3342
+ * Auto-paginating async generator.
3343
+ * Yields every item across all pages.
3344
+ *
3345
+ * Usage:
3346
+ * for await (const item of client.listAutoPaginate(path, params)) { ... }
3347
+ */
3348
+ async *listAutoPaginate(path, params) {
3349
+ let startingAfter;
3350
+ let hasMore = true;
3351
+ while (hasMore) {
3352
+ const queryParams = { ...params };
3353
+ if (startingAfter) queryParams.starting_after = startingAfter;
3354
+ const page = await this.getList(path, queryParams);
3355
+ for (const item of page.data) {
3356
+ yield item;
3357
+ }
3358
+ hasMore = page.has_more;
3359
+ if (page.data.length > 0) {
3360
+ startingAfter = page.data[page.data.length - 1].id;
3361
+ } else {
3362
+ hasMore = false;
3363
+ }
3364
+ }
3365
+ }
3366
+ toError(response) {
3367
+ const data = response.data;
3368
+ const errorObj = data?.error ?? response.error;
3369
+ if (errorObj && typeof errorObj === "object" && "type" in errorObj) {
3370
+ return new PerspectV2Error(errorObj, 400);
3371
+ }
3372
+ return new PerspectV2Error(
3373
+ { type: "api_error", code: "unknown", message: response.message ?? "Unknown error" },
3374
+ 500
3375
+ );
3376
+ }
3377
+ };
3378
+
3379
+ // src/v2/client/content-client.ts
3380
+ var ContentV2Client = class extends BaseV2Client {
3381
+ async list(siteName, params) {
3382
+ return this.getList(this.sitePath(siteName, "content"), params);
3383
+ }
3384
+ async *listAutoPaginated(siteName, params) {
3385
+ yield* this.listAutoPaginate(this.sitePath(siteName, "content"), params);
3386
+ }
3387
+ async get(siteName, idOrSlug) {
3388
+ return this.getOne(this.sitePath(siteName, "content", idOrSlug));
3389
+ }
3390
+ async create(siteName, data) {
3391
+ return this.post(this.sitePath(siteName, "content"), data);
3392
+ }
3393
+ async update(siteName, id, data) {
3394
+ return this.patchOne(this.sitePath(siteName, "content", id), data);
3395
+ }
3396
+ async del(siteName, id) {
3397
+ return this.deleteOne(this.sitePath(siteName, "content", id));
3398
+ }
3399
+ async publish(siteName, id) {
3400
+ return this.post(this.sitePath(siteName, "content", `${id}/publish`));
3401
+ }
3402
+ async unpublish(siteName, id) {
3403
+ return this.post(this.sitePath(siteName, "content", `${id}/unpublish`));
3404
+ }
3405
+ };
3406
+
3407
+ // src/v2/client/products-client.ts
3408
+ var ProductsV2Client = class extends BaseV2Client {
3409
+ async list(siteName, params) {
3410
+ return this.getList(this.sitePath(siteName, "products"), params);
3411
+ }
3412
+ async *listAutoPaginated(siteName, params) {
3413
+ yield* this.listAutoPaginate(this.sitePath(siteName, "products"), params);
3414
+ }
3415
+ async get(siteName, idOrSlug) {
3416
+ return this.getOne(this.sitePath(siteName, "products", idOrSlug));
3417
+ }
3418
+ async create(siteName, data) {
3419
+ return this.post(this.sitePath(siteName, "products"), data);
3420
+ }
3421
+ async update(siteName, id, data) {
3422
+ return this.patchOne(this.sitePath(siteName, "products", id), data);
3423
+ }
3424
+ async del(siteName, id) {
3425
+ return this.deleteOne(this.sitePath(siteName, "products", id));
3426
+ }
3427
+ };
3428
+
3429
+ // src/v2/client/categories-client.ts
3430
+ var CategoriesV2Client = class extends BaseV2Client {
3431
+ async list(siteName, params) {
3432
+ return this.getList(this.sitePath(siteName, "categories"), params);
3433
+ }
3434
+ async get(siteName, id) {
3435
+ return this.getOne(this.sitePath(siteName, "categories", id));
3436
+ }
3437
+ async create(siteName, data) {
3438
+ return this.post(this.sitePath(siteName, "categories"), data);
3439
+ }
3440
+ async update(siteName, id, data) {
3441
+ return this.patchOne(this.sitePath(siteName, "categories", id), data);
3442
+ }
3443
+ async del(siteName, id) {
3444
+ return this.deleteOne(this.sitePath(siteName, "categories", id));
3445
+ }
3446
+ };
3447
+
3448
+ // src/v2/client/collections-client.ts
3449
+ var CollectionsV2Client = class extends BaseV2Client {
3450
+ async list(siteName, params) {
3451
+ return this.getList(this.sitePath(siteName, "collections"), params);
3452
+ }
3453
+ async getCurrent(siteName) {
3454
+ const result = await this.getOne(
3455
+ this.sitePath(siteName, "collections", "current")
3456
+ );
3457
+ return result ?? null;
3458
+ }
3459
+ async get(siteName, id) {
3460
+ return this.getOne(this.sitePath(siteName, "collections", id));
3461
+ }
3462
+ async create(siteName, data) {
3463
+ return this.post(this.sitePath(siteName, "collections"), data);
3464
+ }
3465
+ async update(siteName, id, data) {
3466
+ return this.patchOne(this.sitePath(siteName, "collections", id), data);
3467
+ }
3468
+ async del(siteName, id) {
3469
+ return this.deleteOne(this.sitePath(siteName, "collections", id));
3470
+ }
3471
+ // --- Items ---
3472
+ async listItems(siteName, collectionId) {
3473
+ return this.getList(
3474
+ this.sitePath(siteName, "collections", `${collectionId}/items`)
3475
+ );
3476
+ }
3477
+ async addItem(siteName, collectionId, data) {
3478
+ return this.post(
3479
+ this.sitePath(siteName, "collections", `${collectionId}/items`),
3480
+ data
3481
+ );
3482
+ }
3483
+ async removeItem(siteName, collectionId, itemId) {
3484
+ return this.deleteOne(
3485
+ this.sitePath(siteName, "collections", `${collectionId}/items/${itemId}`)
3486
+ );
3487
+ }
3488
+ };
3489
+
3490
+ // src/v2/client/orders-client.ts
3491
+ var OrdersV2Client = class extends BaseV2Client {
3492
+ async list(siteName, params) {
3493
+ return this.getList(this.sitePath(siteName, "orders"), params);
3494
+ }
3495
+ async *listAutoPaginated(siteName, params) {
3496
+ yield* this.listAutoPaginate(this.sitePath(siteName, "orders"), params);
3497
+ }
3498
+ async get(siteName, id) {
3499
+ return this.getOne(this.sitePath(siteName, "orders", id));
3500
+ }
3501
+ };
3502
+
3503
+ // src/v2/client/site-users-client.ts
3504
+ var SiteUsersV2Client = class extends BaseV2Client {
3505
+ // --- OTP Auth ---
3506
+ async requestOtp(siteName, data) {
3507
+ return this.post(this.sitePath(siteName, "users", "request-otp"), data);
3508
+ }
3509
+ async verifyOtp(siteName, data) {
3510
+ return this.post(this.sitePath(siteName, "users", "verify-otp"), data);
3511
+ }
3512
+ // --- Admin ---
3513
+ async list(siteName, params) {
3514
+ return this.getList(this.sitePath(siteName, "users"), params);
3515
+ }
3516
+ async *listAutoPaginated(siteName, params) {
3517
+ yield* this.listAutoPaginate(this.sitePath(siteName, "users"), params);
3518
+ }
3519
+ async get(siteName, id) {
3520
+ return this.getOne(this.sitePath(siteName, "users", id));
3521
+ }
3522
+ async update(siteName, id, data) {
3523
+ return this.patchOne(this.sitePath(siteName, "users", id), data);
3524
+ }
3525
+ };
3526
+
3527
+ // src/v2/client/newsletter-client.ts
3528
+ var NewsletterV2Client = class extends BaseV2Client {
3529
+ // --- Subscribe / Unsubscribe ---
3530
+ async subscribe(siteName, data) {
3531
+ return this.post(
3532
+ this.sitePath(siteName, "newsletter", "subscribe"),
3533
+ data
3534
+ );
3535
+ }
3536
+ async confirm(siteName, token) {
3537
+ return this.getOne(
3538
+ this.sitePath(siteName, "newsletter", `confirm/${token}`)
3539
+ );
3540
+ }
3541
+ async unsubscribe(siteName, data) {
3542
+ return this.post(
3543
+ this.sitePath(siteName, "newsletter", "unsubscribe"),
3544
+ data
3545
+ );
3546
+ }
3547
+ // --- Subscriptions (admin) ---
3548
+ async listSubscriptions(siteName, params) {
3549
+ return this.getList(
3550
+ this.sitePath(siteName, "newsletter", "subscriptions"),
3551
+ params
3552
+ );
3553
+ }
3554
+ async getSubscription(siteName, id) {
3555
+ return this.getOne(
3556
+ this.sitePath(siteName, "newsletter", `subscriptions/${id}`)
3557
+ );
3558
+ }
3559
+ // --- Lists ---
3560
+ async listLists(siteName) {
3561
+ return this.getList(
3562
+ this.sitePath(siteName, "newsletter", "lists")
3563
+ );
3564
+ }
3565
+ // --- Campaigns ---
3566
+ async listCampaigns(siteName, params) {
3567
+ return this.getList(
3568
+ this.sitePath(siteName, "newsletter", "campaigns"),
3569
+ params
3570
+ );
3571
+ }
3572
+ async getCampaign(siteName, idOrSlug) {
3573
+ return this.getOne(
3574
+ this.sitePath(siteName, "newsletter", `campaigns/${idOrSlug}`)
3575
+ );
3576
+ }
3577
+ };
3578
+
3579
+ // src/v2/client/contacts-client.ts
3580
+ var ContactsV2Client = class extends BaseV2Client {
3581
+ async submit(siteName, data) {
3582
+ return this.post(this.sitePath(siteName, "contacts"), data);
3583
+ }
3584
+ async list(siteName, params) {
3585
+ return this.getList(this.sitePath(siteName, "contacts"), params);
3586
+ }
3587
+ async get(siteName, id) {
3588
+ return this.getOne(this.sitePath(siteName, "contacts", id));
3589
+ }
3590
+ };
3591
+
3592
+ // src/v2/client/organizations-client.ts
3593
+ var OrganizationsV2Client = class extends BaseV2Client {
3594
+ async list() {
3595
+ return this.getList("/organizations");
3596
+ }
3597
+ async get(id) {
3598
+ return this.getOne(`/organizations/${id}`);
3599
+ }
3600
+ };
3601
+
3602
+ // src/v2/client/sites-client.ts
3603
+ var SitesV2Client = class extends BaseV2Client {
3604
+ async list(params) {
3605
+ return this.getList("/sites", params);
3606
+ }
3607
+ async get(name) {
3608
+ return this.getOne(`/sites/${encodeURIComponent(name)}`);
3609
+ }
3610
+ };
3611
+
3612
+ // src/v2/client/api-keys-client.ts
3613
+ var ApiKeysV2Client = class extends BaseV2Client {
3614
+ async list(params) {
3615
+ return this.getList("/api-keys", params);
3616
+ }
3617
+ async get(id) {
3618
+ return this.getOne(`/api-keys/${id}`);
3619
+ }
3620
+ async del(id) {
3621
+ return this.deleteOne(`/api-keys/${id}`);
3622
+ }
3623
+ };
3624
+
3625
+ // src/v2/client/webhooks-client.ts
3626
+ var WebhooksV2Client = class extends BaseV2Client {
3627
+ async list(siteName, params) {
3628
+ return this.getList(this.sitePath(siteName, "webhooks"), params);
3629
+ }
3630
+ async get(siteName, id) {
3631
+ return this.getOne(this.sitePath(siteName, "webhooks", id));
3632
+ }
3633
+ async create(siteName, data) {
3634
+ return this.post(this.sitePath(siteName, "webhooks"), data);
3635
+ }
3636
+ async update(siteName, id, data) {
3637
+ return this.patchOne(this.sitePath(siteName, "webhooks", id), data);
3638
+ }
3639
+ async del(siteName, id) {
3640
+ return this.deleteOne(this.sitePath(siteName, "webhooks", id));
3641
+ }
3642
+ };
3643
+
3644
+ // src/v2/index.ts
3645
+ var PerspectApiV2Client = class {
3646
+ http;
3647
+ content;
3648
+ products;
3649
+ categories;
3650
+ collections;
3651
+ orders;
3652
+ siteUsers;
3653
+ newsletter;
3654
+ contacts;
3655
+ organizations;
3656
+ sites;
3657
+ apiKeys;
3658
+ webhooks;
3659
+ constructor(config) {
3660
+ const baseUrl = config.baseUrl.replace(/\/+$/, "");
3661
+ const v2BaseUrl = baseUrl.endsWith("/api/v2") ? baseUrl : `${baseUrl}/api/v2`;
3662
+ this.http = new HttpClient({ ...config, baseUrl: v2BaseUrl });
3663
+ const basePath = "";
3664
+ this.content = new ContentV2Client(this.http, basePath);
3665
+ this.products = new ProductsV2Client(this.http, basePath);
3666
+ this.categories = new CategoriesV2Client(this.http, basePath);
3667
+ this.collections = new CollectionsV2Client(this.http, basePath);
3668
+ this.orders = new OrdersV2Client(this.http, basePath);
3669
+ this.siteUsers = new SiteUsersV2Client(this.http, basePath);
3670
+ this.newsletter = new NewsletterV2Client(this.http, basePath);
3671
+ this.contacts = new ContactsV2Client(this.http, basePath);
3672
+ this.organizations = new OrganizationsV2Client(this.http, basePath);
3673
+ this.sites = new SitesV2Client(this.http, basePath);
3674
+ this.apiKeys = new ApiKeysV2Client(this.http, basePath);
3675
+ this.webhooks = new WebhooksV2Client(this.http, basePath);
3676
+ }
3677
+ /** Update the JWT token for authenticated requests. */
3678
+ setAuth(jwt) {
3679
+ this.http.setAuth(jwt);
3680
+ }
3681
+ /** Update the API key. */
3682
+ setApiKey(apiKey) {
3683
+ this.http.setApiKey(apiKey);
3684
+ }
3685
+ /** Clear authentication. */
3686
+ clearAuth() {
3687
+ this.http.clearAuth();
3688
+ }
3689
+ };
3690
+ function createPerspectApiV2Client(config) {
3691
+ return new PerspectApiV2Client(config);
3692
+ }
3693
+
3187
3694
  // src/utils/image-transform.ts
3188
3695
  var DEFAULT_IMAGE_SIZES = {
3189
3696
  thumbnail: {
@@ -3804,9 +4311,12 @@ export {
3804
4311
  HttpClient,
3805
4312
  InMemoryCacheAdapter,
3806
4313
  NewsletterClient,
4314
+ NewsletterManagementClient,
3807
4315
  NoopCacheAdapter,
3808
4316
  OrganizationsClient,
3809
4317
  PerspectApiClient,
4318
+ PerspectApiV2Client,
4319
+ PerspectV2Error,
3810
4320
  ProductsClient,
3811
4321
  SiteUsersClient,
3812
4322
  SitesClient,
@@ -3815,6 +4325,7 @@ export {
3815
4325
  createApiError,
3816
4326
  createCheckoutSession,
3817
4327
  createPerspectApiClient,
4328
+ createPerspectApiV2Client,
3818
4329
  perspect_api_client_default as default,
3819
4330
  generateResponsiveImageHtml,
3820
4331
  generateResponsiveUrls,