perspectapi-ts-sdk 4.1.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
@@ -2720,15 +2720,16 @@ var SiteUsersClient = class extends BaseClient {
2720
2720
  );
2721
2721
  }
2722
2722
  /**
2723
- * Cancel a subscription (marks for cancellation at period end)
2723
+ * Cancel a subscription.
2724
2724
  * @param siteName - The site name
2725
2725
  * @param id - Subscription ID
2726
2726
  * @param csrfToken - CSRF token (required)
2727
+ * @param options - Cancellation mode/details
2727
2728
  */
2728
- async cancelSubscription(siteName, id, csrfToken) {
2729
+ async cancelSubscription(siteName, id, csrfToken, options) {
2729
2730
  return this.create(
2730
2731
  this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(id)}/cancel`),
2731
- {},
2732
+ options ?? {},
2732
2733
  csrfToken
2733
2734
  );
2734
2735
  }
@@ -2958,11 +2959,12 @@ var SiteUsersClient = class extends BaseClient {
2958
2959
  * @param siteName - The site name
2959
2960
  * @param userId - User ID
2960
2961
  * @param subscriptionId - Subscription ID
2962
+ * @param options - Cancellation mode/details
2961
2963
  */
2962
- async cancelUserSubscription(siteName, userId, subscriptionId) {
2964
+ async cancelUserSubscription(siteName, userId, subscriptionId, options) {
2963
2965
  return this.create(
2964
2966
  this.siteUserEndpoint(siteName, `/users/${encodeURIComponent(userId)}/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`),
2965
- {}
2967
+ options ?? {}
2966
2968
  );
2967
2969
  }
2968
2970
  /**
@@ -3255,6 +3257,440 @@ function createPerspectApiClient(config) {
3255
3257
  }
3256
3258
  var perspect_api_client_default = PerspectApiClient;
3257
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
+
3258
3694
  // src/utils/image-transform.ts
3259
3695
  var DEFAULT_IMAGE_SIZES = {
3260
3696
  thumbnail: {
@@ -3879,6 +4315,8 @@ export {
3879
4315
  NoopCacheAdapter,
3880
4316
  OrganizationsClient,
3881
4317
  PerspectApiClient,
4318
+ PerspectApiV2Client,
4319
+ PerspectV2Error,
3882
4320
  ProductsClient,
3883
4321
  SiteUsersClient,
3884
4322
  SitesClient,
@@ -3887,6 +4325,7 @@ export {
3887
4325
  createApiError,
3888
4326
  createCheckoutSession,
3889
4327
  createPerspectApiClient,
4328
+ createPerspectApiV2Client,
3890
4329
  perspect_api_client_default as default,
3891
4330
  generateResponsiveImageHtml,
3892
4331
  generateResponsiveUrls,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perspectapi-ts-sdk",
3
- "version": "4.1.0",
3
+ "version": "5.0.0",
4
4
  "description": "TypeScript SDK for PerspectAPI - Cloudflare Workers compatible",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -18,6 +18,8 @@ import type {
18
18
  VerifyOtpResponse,
19
19
  UpdateSiteUserRequest,
20
20
  SetProfileValueRequest,
21
+ CancelSubscriptionRequest,
22
+ CancelSubscriptionResponse,
21
23
  ApiResponse,
22
24
  } from '../types';
23
25
 
@@ -276,19 +278,21 @@ export class SiteUsersClient extends BaseClient {
276
278
  }
277
279
 
278
280
  /**
279
- * Cancel a subscription (marks for cancellation at period end)
281
+ * Cancel a subscription.
280
282
  * @param siteName - The site name
281
283
  * @param id - Subscription ID
282
284
  * @param csrfToken - CSRF token (required)
285
+ * @param options - Cancellation mode/details
283
286
  */
284
287
  async cancelSubscription(
285
288
  siteName: string,
286
289
  id: string,
287
- csrfToken?: string
288
- ): Promise<ApiResponse<{ success: boolean; message: string }>> {
289
- return this.create<Record<string, never>, { success: boolean; message: string }>(
290
+ csrfToken?: string,
291
+ options?: CancelSubscriptionRequest
292
+ ): Promise<ApiResponse<CancelSubscriptionResponse>> {
293
+ return this.create<CancelSubscriptionRequest, CancelSubscriptionResponse>(
290
294
  this.siteUserEndpoint(siteName, `/users/me/subscriptions/${encodeURIComponent(id)}/cancel`),
291
- {},
295
+ options ?? {},
292
296
  csrfToken
293
297
  );
294
298
  }
@@ -596,15 +600,17 @@ export class SiteUsersClient extends BaseClient {
596
600
  * @param siteName - The site name
597
601
  * @param userId - User ID
598
602
  * @param subscriptionId - Subscription ID
603
+ * @param options - Cancellation mode/details
599
604
  */
600
605
  async cancelUserSubscription(
601
606
  siteName: string,
602
607
  userId: string,
603
- subscriptionId: string
604
- ): Promise<ApiResponse<{ success: boolean; message: string }>> {
605
- return this.create<Record<string, never>, { success: boolean; message: string }>(
608
+ subscriptionId: string,
609
+ options?: CancelSubscriptionRequest
610
+ ): Promise<ApiResponse<CancelSubscriptionResponse>> {
611
+ return this.create<CancelSubscriptionRequest, CancelSubscriptionResponse>(
606
612
  this.siteUserEndpoint(siteName, `/users/${encodeURIComponent(userId)}/subscriptions/${encodeURIComponent(subscriptionId)}/cancel`),
607
- {}
613
+ options ?? {}
608
614
  );
609
615
  }
610
616
 
package/src/index.ts CHANGED
@@ -3,10 +3,14 @@
3
3
  * Cloudflare Workers compatible SDK for PerspectAPI
4
4
  */
5
5
 
6
- // Main client
6
+ // Main client (v1)
7
7
  export { PerspectApiClient, createPerspectApiClient } from './perspect-api-client';
8
8
  export { default } from './perspect-api-client';
9
9
 
10
+ // v2 client
11
+ export { PerspectApiV2Client, createPerspectApiV2Client } from './v2';
12
+ export { PerspectV2Error } from './v2/client/base-v2-client';
13
+
10
14
  // Individual clients (for advanced usage)
11
15
  export { AuthClient } from './client/auth-client';
12
16
  export { ContentClient } from './client/content-client';
@@ -958,7 +958,7 @@ export interface SiteUserSubscription {
958
958
  provider_subscription_id?: string;
959
959
  plan_name?: string;
960
960
  plan_id?: string;
961
- status: 'active' | 'past_due' | 'canceled' | 'paused' | 'trialing' | 'expired';
961
+ status: 'active' | 'past_due' | 'canceled' | 'paused' | 'trialing' | 'expired' | 'incomplete';
962
962
  amount?: number;
963
963
  currency?: string;
964
964
  billing_interval?: string;
@@ -981,11 +981,34 @@ export interface SiteUserOrder {
981
981
  currency: string;
982
982
  status: string;
983
983
  payment_status?: string;
984
+ fulfillment_status?: string;
984
985
  line_items: any[];
985
986
  created_at: string;
986
987
  completed_at?: string;
987
988
  }
988
989
 
990
+ export type SubscriptionCancellationMode = 'immediate' | 'period_end' | 'scheduled';
991
+
992
+ export interface CancelSubscriptionRequest {
993
+ mode?: SubscriptionCancellationMode;
994
+ cancel_at?: string; // ISO timestamp
995
+ delay_days?: number;
996
+ delay_hours?: number;
997
+ delay_minutes?: number;
998
+ }
999
+
1000
+ export interface CancelSubscriptionResponse {
1001
+ success: boolean;
1002
+ message: string;
1003
+ cancellation?: {
1004
+ mode: SubscriptionCancellationMode;
1005
+ status: string;
1006
+ cancel_at_period_end: boolean;
1007
+ effective_at: string | null;
1008
+ scheduled_cancel_at: string | null;
1009
+ };
1010
+ }
1011
+
989
1012
  // Credits
990
1013
  export interface CreditTransaction {
991
1014
  id: number;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * v2 API Keys Client
3
+ */
4
+
5
+ import { BaseV2Client } from './base-v2-client';
6
+ import type { V2ApiKey, V2PaginationParams, V2List, V2Deleted } from '../types';
7
+
8
+ export class ApiKeysV2Client extends BaseV2Client {
9
+
10
+ async list(params?: V2PaginationParams): Promise<V2List<V2ApiKey>> {
11
+ return this.getList<V2ApiKey>('/api-keys', params);
12
+ }
13
+
14
+ async get(id: string): Promise<V2ApiKey> {
15
+ return this.getOne<V2ApiKey>(`/api-keys/${id}`);
16
+ }
17
+
18
+ async del(id: string): Promise<V2Deleted> {
19
+ return this.deleteOne(`/api-keys/${id}`);
20
+ }
21
+ }