perspectapi-ts-sdk 7.2.8 → 7.4.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/src/v2/index.ts CHANGED
@@ -30,6 +30,7 @@ import { WebhooksV2Client } from './client/webhooks-client';
30
30
  import { SubscriptionsV2Client } from './client/subscriptions-client';
31
31
  import { CreditsV2Client } from './client/credits-client';
32
32
  import { EmailV2Client } from './client/email-client';
33
+ import { EmailTemplatesV2Client } from './client/email-templates-client';
33
34
 
34
35
  export interface PerspectApiV2Config extends PerspectApiConfig {
35
36
  cache?: CacheConfig;
@@ -54,6 +55,7 @@ export class PerspectApiV2Client {
54
55
  readonly subscriptions: SubscriptionsV2Client;
55
56
  readonly credits: CreditsV2Client;
56
57
  readonly email: EmailV2Client;
58
+ readonly emailTemplates: EmailTemplatesV2Client;
57
59
 
58
60
  constructor(config: PerspectApiV2Config) {
59
61
  // Ensure base URL points to /api/v2
@@ -82,6 +84,7 @@ export class PerspectApiV2Client {
82
84
  this.subscriptions = new SubscriptionsV2Client(this.http, basePath, cache);
83
85
  this.credits = new CreditsV2Client(this.http, basePath, cache);
84
86
  this.email = new EmailV2Client(this.http, basePath, cache);
87
+ this.emailTemplates = new EmailTemplatesV2Client(this.http, basePath, cache);
85
88
  }
86
89
 
87
90
  /** Update the JWT token for authenticated requests. */
@@ -124,3 +127,4 @@ export { WebhooksV2Client } from './client/webhooks-client';
124
127
  export { SubscriptionsV2Client } from './client/subscriptions-client';
125
128
  export { CreditsV2Client } from './client/credits-client';
126
129
  export { EmailV2Client } from './client/email-client';
130
+ export { EmailTemplatesV2Client } from './client/email-templates-client';
package/src/v2/types.ts CHANGED
@@ -507,23 +507,77 @@ export interface V2NewsletterList extends V2Object {
507
507
  updated_at: string | null;
508
508
  }
509
509
 
510
+ export type V2NewsletterCampaignStatus =
511
+ | "draft"
512
+ | "scheduled"
513
+ | "sending"
514
+ | "sent"
515
+ | "cancelled";
516
+
510
517
  export interface V2NewsletterCampaign extends V2Object {
511
518
  object: "newsletter_campaign";
512
519
  name: string;
513
520
  slug: string | null;
521
+ slug_prefix?: string | null;
514
522
  subject: string;
515
523
  preview_text: string | null;
516
- status: string;
524
+ markdown_content?: string | null;
525
+ series_id?: string | null;
526
+ series_name?: string | null;
527
+ template_id?: string | null;
528
+ list_ids?: string[];
529
+ tags?: string[] | null;
530
+ notes?: string | null;
531
+ from_name?: string | null;
532
+ from_email?: string | null;
533
+ reply_to_email?: string | null;
534
+ send_to_all?: boolean;
535
+ status: V2NewsletterCampaignStatus | string;
536
+ scheduled_at?: string | null;
517
537
  sent_at: string | null;
518
538
  completed_at: string | null;
519
539
  total_recipients: number;
520
540
  sent_count: number;
541
+ delivered_count?: number;
521
542
  opened_count: number;
522
543
  clicked_count: number;
544
+ unsubscribed_count?: number;
545
+ bounced_count?: number;
546
+ complained_count?: number;
547
+ created_at: string | null;
548
+ updated_at: string | null;
549
+ }
550
+
551
+ export interface V2NewsletterSeries extends V2Object {
552
+ object: "newsletter_series";
553
+ name: string;
554
+ description: string | null;
555
+ list_ids: string[];
556
+ from_name: string | null;
557
+ from_email: string | null;
558
+ reply_to_email: string | null;
559
+ subject_prefix: string | null;
560
+ cadence: "manual" | "daily" | "weekly" | "monthly" | string;
561
+ timezone: string | null;
562
+ send_time: string | null;
563
+ day_of_week: number | null;
564
+ day_of_month: number | null;
565
+ status: "active" | "paused" | "archived" | string;
566
+ last_sent_at: string | null;
567
+ next_send_at: string | null;
568
+ tags: string[] | null;
569
+ notes: string | null;
523
570
  created_at: string | null;
524
571
  updated_at: string | null;
525
572
  }
526
573
 
574
+ export interface V2NewsletterStatistics {
575
+ object: "newsletter_statistics";
576
+ total: number;
577
+ by_status: Record<string, number>;
578
+ recent_activity: Array<{ date: string; count: number }>;
579
+ }
580
+
527
581
  export interface V2NewsletterTrackingResponse {
528
582
  success: boolean;
529
583
  }
@@ -606,6 +660,93 @@ export interface V2NewsletterImportResult {
606
660
  }>;
607
661
  }
608
662
 
663
+ // --- Newsletter campaigns / series / statistics (admin) ---
664
+
665
+ export interface V2NewsletterCampaignCreateParams {
666
+ campaign_name: string;
667
+ subject: string;
668
+ /** Markdown body; rendered to HTML/text server-side. */
669
+ markdown_content: string;
670
+ slug?: string;
671
+ slug_prefix?: string | null;
672
+ /**
673
+ * `scheduled` requires a `scheduled_at`, the newsletter plan entitlement, and
674
+ * the `newsletters.publish` permission on the API key (creating/updating a
675
+ * draft only needs `newsletters.create`/`newsletters.update`).
676
+ */
677
+ status?: "draft" | "scheduled" | "cancelled";
678
+ /** Local datetime (YYYY-MM-DDTHH:MM[:SS]) in the site/series timezone. */
679
+ scheduled_at?: string | null;
680
+ preview_text?: string;
681
+ from_name?: string;
682
+ from_email?: string;
683
+ reply_to_email?: string;
684
+ /** Newsletter template version ID (`etpl_…`). */
685
+ template_id?: string | null;
686
+ /** Series ID (`nsr_…`). */
687
+ series_id?: string | null;
688
+ /** Target list IDs (`nll_…`). */
689
+ list_ids?: string[];
690
+ tags?: string[];
691
+ notes?: string;
692
+ }
693
+
694
+ export type V2NewsletterCampaignUpdateParams = Partial<
695
+ Omit<V2NewsletterCampaignCreateParams, "campaign_name" | "subject" | "markdown_content">
696
+ > & {
697
+ campaign_name?: string;
698
+ subject?: string;
699
+ markdown_content?: string;
700
+ };
701
+
702
+ export interface V2NewsletterSeriesCreateParams {
703
+ series_name: string;
704
+ description?: string;
705
+ status?: "active" | "paused" | "archived";
706
+ cadence?: "manual" | "daily" | "weekly" | "monthly";
707
+ timezone?: string;
708
+ send_time?: string;
709
+ day_of_week?: number;
710
+ day_of_month?: number;
711
+ next_send_at?: string | null;
712
+ list_ids?: string[];
713
+ from_name?: string;
714
+ from_email?: string;
715
+ reply_to_email?: string;
716
+ subject_prefix?: string;
717
+ tags?: string[];
718
+ notes?: string;
719
+ }
720
+
721
+ export type V2NewsletterSeriesUpdateParams = Partial<V2NewsletterSeriesCreateParams>;
722
+
723
+ export interface V2NewsletterStatisticsParams {
724
+ start_date?: string;
725
+ end_date?: string;
726
+ list_id?: string;
727
+ }
728
+
729
+ export interface V2NewsletterSubscriptionStatusUpdate {
730
+ status: "confirmed" | "unsubscribed" | "bounced" | "complained";
731
+ notes?: string;
732
+ }
733
+
734
+ export interface V2NewsletterBulkParams {
735
+ ids: string[];
736
+ action: "confirm" | "unsubscribe" | "delete" | "add_to_list" | "remove_from_list";
737
+ /** Required for add_to_list / remove_from_list. */
738
+ list_id?: string;
739
+ }
740
+
741
+ export interface V2NewsletterBulkResult {
742
+ object: "newsletter_bulk_result";
743
+ succeeded: number;
744
+ failed: number;
745
+ /** Per-id failures (id + reason) for the subscriptions that did not apply. */
746
+ failures: Array<{ id: string; error: string }>;
747
+ [key: string]: unknown;
748
+ }
749
+
609
750
  // --- Contact ---
610
751
 
611
752
  export interface V2ContactSubmission extends V2Object {
@@ -818,15 +959,105 @@ export interface V2GrantCreditResult {
818
959
 
819
960
  // --- Email ---
820
961
 
962
+ export type V2EmailTemplateType =
963
+ | "order_customer_receipt"
964
+ | "order_admin_notification"
965
+ | "signup_welcome"
966
+ | "order_fulfillment_notification"
967
+ | "order_cancellation_notification"
968
+ | "subscription_cancelled"
969
+ | "subscription_cancellation_admin_notification"
970
+ | "subscription_plan_changed"
971
+ | "subscription_plan_changed_admin_notification"
972
+ | "newsletter"
973
+ | "customer_support";
974
+
975
+ export type V2EmailTemplateStatus = "draft" | "published" | "archived";
976
+
821
977
  export interface V2EmailSendParams {
822
978
  to: string | string[];
823
- subject: string;
979
+ /** Required for raw sends; optional (overrides the rendered subject) for template sends. */
980
+ subject?: string;
824
981
  html?: string;
825
982
  text?: string;
826
983
  from?: string;
827
984
  reply_to?: string;
828
985
  cc?: string | string[];
829
986
  bcc?: string | string[];
987
+ /**
988
+ * Template-based send. Provide exactly one of `template_id` (a published
989
+ * template by ID) or `template_type` (the published template for that type);
990
+ * the template is rendered server-side with `variables` substituted in.
991
+ * Mutually exclusive with `html`/`text`.
992
+ */
993
+ template_id?: string;
994
+ template_type?: V2EmailTemplateType;
995
+ variables?: Record<string, string | number | null>;
996
+ /**
997
+ * When true, every placeholder referenced by the template must be present in
998
+ * `variables` (null counts as provided) — otherwise the API rejects the send
999
+ * instead of rendering the missing placeholders as empty strings.
1000
+ */
1001
+ strict?: boolean;
1002
+ }
1003
+
1004
+ export interface V2EmailTemplate extends V2Object {
1005
+ object: "email_template";
1006
+ template_type: V2EmailTemplateType;
1007
+ template_name: string;
1008
+ description: string | null;
1009
+ subject_template: string;
1010
+ html_template: string;
1011
+ text_template: string;
1012
+ status: V2EmailTemplateStatus;
1013
+ version: number;
1014
+ variables: string[];
1015
+ created_by: string | null;
1016
+ created_at: string;
1017
+ updated_at: string;
1018
+ published_at: string | null;
1019
+ /** Present on clone responses: the source template ID. */
1020
+ source_template_id?: string;
1021
+ }
1022
+
1023
+ export interface V2EmailTemplateType_Listing {
1024
+ object: "email_template_type";
1025
+ template_type: V2EmailTemplateType;
1026
+ variables: string[];
1027
+ }
1028
+
1029
+ export interface V2EmailTemplateListParams {
1030
+ template_type?: V2EmailTemplateType;
1031
+ status?: V2EmailTemplateStatus;
1032
+ }
1033
+
1034
+ export interface V2EmailTemplateCreateParams {
1035
+ template_type: V2EmailTemplateType;
1036
+ template_name: string;
1037
+ subject_template: string;
1038
+ html_template: string;
1039
+ text_template: string;
1040
+ description?: string;
1041
+ /**
1042
+ * Defaults to "draft". Creating directly into "published" additionally
1043
+ * requires the `templates.publish` permission (and the custom-email plan
1044
+ * entitlement, like all template mutations); otherwise the API returns 403.
1045
+ */
1046
+ status?: "draft" | "published";
1047
+ }
1048
+
1049
+ export interface V2EmailTemplateCloneParams {
1050
+ template_name?: string;
1051
+ subject_template?: string;
1052
+ html_template?: string;
1053
+ text_template?: string;
1054
+ description?: string;
1055
+ /**
1056
+ * Defaults to "draft". Creating directly into "published" additionally
1057
+ * requires the `templates.publish` permission (and the custom-email plan
1058
+ * entitlement, like all template mutations); otherwise the API returns 403.
1059
+ */
1060
+ status?: "draft" | "published";
830
1061
  }
831
1062
 
832
1063
  export interface V2EmailSendResult {