perspectapi-ts-sdk 2.8.2 → 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 +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/types/index.ts +1 -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
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -638,6 +638,7 @@ export interface SiteUserOrder {
|
|
|
638
638
|
export interface RequestOtpRequest {
|
|
639
639
|
email: string;
|
|
640
640
|
waitlist?: boolean; // Mark user as waitlist signup
|
|
641
|
+
metadata?: Record<string, any>; // Optional metadata to set on user creation/update
|
|
641
642
|
}
|
|
642
643
|
|
|
643
644
|
export interface VerifyOtpRequest {
|