perspectapi-ts-sdk 2.7.0 → 2.8.2

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.d.ts CHANGED
@@ -265,7 +265,7 @@ interface NewsletterUnsubscribeResponse {
265
265
  status?: string;
266
266
  }
267
267
  type ContentStatus = 'draft' | 'publish' | 'private' | 'trash';
268
- type ContentType = 'post' | 'page';
268
+ type ContentType = 'post' | 'page' | 'block';
269
269
  interface Content {
270
270
  id: number;
271
271
  pageTitle: string;
@@ -573,6 +573,85 @@ interface ContactStatusResponse {
573
573
  processed_at?: string;
574
574
  metadata?: Record<string, any>;
575
575
  }
576
+ interface SiteUser {
577
+ id: string;
578
+ email: string;
579
+ first_name?: string;
580
+ last_name?: string;
581
+ avatar_url?: string;
582
+ status: 'active' | 'suspended' | 'pending_verification';
583
+ email_verified: boolean;
584
+ waitlist: boolean;
585
+ metadata?: Record<string, any>;
586
+ created_at: string;
587
+ last_login_at?: string;
588
+ }
589
+ interface SiteUserProfile {
590
+ [key: string]: {
591
+ value: any;
592
+ updated_at: string;
593
+ };
594
+ }
595
+ interface SiteUserSubscription {
596
+ id: string;
597
+ provider: string;
598
+ provider_subscription_id?: string;
599
+ plan_name?: string;
600
+ plan_id?: string;
601
+ status: 'active' | 'past_due' | 'canceled' | 'paused' | 'trialing' | 'expired';
602
+ amount?: number;
603
+ currency?: string;
604
+ billing_interval?: string;
605
+ billing_interval_count?: number;
606
+ current_period_start?: string;
607
+ current_period_end?: string;
608
+ trial_start?: string;
609
+ trial_end?: string;
610
+ canceled_at?: string;
611
+ cancel_at_period_end: boolean;
612
+ created_at: string;
613
+ updated_at: string;
614
+ }
615
+ interface SiteUserOrder {
616
+ session_id: string;
617
+ order_id?: string;
618
+ customer_email?: string;
619
+ amount_total: number;
620
+ currency: string;
621
+ status: string;
622
+ payment_status?: string;
623
+ line_items: any[];
624
+ created_at: string;
625
+ updated_at: string;
626
+ }
627
+ interface RequestOtpRequest {
628
+ email: string;
629
+ waitlist?: boolean;
630
+ }
631
+ interface VerifyOtpRequest {
632
+ email: string;
633
+ code: string;
634
+ }
635
+ interface VerifyOtpResponse {
636
+ success: boolean;
637
+ token: string;
638
+ user: {
639
+ id: string;
640
+ email: string;
641
+ first_name?: string;
642
+ last_name?: string;
643
+ avatar_url?: string;
644
+ };
645
+ }
646
+ interface UpdateSiteUserRequest {
647
+ first_name?: string;
648
+ last_name?: string;
649
+ avatar_url?: string;
650
+ metadata?: Record<string, any>;
651
+ }
652
+ interface SetProfileValueRequest {
653
+ value: string;
654
+ }
576
655
  interface ApiError {
577
656
  message: string;
578
657
  code?: string;
@@ -1256,6 +1335,72 @@ declare class ProductsClient extends BaseClient {
1256
1335
  * e.g., 'shop/shoes/nike-air' -> 'shop', 'product-name' -> undefined
1257
1336
  */
1258
1337
  private extractSlugPrefix;
1338
+ /**
1339
+ * Get all options (and their values) for a product
1340
+ */
1341
+ getProductOptions(siteName: string, productId: number): Promise<ApiResponse<Array<{
1342
+ option_id: number;
1343
+ option_name: string;
1344
+ display_order: number;
1345
+ values: Array<{
1346
+ value_id: number;
1347
+ value: string;
1348
+ display_order: number;
1349
+ }>;
1350
+ }>>>;
1351
+ /**
1352
+ * Create a new product option (e.g., "Size", "Color")
1353
+ */
1354
+ createProductOption(siteName: string, productId: number, data: {
1355
+ option_name: string;
1356
+ display_order?: number;
1357
+ }): Promise<ApiResponse<{
1358
+ option_id: number;
1359
+ option_name: string;
1360
+ display_order: number;
1361
+ }>>;
1362
+ /**
1363
+ * Create a new value for a product option (e.g., "Small", "Red")
1364
+ */
1365
+ createProductOptionValue(siteName: string, productId: number, optionId: number, data: {
1366
+ value: string;
1367
+ display_order?: number;
1368
+ }): Promise<ApiResponse<{
1369
+ value_id: number;
1370
+ value: string;
1371
+ display_order: number;
1372
+ }>>;
1373
+ /**
1374
+ * Get all SKUs for a product (with their option value combinations)
1375
+ */
1376
+ getProductSkus(siteName: string, productId: number): Promise<ApiResponse<Array<{
1377
+ sku_id: number;
1378
+ sku: string;
1379
+ price?: number;
1380
+ sale_price?: number;
1381
+ stock_quantity?: number;
1382
+ combination_key: string;
1383
+ value_ids: number[];
1384
+ created_at: string;
1385
+ updated_at: string;
1386
+ }>>>;
1387
+ /**
1388
+ * Create or update a SKU for a product variant combination
1389
+ */
1390
+ createProductSku(siteName: string, productId: number, data: {
1391
+ sku: string;
1392
+ price?: number | null;
1393
+ sale_price?: number | null;
1394
+ stock_quantity?: number | null;
1395
+ value_ids: number[];
1396
+ }): Promise<ApiResponse<{
1397
+ sku_id: number;
1398
+ sku: string;
1399
+ price?: number;
1400
+ sale_price?: number;
1401
+ stock_quantity?: number;
1402
+ combination_key: string;
1403
+ }>>;
1259
1404
  }
1260
1405
 
1261
1406
  /**
@@ -2049,6 +2194,210 @@ declare class NewsletterClient extends BaseClient {
2049
2194
  static getTrackingPixel(): Uint8Array;
2050
2195
  }
2051
2196
 
2197
+ /**
2198
+ * Site Users client for PerspectAPI SDK
2199
+ * Handles per-site customer accounts (OTP-based auth, profiles, orders, subscriptions)
2200
+ */
2201
+
2202
+ declare class SiteUsersClient extends BaseClient {
2203
+ constructor(http: any, cache?: CacheManager);
2204
+ /**
2205
+ * Build a site user endpoint scoped to a site (without /sites prefix)
2206
+ */
2207
+ private siteUserEndpoint;
2208
+ /**
2209
+ * Request OTP for login/signup
2210
+ * @param siteName - The site name
2211
+ * @param data - Email address
2212
+ * @param csrfToken - CSRF token (required for browser-based submissions)
2213
+ */
2214
+ requestOtp(siteName: string, data: RequestOtpRequest, csrfToken?: string): Promise<ApiResponse<{
2215
+ success: boolean;
2216
+ }>>;
2217
+ /**
2218
+ * Verify OTP and get JWT token
2219
+ *
2220
+ * For cross-domain authentication, you must manually set the token after verification:
2221
+ * ```typescript
2222
+ * const response = await client.siteUsers.verifyOtp('mysite', { email, code });
2223
+ * const { token, user } = response.data;
2224
+ *
2225
+ * // Store token securely (choose one):
2226
+ * // Option 1: Memory (lost on refresh, most secure)
2227
+ * client.setAuth(token);
2228
+ *
2229
+ * // Option 2: httpOnly cookie on YOUR domain (recommended for production)
2230
+ * await fetch('/your-api/set-auth-cookie', {
2231
+ * method: 'POST',
2232
+ * body: JSON.stringify({ token })
2233
+ * });
2234
+ * client.setAuth(token);
2235
+ *
2236
+ * // Option 3: localStorage (vulnerable to XSS, not recommended)
2237
+ * localStorage.setItem('site_user_token', token);
2238
+ * client.setAuth(token);
2239
+ * ```
2240
+ *
2241
+ * For convenience, use `verifyOtpAndSetAuth()` to automatically set the token in memory.
2242
+ *
2243
+ * @param siteName - The site name
2244
+ * @param data - Email and code
2245
+ * @param csrfToken - CSRF token (required for browser-based submissions)
2246
+ */
2247
+ verifyOtp(siteName: string, data: VerifyOtpRequest, csrfToken?: string): Promise<ApiResponse<VerifyOtpResponse>>;
2248
+ /**
2249
+ * Verify OTP and automatically set the token for subsequent requests
2250
+ *
2251
+ * Convenience method that:
2252
+ * 1. Verifies the OTP
2253
+ * 2. Automatically calls setAuth() with the returned token
2254
+ *
2255
+ * Note: Token is stored in memory only and will be lost on page refresh.
2256
+ * For persistent auth, use verifyOtp() and store the token yourself.
2257
+ *
2258
+ * @param siteName - The site name
2259
+ * @param data - Email and code
2260
+ * @param csrfToken - CSRF token (required for browser-based submissions)
2261
+ */
2262
+ verifyOtpAndSetAuth(siteName: string, data: VerifyOtpRequest, csrfToken?: string): Promise<ApiResponse<VerifyOtpResponse>>;
2263
+ /**
2264
+ * Logout (clear session cookie)
2265
+ * @param siteName - The site name
2266
+ */
2267
+ logout(siteName: string): Promise<ApiResponse<{
2268
+ success: boolean;
2269
+ }>>;
2270
+ /**
2271
+ * Get current user profile
2272
+ * @param siteName - The site name
2273
+ */
2274
+ getMe(siteName: string): Promise<ApiResponse<{
2275
+ user: SiteUser;
2276
+ profile: SiteUserProfile;
2277
+ }>>;
2278
+ /**
2279
+ * Update current user profile
2280
+ * @param siteName - The site name
2281
+ * @param data - Fields to update
2282
+ * @param csrfToken - CSRF token (required)
2283
+ */
2284
+ updateMe(siteName: string, data: UpdateSiteUserRequest, csrfToken?: string): Promise<ApiResponse<{
2285
+ success: boolean;
2286
+ }>>;
2287
+ /**
2288
+ * Get all profile key-values
2289
+ * @param siteName - The site name
2290
+ */
2291
+ getProfile(siteName: string): Promise<ApiResponse<{
2292
+ profile: SiteUserProfile;
2293
+ }>>;
2294
+ /**
2295
+ * Set a profile key-value
2296
+ * @param siteName - The site name
2297
+ * @param key - Profile key (e.g., 'phone', 'whatsapp', 'address_shipping')
2298
+ * @param value - Profile value (string or JSON string)
2299
+ * @param csrfToken - CSRF token (required)
2300
+ */
2301
+ setProfileValue(siteName: string, key: string, value: string, csrfToken?: string): Promise<ApiResponse<{
2302
+ success: boolean;
2303
+ }>>;
2304
+ /**
2305
+ * Delete a profile key-value
2306
+ * @param siteName - The site name
2307
+ * @param key - Profile key to delete
2308
+ * @param csrfToken - CSRF token (required)
2309
+ */
2310
+ deleteProfileValue(siteName: string, key: string, csrfToken?: string): Promise<ApiResponse<{
2311
+ success: boolean;
2312
+ }>>;
2313
+ /**
2314
+ * Get transaction/order history
2315
+ * @param siteName - The site name
2316
+ * @param params - Pagination params
2317
+ */
2318
+ getOrders(siteName: string, params?: {
2319
+ limit?: number;
2320
+ offset?: number;
2321
+ }): Promise<ApiResponse<{
2322
+ orders: SiteUserOrder[];
2323
+ }>>;
2324
+ /**
2325
+ * Get single order detail
2326
+ * @param siteName - The site name
2327
+ * @param orderId - Order ID or session ID
2328
+ */
2329
+ getOrder(siteName: string, orderId: string): Promise<ApiResponse<{
2330
+ order: any;
2331
+ }>>;
2332
+ /**
2333
+ * Get payment subscriptions
2334
+ * @param siteName - The site name
2335
+ * @param params - Pagination params
2336
+ */
2337
+ getSubscriptions(siteName: string, params?: {
2338
+ limit?: number;
2339
+ offset?: number;
2340
+ }): Promise<ApiResponse<{
2341
+ subscriptions: SiteUserSubscription[];
2342
+ }>>;
2343
+ /**
2344
+ * Get single subscription detail
2345
+ * @param siteName - The site name
2346
+ * @param id - Subscription ID
2347
+ */
2348
+ getSubscription(siteName: string, id: string): Promise<ApiResponse<{
2349
+ subscription: SiteUserSubscription;
2350
+ }>>;
2351
+ /**
2352
+ * Cancel a subscription (marks for cancellation at period end)
2353
+ * @param siteName - The site name
2354
+ * @param id - Subscription ID
2355
+ * @param csrfToken - CSRF token (required)
2356
+ */
2357
+ cancelSubscription(siteName: string, id: string, csrfToken?: string): Promise<ApiResponse<{
2358
+ success: boolean;
2359
+ message: string;
2360
+ }>>;
2361
+ /**
2362
+ * Get linked newsletter subscriptions
2363
+ * @param siteName - The site name
2364
+ */
2365
+ getNewsletterSubscriptions(siteName: string): Promise<ApiResponse<{
2366
+ newsletters: any[];
2367
+ }>>;
2368
+ /**
2369
+ * List all site users (admin only)
2370
+ * @param siteName - The site name
2371
+ * @param params - Query params (limit, offset, status)
2372
+ */
2373
+ listUsers(siteName: string, params?: {
2374
+ limit?: number;
2375
+ offset?: number;
2376
+ status?: string;
2377
+ }): Promise<ApiResponse<{
2378
+ users: SiteUser[];
2379
+ }>>;
2380
+ /**
2381
+ * Get user detail (admin only)
2382
+ * @param siteName - The site name
2383
+ * @param userId - User ID
2384
+ */
2385
+ getUser(siteName: string, userId: string): Promise<ApiResponse<{
2386
+ user: SiteUser;
2387
+ profile: SiteUserProfile;
2388
+ }>>;
2389
+ /**
2390
+ * Update user status (admin only)
2391
+ * @param siteName - The site name
2392
+ * @param userId - User ID
2393
+ * @param status - New status
2394
+ * @param csrfToken - CSRF token (required)
2395
+ */
2396
+ updateUserStatus(siteName: string, userId: string, status: 'active' | 'suspended' | 'pending_verification', csrfToken?: string): Promise<ApiResponse<{
2397
+ success: boolean;
2398
+ }>>;
2399
+ }
2400
+
2052
2401
  /**
2053
2402
  * Main PerspectAPI SDK Client
2054
2403
  * Cloudflare Workers compatible TypeScript SDK
@@ -2068,6 +2417,7 @@ declare class PerspectApiClient {
2068
2417
  readonly checkout: CheckoutClient;
2069
2418
  readonly contact: ContactClient;
2070
2419
  readonly newsletter: NewsletterClient;
2420
+ readonly siteUsers: SiteUsersClient;
2071
2421
  constructor(config: PerspectApiConfig);
2072
2422
  /**
2073
2423
  * Update authentication token
@@ -2472,4 +2822,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
2472
2822
  error: string;
2473
2823
  }>;
2474
2824
 
2475
- export { type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, type AuthResponse, BaseClient, type BlogPost, type CacheConfig, CacheManager, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateSiteRequest, type CreateWebhookRequest, DEFAULT_IMAGE_SIZES, HttpClient, type HttpMethod, type ImageTransformOptions, InMemoryCacheAdapter, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, NewsletterClient, type NewsletterConfirmResponse, type NewsletterList, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, type Product, type ProductQueryParams, ProductsClient, type RequestOptions, type ResponsiveImageSizes, type SignInRequest, type SignUpRequest, type Site, SitesClient, type UpdateApiKeyRequest, type UpdateContentRequest, type User, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };
2825
+ export { type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, type AuthResponse, BaseClient, type BlogPost, type CacheConfig, CacheManager, CategoriesClient, type Category, type CategorySummary, type CheckoutAddress, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, type CheckoutSessionTax, type CheckoutTaxBreakdownItem, type CheckoutTaxCustomerExemptionRequest, type CheckoutTaxExemptionStatus, type CheckoutTaxRequest, type CheckoutTaxStrategy, ContactClient, type ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, type ContentCategoryResponse, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateNewsletterSubscriptionRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateSiteRequest, type CreateWebhookRequest, DEFAULT_IMAGE_SIZES, HttpClient, type HttpMethod, type ImageTransformOptions, InMemoryCacheAdapter, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, NewsletterClient, type NewsletterConfirmResponse, type NewsletterList, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterUnsubscribeRequest, type NewsletterUnsubscribeResponse, NoopCacheAdapter, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, type Product, type ProductQueryParams, ProductsClient, type RequestOptions, type RequestOtpRequest, type ResponsiveImageSizes, type SetProfileValueRequest, type SignInRequest, type SignUpRequest, type Site, type SiteUser, type SiteUserOrder, type SiteUserProfile, type SiteUserSubscription, SiteUsersClient, SitesClient, type UpdateApiKeyRequest, type UpdateContentRequest, type UpdateSiteUserRequest, type User, type VerifyOtpRequest, type VerifyOtpResponse, type Webhook, WebhooksClient, buildImageUrl, createApiError, createCheckoutSession, createPerspectApiClient, PerspectApiClient as default, generateResponsiveImageHtml, generateResponsiveUrls, generateSizesAttribute, generateSrcSet, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformMediaItem, transformProduct };