perspectapi-ts-sdk 2.8.1 → 2.8.3
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 +95 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/types/index.ts +3 -0
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ A comprehensive TypeScript SDK for PerspectAPI, designed to work seamlessly with
|
|
|
13
13
|
- 📊 **Comprehensive Coverage** - All PerspectAPI endpoints supported
|
|
14
14
|
- 🧩 **High-Level Loaders** - Drop-in helpers for products, content, and checkout flows with fallbacks
|
|
15
15
|
- 📧 **Newsletter Management** - Complete newsletter subscription system with double opt-in, preferences, and lists
|
|
16
|
+
- 👥 **Site Users** - OTP-based customer accounts with metadata, profiles, orders, and subscriptions
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
18
19
|
|
|
@@ -734,6 +735,100 @@ console.log('Imported:', importResult.data.imported);
|
|
|
734
735
|
console.log('Failed:', importResult.data.failed);
|
|
735
736
|
```
|
|
736
737
|
|
|
738
|
+
> 📚 **For complete newsletter documentation**, see [docs/newsletter.md](docs/newsletter.md)
|
|
739
|
+
|
|
740
|
+
### Site Users (Customer Accounts)
|
|
741
|
+
|
|
742
|
+
Site users are per-site customer accounts with OTP-based authentication, separate from admin users.
|
|
743
|
+
|
|
744
|
+
```typescript
|
|
745
|
+
const siteName = 'your-site-name';
|
|
746
|
+
|
|
747
|
+
// Request OTP for login/signup (with optional metadata)
|
|
748
|
+
await client.siteUsers.requestOtp(
|
|
749
|
+
siteName,
|
|
750
|
+
{
|
|
751
|
+
email: 'user@example.com',
|
|
752
|
+
waitlist: true, // Optional: mark as waitlist signup
|
|
753
|
+
metadata: { // Optional: set metadata at signup time
|
|
754
|
+
signupSource: 'landing-page',
|
|
755
|
+
referralCode: 'FRIEND123',
|
|
756
|
+
interests: ['product-updates']
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
csrfToken
|
|
760
|
+
);
|
|
761
|
+
|
|
762
|
+
// Verify OTP and get JWT token
|
|
763
|
+
const response = await client.siteUsers.verifyOtp(
|
|
764
|
+
siteName,
|
|
765
|
+
{ email: 'user@example.com', code: '123456' },
|
|
766
|
+
csrfToken
|
|
767
|
+
);
|
|
768
|
+
|
|
769
|
+
const { token, user } = response.data;
|
|
770
|
+
client.setAuth(token); // Set auth for subsequent requests
|
|
771
|
+
|
|
772
|
+
// Get current user profile
|
|
773
|
+
const { data } = await client.siteUsers.getMe(siteName);
|
|
774
|
+
console.log(data.user); // Basic user fields + metadata
|
|
775
|
+
console.log(data.profile); // Key-value profile data
|
|
776
|
+
|
|
777
|
+
// Update user profile and metadata
|
|
778
|
+
await client.siteUsers.updateMe(
|
|
779
|
+
siteName,
|
|
780
|
+
{
|
|
781
|
+
first_name: 'John',
|
|
782
|
+
last_name: 'Doe',
|
|
783
|
+
metadata: {
|
|
784
|
+
preferences: { theme: 'dark' },
|
|
785
|
+
tags: ['premium'],
|
|
786
|
+
customField: 'value'
|
|
787
|
+
}
|
|
788
|
+
},
|
|
789
|
+
csrfToken
|
|
790
|
+
);
|
|
791
|
+
|
|
792
|
+
// Set profile key-values (phone, addresses, etc.)
|
|
793
|
+
await client.siteUsers.setProfileValue(
|
|
794
|
+
siteName,
|
|
795
|
+
'phone',
|
|
796
|
+
'+1-555-0123',
|
|
797
|
+
csrfToken
|
|
798
|
+
);
|
|
799
|
+
|
|
800
|
+
await client.siteUsers.setProfileValue(
|
|
801
|
+
siteName,
|
|
802
|
+
'address_shipping',
|
|
803
|
+
JSON.stringify({
|
|
804
|
+
line1: '123 Main St',
|
|
805
|
+
city: 'San Francisco',
|
|
806
|
+
state: 'CA',
|
|
807
|
+
postal_code: '94102',
|
|
808
|
+
country: 'US'
|
|
809
|
+
}),
|
|
810
|
+
csrfToken
|
|
811
|
+
);
|
|
812
|
+
|
|
813
|
+
// Get order history
|
|
814
|
+
const orders = await client.siteUsers.getOrders(siteName, {
|
|
815
|
+
limit: 50,
|
|
816
|
+
offset: 0
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
// Get subscriptions
|
|
820
|
+
const subscriptions = await client.siteUsers.getSubscriptions(siteName);
|
|
821
|
+
|
|
822
|
+
// Cancel subscription
|
|
823
|
+
await client.siteUsers.cancelSubscription(siteName, 'sub_123', csrfToken);
|
|
824
|
+
|
|
825
|
+
// Logout
|
|
826
|
+
await client.siteUsers.logout(siteName);
|
|
827
|
+
client.setAuth(null);
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
> 📚 **For complete site users documentation** including waitlist management, metadata patterns, cross-domain authentication, and complete examples, see [docs/site-users.md](docs/site-users.md)
|
|
831
|
+
|
|
737
832
|
## Configuration Options
|
|
738
833
|
|
|
739
834
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -582,6 +582,7 @@ interface SiteUser {
|
|
|
582
582
|
status: 'active' | 'suspended' | 'pending_verification';
|
|
583
583
|
email_verified: boolean;
|
|
584
584
|
waitlist: boolean;
|
|
585
|
+
metadata?: Record<string, any>;
|
|
585
586
|
created_at: string;
|
|
586
587
|
last_login_at?: string;
|
|
587
588
|
}
|
|
@@ -626,6 +627,7 @@ interface SiteUserOrder {
|
|
|
626
627
|
interface RequestOtpRequest {
|
|
627
628
|
email: string;
|
|
628
629
|
waitlist?: boolean;
|
|
630
|
+
metadata?: Record<string, any>;
|
|
629
631
|
}
|
|
630
632
|
interface VerifyOtpRequest {
|
|
631
633
|
email: string;
|
|
@@ -646,6 +648,7 @@ interface UpdateSiteUserRequest {
|
|
|
646
648
|
first_name?: string;
|
|
647
649
|
last_name?: string;
|
|
648
650
|
avatar_url?: string;
|
|
651
|
+
metadata?: Record<string, any>;
|
|
649
652
|
}
|
|
650
653
|
interface SetProfileValueRequest {
|
|
651
654
|
value: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -582,6 +582,7 @@ interface SiteUser {
|
|
|
582
582
|
status: 'active' | 'suspended' | 'pending_verification';
|
|
583
583
|
email_verified: boolean;
|
|
584
584
|
waitlist: boolean;
|
|
585
|
+
metadata?: Record<string, any>;
|
|
585
586
|
created_at: string;
|
|
586
587
|
last_login_at?: string;
|
|
587
588
|
}
|
|
@@ -626,6 +627,7 @@ interface SiteUserOrder {
|
|
|
626
627
|
interface RequestOtpRequest {
|
|
627
628
|
email: string;
|
|
628
629
|
waitlist?: boolean;
|
|
630
|
+
metadata?: Record<string, any>;
|
|
629
631
|
}
|
|
630
632
|
interface VerifyOtpRequest {
|
|
631
633
|
email: string;
|
|
@@ -646,6 +648,7 @@ interface UpdateSiteUserRequest {
|
|
|
646
648
|
first_name?: string;
|
|
647
649
|
last_name?: string;
|
|
648
650
|
avatar_url?: string;
|
|
651
|
+
metadata?: Record<string, any>;
|
|
649
652
|
}
|
|
650
653
|
interface SetProfileValueRequest {
|
|
651
654
|
value: string;
|
package/package.json
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -589,6 +589,7 @@ export interface SiteUser {
|
|
|
589
589
|
status: 'active' | 'suspended' | 'pending_verification';
|
|
590
590
|
email_verified: boolean;
|
|
591
591
|
waitlist: boolean;
|
|
592
|
+
metadata?: Record<string, any>;
|
|
592
593
|
created_at: string;
|
|
593
594
|
last_login_at?: string;
|
|
594
595
|
}
|
|
@@ -637,6 +638,7 @@ export interface SiteUserOrder {
|
|
|
637
638
|
export interface RequestOtpRequest {
|
|
638
639
|
email: string;
|
|
639
640
|
waitlist?: boolean; // Mark user as waitlist signup
|
|
641
|
+
metadata?: Record<string, any>; // Optional metadata to set on user creation/update
|
|
640
642
|
}
|
|
641
643
|
|
|
642
644
|
export interface VerifyOtpRequest {
|
|
@@ -660,6 +662,7 @@ export interface UpdateSiteUserRequest {
|
|
|
660
662
|
first_name?: string;
|
|
661
663
|
last_name?: string;
|
|
662
664
|
avatar_url?: string;
|
|
665
|
+
metadata?: Record<string, any>;
|
|
663
666
|
}
|
|
664
667
|
|
|
665
668
|
export interface SetProfileValueRequest {
|