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/README.md CHANGED
@@ -688,79 +688,56 @@ const lists = await client.newsletter.getLists(siteName);
688
688
  console.log('Available lists:', lists.data.lists);
689
689
  ```
690
690
 
691
- #### Newsletter Admin Functions
691
+ #### Newsletter Management APIs
692
+
693
+ `client.newsletter` is now public-only (subscribe/confirm/unsubscribe/preferences/public lists/published campaigns).
694
+ For management operations, use `client.newsletterManagement`.
692
695
 
693
696
  ```typescript
694
- // Get all subscriptions (admin only)
695
- const subscriptions = await client.newsletter.getSubscriptions(siteName, {
697
+ // Sync subscriber by email (canonical create/update path)
698
+ const sync = await client.newsletterManagement.syncSubscription(siteName, {
699
+ email: 'user@example.com',
700
+ name: 'User Name',
701
+ list_ids: ['list_default'],
702
+ resubscribe_override: false
703
+ });
704
+ console.log(sync.data.code); // CREATED, UPDATED, RESUBSCRIBED, ALREADY_UNSUBSCRIBED
705
+
706
+ // List subscribers
707
+ const subscriptions = await client.newsletterManagement.listSubscriptions(siteName, {
696
708
  page: 1,
697
709
  limit: 100,
698
- status: 'confirmed',
699
- list_id: 'list_weekly',
700
- search: 'john',
701
- startDate: '2024-01-01',
702
- endDate: '2024-12-31'
710
+ status: 'confirmed'
703
711
  });
704
712
 
705
- // Update subscription status
706
- await client.newsletter.updateSubscriptionStatus(
707
- siteName,
708
- 'sub_123',
709
- 'unsubscribed',
710
- 'Admin action: User requested via support'
711
- );
712
-
713
- // Bulk operations
714
- await client.newsletter.bulkUpdateSubscriptions(siteName, {
715
- ids: ['sub_123', 'sub_456'],
716
- action: 'add_to_list',
717
- list_id: 'list_special_offers'
713
+ // Import with override controls (row-level override wins)
714
+ await client.newsletterManagement.importSubscriptions(siteName, {
715
+ resubscribe_override: false,
716
+ rows: [
717
+ { email: 'user1@example.com', list_ids: ['list_default'] },
718
+ { email: 'user2@example.com', resubscribe_override: true }
719
+ ]
718
720
  });
719
721
 
720
- // List management
721
- const newList = await client.newsletter.createList(siteName, {
722
+ // List + campaign management
723
+ await client.newsletterManagement.createList(siteName, {
722
724
  list_name: 'VIP Customers',
723
725
  slug: 'vip-customers',
724
- description: 'Exclusive updates for VIP customers',
725
- is_public: false,
726
- is_default: false,
727
- double_opt_in: true,
728
- welcome_email_enabled: true
729
- });
730
-
731
- await client.newsletter.updateList(siteName, 'list_123', {
732
- description: 'Updated description',
733
- is_public: true
726
+ is_public: false
734
727
  });
735
728
 
736
- // Get statistics
737
- const stats = await client.newsletter.getStatistics(siteName, {
738
- startDate: '2024-01-01',
739
- endDate: '2024-12-31',
740
- list_id: 'list_weekly'
741
- });
742
- console.log('Total subscribers:', stats.data.totalSubscribers);
743
- console.log('Open rate:', stats.data.engagementMetrics.averageOpenRate);
744
-
745
- // Export subscriptions
746
- const exportData = await client.newsletter.exportSubscriptions(siteName, {
747
- format: 'csv', // csv, json, or xlsx
748
- status: 'confirmed',
749
- list_id: 'list_weekly'
729
+ await client.newsletterManagement.createCampaign(siteName, {
730
+ campaign_name: 'Spring Update',
731
+ subject: 'Spring Update',
732
+ markdown_content: '# Hello',
733
+ status: 'draft'
750
734
  });
751
- console.log('Download URL:', exportData.data.downloadUrl);
752
735
 
753
- // Import subscriptions
754
- const importResult = await client.newsletter.importSubscriptions(siteName, {
755
- subscriptions: [
756
- { email: 'user1@example.com', name: 'User One', lists: ['list_weekly'] },
757
- { email: 'user2@example.com', name: 'User Two', lists: ['list_daily'] }
758
- ],
759
- skip_confirmation: false, // Skip double opt-in for imported users
760
- update_existing: true // Update if email already exists
736
+ // Exports (csv/json only; xlsx returns UNSUPPORTED_FORMAT)
737
+ const exportData = await client.newsletterManagement.createExport(siteName, {
738
+ format: 'csv'
761
739
  });
762
- console.log('Imported:', importResult.data.imported);
763
- console.log('Failed:', importResult.data.failed);
740
+ console.log(exportData.data.downloadUrl);
764
741
  ```
765
742
 
766
743
  > 📚 **For complete newsletter documentation**, see [docs/newsletter.md](docs/newsletter.md)
@@ -847,9 +824,33 @@ const orders = await client.siteUsers.getOrders(siteName, {
847
824
  // Get subscriptions
848
825
  const subscriptions = await client.siteUsers.getSubscriptions(siteName);
849
826
 
850
- // Cancel subscription
827
+ // Cancel at end of billing period (default)
851
828
  await client.siteUsers.cancelSubscription(siteName, 'sub_123', csrfToken);
852
829
 
830
+ // Cancel immediately
831
+ await client.siteUsers.cancelSubscription(
832
+ siteName,
833
+ 'sub_123',
834
+ csrfToken,
835
+ { mode: 'immediate' }
836
+ );
837
+
838
+ // Cancel at a scheduled time (absolute)
839
+ await client.siteUsers.cancelSubscription(
840
+ siteName,
841
+ 'sub_123',
842
+ csrfToken,
843
+ { mode: 'scheduled', cancel_at: '2026-05-01T15:30:00Z' }
844
+ );
845
+
846
+ // Cancel after a configured delay (days/hours/minutes)
847
+ await client.siteUsers.cancelSubscription(
848
+ siteName,
849
+ 'sub_123',
850
+ csrfToken,
851
+ { mode: 'scheduled', delay_days: 7, delay_hours: 2 }
852
+ );
853
+
853
854
  // Logout
854
855
  await client.siteUsers.logout(siteName);
855
856
  client.setAuth(null);