perspectapi-ts-sdk 1.1.1

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.
@@ -0,0 +1,1770 @@
1
+ /**
2
+ * Core types and interfaces for PerspectAPI SDK
3
+ */
4
+ interface ApiResponse<T = any> {
5
+ data?: T;
6
+ message?: string;
7
+ error?: string;
8
+ success?: boolean;
9
+ }
10
+ interface PaginationParams {
11
+ page?: number;
12
+ limit?: number;
13
+ offset?: number;
14
+ }
15
+ interface PaginatedResponse<T> extends ApiResponse<T[]> {
16
+ pagination?: {
17
+ page: number;
18
+ limit: number;
19
+ total: number;
20
+ totalPages: number;
21
+ };
22
+ }
23
+ interface SignUpRequest {
24
+ email: string;
25
+ password: string;
26
+ firstName?: string;
27
+ lastName?: string;
28
+ }
29
+ interface SignInRequest {
30
+ email: string;
31
+ password: string;
32
+ }
33
+ interface AuthResponse {
34
+ message: string;
35
+ user?: User;
36
+ token?: string;
37
+ }
38
+ interface User {
39
+ id: string;
40
+ email: string;
41
+ firstName?: string;
42
+ lastName?: string;
43
+ createdAt?: string;
44
+ isActive?: boolean;
45
+ }
46
+ interface ApiKey {
47
+ id: string;
48
+ name: string;
49
+ description?: string;
50
+ permissions: string[];
51
+ organizationId?: number;
52
+ siteName?: string;
53
+ isActive: boolean;
54
+ createdAt: string;
55
+ expiresAt?: string;
56
+ lastUsedAt?: string;
57
+ }
58
+ interface CreateApiKeyRequest {
59
+ name: string;
60
+ description?: string;
61
+ permissions: string[];
62
+ organizationId?: number;
63
+ siteName?: string;
64
+ expiresAt?: string;
65
+ }
66
+ interface UpdateApiKeyRequest {
67
+ name?: string;
68
+ description?: string;
69
+ permissions?: string[];
70
+ isActive?: boolean;
71
+ }
72
+ interface Organization {
73
+ id: number;
74
+ name: string;
75
+ description?: string;
76
+ createdAt: string;
77
+ updatedAt: string;
78
+ }
79
+ interface CreateOrganizationRequest {
80
+ name: string;
81
+ description?: string;
82
+ }
83
+ interface Site {
84
+ id: number;
85
+ name: string;
86
+ domain?: string;
87
+ managementDomain?: string;
88
+ description?: string;
89
+ organizationId: number;
90
+ isActive: boolean;
91
+ createdAt: string;
92
+ updatedAt: string;
93
+ }
94
+ interface CreateSiteRequest {
95
+ name: string;
96
+ domain?: string;
97
+ managementDomain?: string;
98
+ description?: string;
99
+ organizationId: number;
100
+ }
101
+ type ContentStatus = 'draft' | 'publish' | 'private' | 'trash';
102
+ type ContentType = 'post' | 'page';
103
+ interface Content {
104
+ id: number;
105
+ pageTitle: string;
106
+ pageContent: string;
107
+ contentMarkdown?: string;
108
+ custom?: Record<string, any>;
109
+ slug?: string;
110
+ pageStatus: ContentStatus;
111
+ pageType: ContentType;
112
+ userId?: number;
113
+ organizationId?: number;
114
+ createdAt: string;
115
+ updatedAt: string;
116
+ }
117
+ interface CreateContentRequest {
118
+ page_title: string;
119
+ page_content: string;
120
+ content_markdown?: string;
121
+ custom?: Record<string, any>;
122
+ slug?: string;
123
+ page_status?: ContentStatus;
124
+ page_type?: ContentType;
125
+ }
126
+ interface UpdateContentRequest extends Partial<CreateContentRequest> {
127
+ }
128
+ interface ContentQueryParams extends PaginationParams {
129
+ page_status?: ContentStatus;
130
+ page_type?: ContentType;
131
+ search?: string;
132
+ user_id?: number;
133
+ }
134
+ interface Category {
135
+ id: number;
136
+ name: string;
137
+ slug: string;
138
+ description?: string;
139
+ parentId?: number;
140
+ organizationId?: number;
141
+ createdAt: string;
142
+ updatedAt: string;
143
+ }
144
+ interface CreateCategoryRequest {
145
+ name: string;
146
+ slug?: string;
147
+ description?: string;
148
+ parentId?: number;
149
+ }
150
+ interface MediaItem {
151
+ media_id: string;
152
+ attachment_id: number;
153
+ file_name: string;
154
+ link: string;
155
+ content_type: string;
156
+ width: number;
157
+ height: number;
158
+ filesize: number;
159
+ r2_key: string;
160
+ site_name: string;
161
+ }
162
+ interface Product {
163
+ id: number | string;
164
+ name?: string;
165
+ product?: string;
166
+ description?: string;
167
+ description_markdown?: string;
168
+ price?: number;
169
+ currency?: string;
170
+ sku?: string;
171
+ slug?: string;
172
+ slug_prefix?: string;
173
+ image?: string;
174
+ media?: MediaItem[] | MediaItem[][];
175
+ isActive?: boolean;
176
+ organizationId?: number;
177
+ createdAt?: string;
178
+ updatedAt?: string;
179
+ gateway_product_id_live?: string;
180
+ gateway_product_id_test?: string;
181
+ stripe_product_id_live?: string;
182
+ stripe_product_id_test?: string;
183
+ [key: string]: any;
184
+ }
185
+ interface CreateProductRequest {
186
+ name: string;
187
+ description?: string;
188
+ price: number;
189
+ currency?: string;
190
+ sku?: string;
191
+ isActive?: boolean;
192
+ }
193
+ interface ProductQueryParams extends PaginationParams {
194
+ organizationId?: number;
195
+ isActive?: boolean;
196
+ search?: string;
197
+ category?: string | string[];
198
+ category_id?: number | string | Array<number | string>;
199
+ }
200
+ interface BlogPost {
201
+ id: string | number;
202
+ slug: string;
203
+ slug_prefix?: string;
204
+ page_type?: string;
205
+ title: string;
206
+ content?: string;
207
+ excerpt?: string;
208
+ image?: string;
209
+ published?: boolean;
210
+ created_at?: string;
211
+ updated_at?: string;
212
+ description?: string;
213
+ published_date?: string;
214
+ author?: string;
215
+ tags?: string[];
216
+ [key: string]: any;
217
+ }
218
+ interface PaymentGateway {
219
+ id: number;
220
+ name: string;
221
+ provider: string;
222
+ isActive: boolean;
223
+ configuration: Record<string, any>;
224
+ organizationId?: number;
225
+ createdAt: string;
226
+ updatedAt: string;
227
+ }
228
+ interface CreatePaymentGatewayRequest {
229
+ name: string;
230
+ provider: string;
231
+ configuration: Record<string, any>;
232
+ isActive?: boolean;
233
+ }
234
+ interface Webhook {
235
+ id: string;
236
+ name: string;
237
+ url: string;
238
+ provider: string;
239
+ events: string[];
240
+ isActive: boolean;
241
+ secret?: string;
242
+ organizationId?: number;
243
+ createdAt: string;
244
+ updatedAt: string;
245
+ }
246
+ interface CreateWebhookRequest {
247
+ name: string;
248
+ url: string;
249
+ provider: string;
250
+ events: string[];
251
+ isActive?: boolean;
252
+ secret?: string;
253
+ }
254
+ type CheckoutMetadataValue = string | number | boolean | null | CheckoutMetadataValue[] | {
255
+ [key: string]: CheckoutMetadataValue;
256
+ };
257
+ type CheckoutMetadata = Record<string, CheckoutMetadataValue>;
258
+ interface CreateCheckoutSessionRequest {
259
+ priceId?: string;
260
+ quantity?: number;
261
+ line_items?: Array<{
262
+ price?: string;
263
+ quantity: number;
264
+ price_data?: {
265
+ currency: string;
266
+ product_data: {
267
+ name: string;
268
+ description?: string;
269
+ images?: string[];
270
+ };
271
+ unit_amount: number;
272
+ };
273
+ }>;
274
+ success_url: string;
275
+ cancel_url: string;
276
+ successUrl?: string;
277
+ cancelUrl?: string;
278
+ customer_email?: string;
279
+ customerEmail?: string;
280
+ metadata?: CheckoutMetadata;
281
+ mode?: 'payment' | 'subscription' | 'setup';
282
+ automatic_tax?: {
283
+ enabled: boolean;
284
+ };
285
+ shipping_address_collection?: {
286
+ allowed_countries: string[];
287
+ };
288
+ billing_address_collection?: 'auto' | 'required';
289
+ }
290
+ interface CheckoutSession {
291
+ id: string;
292
+ url: string;
293
+ status: string;
294
+ }
295
+ interface ContactSubmission {
296
+ id: string;
297
+ name: string;
298
+ email: string;
299
+ subject?: string;
300
+ message: string;
301
+ status: string;
302
+ createdAt: string;
303
+ }
304
+ interface CreateContactRequest {
305
+ name: string;
306
+ email: string;
307
+ subject?: string;
308
+ message: string;
309
+ turnstileToken?: string;
310
+ }
311
+ interface ApiError {
312
+ message: string;
313
+ code?: string;
314
+ status?: number;
315
+ details?: any;
316
+ }
317
+ interface PerspectApiConfig {
318
+ baseUrl: string;
319
+ apiKey?: string;
320
+ jwt?: string;
321
+ timeout?: number;
322
+ retries?: number;
323
+ headers?: Record<string, string>;
324
+ }
325
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
326
+ interface RequestOptions {
327
+ method?: HttpMethod;
328
+ headers?: Record<string, string>;
329
+ body?: any;
330
+ params?: Record<string, string | number | boolean>;
331
+ timeout?: number;
332
+ }
333
+
334
+ /**
335
+ * HTTP Client for PerspectAPI SDK
336
+ * Cloudflare Workers compatible - uses native fetch API
337
+ */
338
+
339
+ declare class HttpClient {
340
+ private baseUrl;
341
+ private defaultHeaders;
342
+ private timeout;
343
+ private retries;
344
+ constructor(config: PerspectApiConfig);
345
+ /**
346
+ * Update authentication token
347
+ */
348
+ setAuth(jwt: string): void;
349
+ /**
350
+ * Update API key
351
+ */
352
+ setApiKey(apiKey: string): void;
353
+ /**
354
+ * Remove authentication
355
+ */
356
+ clearAuth(): void;
357
+ /**
358
+ * Make HTTP request with retry logic
359
+ */
360
+ request<T = any>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>>;
361
+ /**
362
+ * GET request
363
+ */
364
+ get<T = any>(endpoint: string, params?: Record<string, any>): Promise<ApiResponse<T>>;
365
+ /**
366
+ * POST request
367
+ */
368
+ post<T = any>(endpoint: string, body?: any): Promise<ApiResponse<T>>;
369
+ /**
370
+ * PUT request
371
+ */
372
+ put<T = any>(endpoint: string, body?: any): Promise<ApiResponse<T>>;
373
+ /**
374
+ * DELETE request
375
+ */
376
+ delete<T = any>(endpoint: string): Promise<ApiResponse<T>>;
377
+ /**
378
+ * PATCH request
379
+ */
380
+ patch<T = any>(endpoint: string, body?: any): Promise<ApiResponse<T>>;
381
+ /**
382
+ * Build full URL with query parameters
383
+ */
384
+ private buildUrl;
385
+ /**
386
+ * Build request options
387
+ */
388
+ private buildRequestOptions;
389
+ /**
390
+ * Fetch with timeout support
391
+ */
392
+ private fetchWithTimeout;
393
+ /**
394
+ * Handle response and errors
395
+ */
396
+ private handleResponse;
397
+ /**
398
+ * Delay utility for retries
399
+ */
400
+ private delay;
401
+ }
402
+ /**
403
+ * Create API Error from unknown error
404
+ */
405
+ declare function createApiError(error: unknown): ApiError;
406
+
407
+ /**
408
+ * Base client class for PerspectAPI SDK
409
+ */
410
+
411
+ declare abstract class BaseClient {
412
+ protected http: HttpClient;
413
+ protected basePath: string;
414
+ constructor(http: HttpClient, basePath: string);
415
+ /**
416
+ * Build a site-scoped endpoint relative to the API base path
417
+ */
418
+ protected siteScopedEndpoint(siteName: string, endpoint?: string, options?: {
419
+ includeSitesSegment?: boolean;
420
+ }): string;
421
+ /**
422
+ * Build endpoint path
423
+ */
424
+ protected buildPath(endpoint: string): string;
425
+ /**
426
+ * Handle paginated responses
427
+ */
428
+ protected getPaginated<T>(endpoint: string, params?: Record<string, any>): Promise<ApiResponse<T[]>>;
429
+ /**
430
+ * Handle single resource responses
431
+ */
432
+ protected getSingle<T>(endpoint: string): Promise<ApiResponse<T>>;
433
+ /**
434
+ * Handle create operations
435
+ */
436
+ protected create<T, R = T>(endpoint: string, data: T): Promise<ApiResponse<R>>;
437
+ /**
438
+ * Handle update operations
439
+ */
440
+ protected update<T, R = T>(endpoint: string, data: T): Promise<ApiResponse<R>>;
441
+ /**
442
+ * Handle partial update operations
443
+ */
444
+ protected patch<T, R = T>(endpoint: string, data: T): Promise<ApiResponse<R>>;
445
+ /**
446
+ * Handle delete operations
447
+ */
448
+ protected delete<T = any>(endpoint: string): Promise<ApiResponse<T>>;
449
+ }
450
+
451
+ /**
452
+ * Authentication client for PerspectAPI SDK
453
+ */
454
+
455
+ declare class AuthClient extends BaseClient {
456
+ constructor(http: any);
457
+ /**
458
+ * Get CSRF token
459
+ */
460
+ getCsrfToken(): Promise<ApiResponse<{
461
+ token: string;
462
+ }>>;
463
+ /**
464
+ * Sign up a new user
465
+ */
466
+ signUp(data: SignUpRequest): Promise<ApiResponse<{
467
+ message: string;
468
+ userId: string;
469
+ }>>;
470
+ /**
471
+ * Sign in user
472
+ */
473
+ signIn(data: SignInRequest): Promise<ApiResponse<AuthResponse>>;
474
+ /**
475
+ * Activate user account
476
+ */
477
+ activateAccount(activationKey: string): Promise<ApiResponse<{
478
+ message: string;
479
+ }>>;
480
+ /**
481
+ * Request password reset
482
+ */
483
+ forgotPassword(email: string): Promise<ApiResponse<{
484
+ message: string;
485
+ }>>;
486
+ /**
487
+ * Reset password with token
488
+ */
489
+ resetPassword(resetToken: string, password: string): Promise<ApiResponse<{
490
+ message: string;
491
+ }>>;
492
+ /**
493
+ * Get current user profile
494
+ */
495
+ getUserProfile(): Promise<ApiResponse<{
496
+ user: User;
497
+ }>>;
498
+ /**
499
+ * Sign out (clear local auth)
500
+ */
501
+ signOut(): void;
502
+ }
503
+
504
+ /**
505
+ * Content Management client for PerspectAPI SDK
506
+ */
507
+
508
+ declare class ContentClient extends BaseClient {
509
+ constructor(http: any);
510
+ /**
511
+ * Get all content with pagination and filtering for a site
512
+ */
513
+ getContent(siteName: string, params?: ContentQueryParams): Promise<PaginatedResponse<Content>>;
514
+ /**
515
+ * Get content by ID
516
+ */
517
+ getContentById(id: number): Promise<ApiResponse<Content>>;
518
+ /**
519
+ * Get content by slug for a site
520
+ */
521
+ getContentBySlug(siteName: string, slug: string): Promise<ApiResponse<Content>>;
522
+ /**
523
+ * Create new content
524
+ */
525
+ createContent(data: CreateContentRequest): Promise<ApiResponse<Content>>;
526
+ /**
527
+ * Update content
528
+ */
529
+ updateContent(id: number, data: UpdateContentRequest): Promise<ApiResponse<Content>>;
530
+ /**
531
+ * Partially update content
532
+ */
533
+ patchContent(id: number, data: Partial<UpdateContentRequest>): Promise<ApiResponse<Content>>;
534
+ /**
535
+ * Delete content
536
+ */
537
+ deleteContent(id: number): Promise<ApiResponse<{
538
+ message: string;
539
+ }>>;
540
+ /**
541
+ * Publish content
542
+ */
543
+ publishContent(id: number): Promise<ApiResponse<Content>>;
544
+ /**
545
+ * Unpublish content
546
+ */
547
+ unpublishContent(id: number): Promise<ApiResponse<Content>>;
548
+ /**
549
+ * Move content to trash
550
+ */
551
+ trashContent(id: number): Promise<ApiResponse<Content>>;
552
+ /**
553
+ * Restore content from trash
554
+ */
555
+ restoreContent(id: number): Promise<ApiResponse<Content>>;
556
+ /**
557
+ * Get content revisions
558
+ */
559
+ getContentRevisions(id: number): Promise<ApiResponse<Content[]>>;
560
+ /**
561
+ * Duplicate content
562
+ */
563
+ duplicateContent(id: number): Promise<ApiResponse<Content>>;
564
+ }
565
+
566
+ /**
567
+ * API Keys Management client for PerspectAPI SDK
568
+ */
569
+
570
+ declare class ApiKeysClient extends BaseClient {
571
+ constructor(http: any);
572
+ /**
573
+ * Get all API keys
574
+ */
575
+ getApiKeys(params?: {
576
+ page?: number;
577
+ limit?: number;
578
+ }): Promise<PaginatedResponse<ApiKey>>;
579
+ /**
580
+ * Get API key by ID
581
+ */
582
+ getApiKeyById(id: string): Promise<ApiResponse<ApiKey>>;
583
+ /**
584
+ * Create new API key
585
+ */
586
+ createApiKey(data: CreateApiKeyRequest): Promise<ApiResponse<ApiKey & {
587
+ key: string;
588
+ }>>;
589
+ /**
590
+ * Update API key
591
+ */
592
+ updateApiKey(id: string, data: UpdateApiKeyRequest): Promise<ApiResponse<ApiKey>>;
593
+ /**
594
+ * Delete API key
595
+ */
596
+ deleteApiKey(id: string): Promise<ApiResponse<{
597
+ message: string;
598
+ }>>;
599
+ /**
600
+ * Regenerate API key
601
+ */
602
+ regenerateApiKey(id: string): Promise<ApiResponse<ApiKey & {
603
+ key: string;
604
+ }>>;
605
+ /**
606
+ * Activate API key
607
+ */
608
+ activateApiKey(id: string): Promise<ApiResponse<ApiKey>>;
609
+ /**
610
+ * Deactivate API key
611
+ */
612
+ deactivateApiKey(id: string): Promise<ApiResponse<ApiKey>>;
613
+ /**
614
+ * Get API key usage statistics
615
+ */
616
+ getApiKeyStats(id: string): Promise<ApiResponse<{
617
+ totalRequests: number;
618
+ requestsToday: number;
619
+ requestsThisMonth: number;
620
+ lastUsedAt?: string;
621
+ }>>;
622
+ /**
623
+ * Test API key validity
624
+ */
625
+ testApiKey(key: string): Promise<ApiResponse<{
626
+ valid: boolean;
627
+ keyId?: string;
628
+ permissions?: string[];
629
+ expiresAt?: string;
630
+ }>>;
631
+ }
632
+
633
+ /**
634
+ * Organizations Management client for PerspectAPI SDK
635
+ */
636
+
637
+ declare class OrganizationsClient extends BaseClient {
638
+ constructor(http: any);
639
+ /**
640
+ * Get all organizations
641
+ */
642
+ getOrganizations(params?: {
643
+ page?: number;
644
+ limit?: number;
645
+ }): Promise<PaginatedResponse<Organization>>;
646
+ /**
647
+ * Get organization by ID
648
+ */
649
+ getOrganizationById(id: number): Promise<ApiResponse<Organization>>;
650
+ /**
651
+ * Create new organization
652
+ */
653
+ createOrganization(data: CreateOrganizationRequest): Promise<ApiResponse<Organization>>;
654
+ /**
655
+ * Update organization
656
+ */
657
+ updateOrganization(id: number, data: Partial<CreateOrganizationRequest>): Promise<ApiResponse<Organization>>;
658
+ /**
659
+ * Delete organization
660
+ */
661
+ deleteOrganization(id: number): Promise<ApiResponse<{
662
+ message: string;
663
+ }>>;
664
+ /**
665
+ * Get organization members
666
+ */
667
+ getOrganizationMembers(id: number): Promise<ApiResponse<Array<{
668
+ id: string;
669
+ email: string;
670
+ firstName?: string;
671
+ lastName?: string;
672
+ role: string;
673
+ joinedAt: string;
674
+ }>>>;
675
+ /**
676
+ * Add member to organization
677
+ */
678
+ addOrganizationMember(id: number, data: {
679
+ email: string;
680
+ role: string;
681
+ }): Promise<ApiResponse<{
682
+ message: string;
683
+ }>>;
684
+ /**
685
+ * Update organization member role
686
+ */
687
+ updateOrganizationMember(id: number, userId: string, data: {
688
+ role: string;
689
+ }): Promise<ApiResponse<{
690
+ message: string;
691
+ }>>;
692
+ /**
693
+ * Remove member from organization
694
+ */
695
+ removeOrganizationMember(id: number, userId: string): Promise<ApiResponse<{
696
+ message: string;
697
+ }>>;
698
+ /**
699
+ * Get organization settings
700
+ */
701
+ getOrganizationSettings(id: number): Promise<ApiResponse<Record<string, any>>>;
702
+ /**
703
+ * Update organization settings
704
+ */
705
+ updateOrganizationSettings(id: number, settings: Record<string, any>): Promise<ApiResponse<Record<string, any>>>;
706
+ }
707
+
708
+ /**
709
+ * Sites Management client for PerspectAPI SDK
710
+ */
711
+
712
+ declare class SitesClient extends BaseClient {
713
+ constructor(http: any);
714
+ /**
715
+ * Get all sites
716
+ */
717
+ getSites(params?: {
718
+ page?: number;
719
+ limit?: number;
720
+ organizationId?: number;
721
+ }): Promise<PaginatedResponse<Site>>;
722
+ /**
723
+ * Get site by ID
724
+ */
725
+ getSiteById(id: number): Promise<ApiResponse<Site>>;
726
+ /**
727
+ * Get site by name
728
+ */
729
+ getSiteByName(name: string): Promise<ApiResponse<Site>>;
730
+ /**
731
+ * Create new site
732
+ */
733
+ createSite(data: CreateSiteRequest): Promise<ApiResponse<Site>>;
734
+ /**
735
+ * Update site
736
+ */
737
+ updateSite(id: number, data: Partial<CreateSiteRequest>): Promise<ApiResponse<Site>>;
738
+ /**
739
+ * Delete site
740
+ */
741
+ deleteSite(id: number): Promise<ApiResponse<{
742
+ message: string;
743
+ }>>;
744
+ /**
745
+ * Activate site
746
+ */
747
+ activateSite(id: number): Promise<ApiResponse<Site>>;
748
+ /**
749
+ * Deactivate site
750
+ */
751
+ deactivateSite(id: number): Promise<ApiResponse<Site>>;
752
+ /**
753
+ * Get site configuration
754
+ */
755
+ getSiteConfig(id: number): Promise<ApiResponse<Record<string, any>>>;
756
+ /**
757
+ * Update site configuration
758
+ */
759
+ updateSiteConfig(id: number, config: Record<string, any>): Promise<ApiResponse<Record<string, any>>>;
760
+ /**
761
+ * Get site analytics
762
+ */
763
+ getSiteAnalytics(id: number, params?: {
764
+ startDate?: string;
765
+ endDate?: string;
766
+ metrics?: string[];
767
+ }): Promise<ApiResponse<{
768
+ pageViews: number;
769
+ uniqueVisitors: number;
770
+ bounceRate: number;
771
+ avgSessionDuration: number;
772
+ topPages: Array<{
773
+ path: string;
774
+ views: number;
775
+ }>;
776
+ }>>;
777
+ /**
778
+ * Get site domains
779
+ */
780
+ getSiteDomains(id: number): Promise<ApiResponse<Array<{
781
+ domain: string;
782
+ isPrimary: boolean;
783
+ isVerified: boolean;
784
+ createdAt: string;
785
+ }>>>;
786
+ /**
787
+ * Add domain to site
788
+ */
789
+ addSiteDomain(id: number, data: {
790
+ domain: string;
791
+ isPrimary?: boolean;
792
+ }): Promise<ApiResponse<{
793
+ message: string;
794
+ }>>;
795
+ /**
796
+ * Remove domain from site
797
+ */
798
+ removeSiteDomain(id: number, domain: string): Promise<ApiResponse<{
799
+ message: string;
800
+ }>>;
801
+ /**
802
+ * Verify domain ownership
803
+ */
804
+ verifySiteDomain(id: number, domain: string): Promise<ApiResponse<{
805
+ verified: boolean;
806
+ verificationMethod: string;
807
+ verificationValue: string;
808
+ }>>;
809
+ }
810
+
811
+ /**
812
+ * Products Management client for PerspectAPI SDK
813
+ */
814
+
815
+ declare class ProductsClient extends BaseClient {
816
+ constructor(http: any);
817
+ /**
818
+ * Get all products for a site
819
+ */
820
+ getProducts(siteName: string, params?: ProductQueryParams): Promise<PaginatedResponse<Product>>;
821
+ /**
822
+ * Get product by ID
823
+ */
824
+ getProductById(id: number): Promise<ApiResponse<Product>>;
825
+ /**
826
+ * Get product by SKU
827
+ */
828
+ getProductBySku(sku: string): Promise<ApiResponse<Product>>;
829
+ /**
830
+ * Get product by slug and site name
831
+ */
832
+ getProductBySlug(siteName: string, slug: string): Promise<ApiResponse<Product & {
833
+ variants?: any[];
834
+ }>>;
835
+ /**
836
+ * Create new product
837
+ */
838
+ createProduct(data: CreateProductRequest): Promise<ApiResponse<Product>>;
839
+ /**
840
+ * Update product
841
+ */
842
+ updateProduct(id: number, data: Partial<CreateProductRequest>): Promise<ApiResponse<Product>>;
843
+ /**
844
+ * Delete product
845
+ */
846
+ deleteProduct(id: number): Promise<ApiResponse<{
847
+ message: string;
848
+ }>>;
849
+ /**
850
+ * Activate product
851
+ */
852
+ activateProduct(id: number): Promise<ApiResponse<Product>>;
853
+ /**
854
+ * Deactivate product
855
+ */
856
+ deactivateProduct(id: number): Promise<ApiResponse<Product>>;
857
+ /**
858
+ * Get product variants
859
+ */
860
+ getProductVariants(id: number): Promise<ApiResponse<Array<{
861
+ id: number;
862
+ name: string;
863
+ sku: string;
864
+ price: number;
865
+ inventory: number;
866
+ attributes: Record<string, any>;
867
+ }>>>;
868
+ /**
869
+ * Add product variant
870
+ */
871
+ addProductVariant(id: number, data: {
872
+ name: string;
873
+ sku: string;
874
+ price: number;
875
+ inventory?: number;
876
+ attributes?: Record<string, any>;
877
+ }): Promise<ApiResponse<{
878
+ message: string;
879
+ }>>;
880
+ /**
881
+ * Update product variant
882
+ */
883
+ updateProductVariant(id: number, variantId: number, data: {
884
+ name?: string;
885
+ sku?: string;
886
+ price?: number;
887
+ inventory?: number;
888
+ attributes?: Record<string, any>;
889
+ }): Promise<ApiResponse<{
890
+ message: string;
891
+ }>>;
892
+ /**
893
+ * Delete product variant
894
+ */
895
+ deleteProductVariant(id: number, variantId: number): Promise<ApiResponse<{
896
+ message: string;
897
+ }>>;
898
+ /**
899
+ * Get product inventory
900
+ */
901
+ getProductInventory(id: number): Promise<ApiResponse<{
902
+ totalStock: number;
903
+ availableStock: number;
904
+ reservedStock: number;
905
+ lowStockThreshold: number;
906
+ isLowStock: boolean;
907
+ }>>;
908
+ /**
909
+ * Update product inventory
910
+ */
911
+ updateProductInventory(id: number, data: {
912
+ quantity: number;
913
+ operation: 'add' | 'subtract' | 'set';
914
+ reason?: string;
915
+ }): Promise<ApiResponse<{
916
+ message: string;
917
+ newQuantity: number;
918
+ }>>;
919
+ /**
920
+ * Get product categories
921
+ */
922
+ getProductCategories(id: number): Promise<ApiResponse<Array<{
923
+ id: number;
924
+ name: string;
925
+ slug: string;
926
+ }>>>;
927
+ /**
928
+ * Add product to category
929
+ */
930
+ addProductToCategory(id: number, categoryId: number): Promise<ApiResponse<{
931
+ message: string;
932
+ }>>;
933
+ /**
934
+ * Remove product from category
935
+ */
936
+ removeProductFromCategory(id: number, categoryId: number): Promise<ApiResponse<{
937
+ message: string;
938
+ }>>;
939
+ /**
940
+ * Get products by category slug
941
+ */
942
+ getProductsByCategorySlug(siteName: string, categorySlug: string, params?: {
943
+ page?: number;
944
+ limit?: number;
945
+ published?: boolean;
946
+ search?: string;
947
+ }): Promise<ApiResponse<{
948
+ data: Product[];
949
+ category: {
950
+ id: number;
951
+ name: string;
952
+ slug: string;
953
+ description?: string;
954
+ };
955
+ meta: {
956
+ count: number;
957
+ limit?: number;
958
+ offset?: number;
959
+ };
960
+ }>>;
961
+ }
962
+
963
+ /**
964
+ * Categories Management client for PerspectAPI SDK
965
+ */
966
+
967
+ declare class CategoriesClient extends BaseClient {
968
+ constructor(http: any);
969
+ /**
970
+ * Get all categories
971
+ */
972
+ getCategories(params?: {
973
+ page?: number;
974
+ limit?: number;
975
+ parentId?: number;
976
+ organizationId?: number;
977
+ }): Promise<PaginatedResponse<Category>>;
978
+ /**
979
+ * Get category by ID
980
+ */
981
+ getCategoryById(id: number): Promise<ApiResponse<Category>>;
982
+ /**
983
+ * Get category by slug
984
+ */
985
+ getCategoryBySlug(slug: string): Promise<ApiResponse<Category>>;
986
+ /**
987
+ * Get product category by slug (for products)
988
+ */
989
+ getProductCategoryBySlug(siteName: string, slug: string): Promise<ApiResponse<Category>>;
990
+ /**
991
+ * Create new category
992
+ */
993
+ createCategory(data: CreateCategoryRequest): Promise<ApiResponse<Category>>;
994
+ /**
995
+ * Update category
996
+ */
997
+ updateCategory(id: number, data: Partial<CreateCategoryRequest>): Promise<ApiResponse<Category>>;
998
+ /**
999
+ * Delete category
1000
+ */
1001
+ deleteCategory(id: number): Promise<ApiResponse<{
1002
+ message: string;
1003
+ }>>;
1004
+ /**
1005
+ * Get category tree (hierarchical structure)
1006
+ */
1007
+ getCategoryTree(rootId?: number): Promise<ApiResponse<Array<Category & {
1008
+ children: Category[];
1009
+ }>>>;
1010
+ /**
1011
+ * Get category children
1012
+ */
1013
+ getCategoryChildren(id: number): Promise<ApiResponse<Category[]>>;
1014
+ /**
1015
+ * Get category parent
1016
+ */
1017
+ getCategoryParent(id: number): Promise<ApiResponse<Category | null>>;
1018
+ /**
1019
+ * Move category to new parent
1020
+ */
1021
+ moveCategoryToParent(id: number, parentId: number | null): Promise<ApiResponse<Category>>;
1022
+ /**
1023
+ * Get category breadcrumb path
1024
+ */
1025
+ getCategoryBreadcrumb(id: number): Promise<ApiResponse<Array<{
1026
+ id: number;
1027
+ name: string;
1028
+ slug: string;
1029
+ }>>>;
1030
+ /**
1031
+ * Get category content/products
1032
+ */
1033
+ getCategoryContent(id: number, params?: {
1034
+ page?: number;
1035
+ limit?: number;
1036
+ type?: 'content' | 'products' | 'all';
1037
+ }): Promise<ApiResponse<{
1038
+ content: any[];
1039
+ products: any[];
1040
+ total: number;
1041
+ }>>;
1042
+ /**
1043
+ * Bulk update category order
1044
+ */
1045
+ updateCategoryOrder(updates: Array<{
1046
+ id: number;
1047
+ order: number;
1048
+ parentId?: number;
1049
+ }>): Promise<ApiResponse<{
1050
+ message: string;
1051
+ }>>;
1052
+ /**
1053
+ * Search categories
1054
+ */
1055
+ searchCategories(query: string, params?: {
1056
+ limit?: number;
1057
+ organizationId?: number;
1058
+ }): Promise<ApiResponse<Category[]>>;
1059
+ }
1060
+
1061
+ /**
1062
+ * Webhooks Management client for PerspectAPI SDK
1063
+ */
1064
+
1065
+ declare class WebhooksClient extends BaseClient {
1066
+ constructor(http: any);
1067
+ /**
1068
+ * Get all webhooks
1069
+ */
1070
+ getWebhooks(params?: {
1071
+ page?: number;
1072
+ limit?: number;
1073
+ provider?: string;
1074
+ isActive?: boolean;
1075
+ }): Promise<PaginatedResponse<Webhook>>;
1076
+ /**
1077
+ * Get webhook by ID
1078
+ */
1079
+ getWebhookById(id: string): Promise<ApiResponse<Webhook>>;
1080
+ /**
1081
+ * Create new webhook
1082
+ */
1083
+ createWebhook(data: CreateWebhookRequest): Promise<ApiResponse<Webhook>>;
1084
+ /**
1085
+ * Update webhook
1086
+ */
1087
+ updateWebhook(id: string, data: Partial<CreateWebhookRequest>): Promise<ApiResponse<Webhook>>;
1088
+ /**
1089
+ * Delete webhook
1090
+ */
1091
+ deleteWebhook(id: string): Promise<ApiResponse<{
1092
+ message: string;
1093
+ }>>;
1094
+ /**
1095
+ * Activate webhook
1096
+ */
1097
+ activateWebhook(id: string): Promise<ApiResponse<Webhook>>;
1098
+ /**
1099
+ * Deactivate webhook
1100
+ */
1101
+ deactivateWebhook(id: string): Promise<ApiResponse<Webhook>>;
1102
+ /**
1103
+ * Test webhook
1104
+ */
1105
+ testWebhook(id: string, data?: any): Promise<ApiResponse<{
1106
+ success: boolean;
1107
+ statusCode: number;
1108
+ response: any;
1109
+ duration: number;
1110
+ }>>;
1111
+ /**
1112
+ * Get webhook events
1113
+ */
1114
+ getWebhookEvents(id: string, params?: {
1115
+ page?: number;
1116
+ limit?: number;
1117
+ status?: 'pending' | 'processing' | 'completed' | 'failed';
1118
+ startDate?: string;
1119
+ endDate?: string;
1120
+ }): Promise<PaginatedResponse<{
1121
+ id: string;
1122
+ eventType: string;
1123
+ status: string;
1124
+ payload: any;
1125
+ response?: any;
1126
+ attempts: number;
1127
+ createdAt: string;
1128
+ processedAt?: string;
1129
+ }>>;
1130
+ /**
1131
+ * Get webhook logs
1132
+ */
1133
+ getWebhookLogs(id: string, params?: {
1134
+ page?: number;
1135
+ limit?: number;
1136
+ level?: 'info' | 'warn' | 'error';
1137
+ startDate?: string;
1138
+ endDate?: string;
1139
+ }): Promise<PaginatedResponse<{
1140
+ id: string;
1141
+ level: string;
1142
+ message: string;
1143
+ metadata?: any;
1144
+ createdAt: string;
1145
+ }>>;
1146
+ /**
1147
+ * Get webhook statistics
1148
+ */
1149
+ getWebhookStats(id?: string): Promise<ApiResponse<{
1150
+ totalWebhooks: number;
1151
+ activeWebhooks: number;
1152
+ totalEvents: number;
1153
+ successfulEvents: number;
1154
+ failedEvents: number;
1155
+ averageResponseTime: number;
1156
+ eventsByProvider: Record<string, number>;
1157
+ recentActivity: Array<{
1158
+ date: string;
1159
+ events: number;
1160
+ successes: number;
1161
+ failures: number;
1162
+ }>;
1163
+ }>>;
1164
+ /**
1165
+ * Get supported webhook providers
1166
+ */
1167
+ getWebhookProviders(): Promise<ApiResponse<Array<{
1168
+ name: string;
1169
+ displayName: string;
1170
+ description: string;
1171
+ supportedEvents: string[];
1172
+ configurationFields: Array<{
1173
+ name: string;
1174
+ type: string;
1175
+ required: boolean;
1176
+ description: string;
1177
+ }>;
1178
+ }>>>;
1179
+ /**
1180
+ * Retry failed webhook event
1181
+ */
1182
+ retryWebhookEvent(webhookId: string, eventId: string): Promise<ApiResponse<{
1183
+ success: boolean;
1184
+ message: string;
1185
+ }>>;
1186
+ /**
1187
+ * Bulk retry failed webhook events
1188
+ */
1189
+ bulkRetryWebhookEvents(webhookId: string, eventIds: string[]): Promise<ApiResponse<{
1190
+ success: boolean;
1191
+ retriedCount: number;
1192
+ failedCount: number;
1193
+ }>>;
1194
+ /**
1195
+ * Get webhook delivery attempts
1196
+ */
1197
+ getWebhookDeliveryAttempts(webhookId: string, eventId: string): Promise<ApiResponse<Array<{
1198
+ id: string;
1199
+ attempt: number;
1200
+ statusCode: number;
1201
+ response: any;
1202
+ duration: number;
1203
+ createdAt: string;
1204
+ }>>>;
1205
+ }
1206
+
1207
+ /**
1208
+ * Checkout/Stripe client for PerspectAPI SDK
1209
+ */
1210
+
1211
+ declare class CheckoutClient extends BaseClient {
1212
+ constructor(http: any);
1213
+ /**
1214
+ * Get CSRF token for a specific site
1215
+ * @param siteName - The site name to get CSRF token for
1216
+ */
1217
+ getCsrfToken(siteName: string): Promise<ApiResponse<{
1218
+ csrf_token: string;
1219
+ site_id: string;
1220
+ site_name: string;
1221
+ }>>;
1222
+ /**
1223
+ * Create Stripe checkout session with CSRF protection
1224
+ * @param siteName - The site name for the checkout session
1225
+ * @param data - Checkout session data (can include priceId for single item or line_items for multiple)
1226
+ * @param csrfToken - Optional CSRF token (if not provided, will fetch automatically)
1227
+ */
1228
+ createCheckoutSession(siteName: string, data: CreateCheckoutSessionRequest, csrfToken?: string): Promise<ApiResponse<CheckoutSession>>;
1229
+ /**
1230
+ * Get checkout session by ID
1231
+ */
1232
+ getCheckoutSession(sessionId: string): Promise<ApiResponse<{
1233
+ id: string;
1234
+ status: string;
1235
+ paymentStatus: string;
1236
+ customerEmail?: string;
1237
+ amountTotal: number;
1238
+ currency: string;
1239
+ metadata?: Record<string, string>;
1240
+ createdAt: string;
1241
+ expiresAt: string;
1242
+ }>>;
1243
+ /**
1244
+ * Get checkout sessions for organization
1245
+ */
1246
+ getCheckoutSessions(params?: {
1247
+ page?: number;
1248
+ limit?: number;
1249
+ status?: string;
1250
+ customerEmail?: string;
1251
+ startDate?: string;
1252
+ endDate?: string;
1253
+ }): Promise<ApiResponse<Array<{
1254
+ id: string;
1255
+ status: string;
1256
+ paymentStatus: string;
1257
+ customerEmail?: string;
1258
+ amountTotal: number;
1259
+ currency: string;
1260
+ createdAt: string;
1261
+ }>>>;
1262
+ /**
1263
+ * Cancel checkout session
1264
+ */
1265
+ cancelCheckoutSession(sessionId: string): Promise<ApiResponse<{
1266
+ success: boolean;
1267
+ message: string;
1268
+ }>>;
1269
+ /**
1270
+ * Expire checkout session
1271
+ */
1272
+ expireCheckoutSession(sessionId: string): Promise<ApiResponse<{
1273
+ success: boolean;
1274
+ message: string;
1275
+ }>>;
1276
+ /**
1277
+ * Get Stripe publishable key
1278
+ */
1279
+ getStripePublishableKey(): Promise<ApiResponse<{
1280
+ publishableKey: string;
1281
+ mode: 'test' | 'live';
1282
+ }>>;
1283
+ /**
1284
+ * Create payment intent (for custom checkout flows)
1285
+ */
1286
+ createPaymentIntent(data: {
1287
+ amount: number;
1288
+ currency: string;
1289
+ customerEmail?: string;
1290
+ metadata?: Record<string, string>;
1291
+ paymentMethodTypes?: string[];
1292
+ }): Promise<ApiResponse<{
1293
+ clientSecret: string;
1294
+ id: string;
1295
+ status: string;
1296
+ }>>;
1297
+ /**
1298
+ * Confirm payment intent
1299
+ */
1300
+ confirmPaymentIntent(paymentIntentId: string, data: {
1301
+ paymentMethodId: string;
1302
+ returnUrl?: string;
1303
+ }): Promise<ApiResponse<{
1304
+ success: boolean;
1305
+ status: string;
1306
+ nextAction?: any;
1307
+ }>>;
1308
+ /**
1309
+ * Get payment methods for customer
1310
+ */
1311
+ getPaymentMethods(customerId: string): Promise<ApiResponse<Array<{
1312
+ id: string;
1313
+ type: string;
1314
+ card?: {
1315
+ brand: string;
1316
+ last4: string;
1317
+ expMonth: number;
1318
+ expYear: number;
1319
+ };
1320
+ createdAt: string;
1321
+ }>>>;
1322
+ /**
1323
+ * Create customer
1324
+ */
1325
+ createCustomer(data: {
1326
+ email: string;
1327
+ name?: string;
1328
+ phone?: string;
1329
+ metadata?: Record<string, string>;
1330
+ }): Promise<ApiResponse<{
1331
+ id: string;
1332
+ email: string;
1333
+ name?: string;
1334
+ createdAt: string;
1335
+ }>>;
1336
+ /**
1337
+ * Get customer by ID
1338
+ */
1339
+ getCustomer(customerId: string): Promise<ApiResponse<{
1340
+ id: string;
1341
+ email: string;
1342
+ name?: string;
1343
+ phone?: string;
1344
+ metadata?: Record<string, string>;
1345
+ createdAt: string;
1346
+ }>>;
1347
+ /**
1348
+ * Update customer
1349
+ */
1350
+ updateCustomer(customerId: string, data: {
1351
+ email?: string;
1352
+ name?: string;
1353
+ phone?: string;
1354
+ metadata?: Record<string, string>;
1355
+ }): Promise<ApiResponse<{
1356
+ id: string;
1357
+ email: string;
1358
+ name?: string;
1359
+ updatedAt: string;
1360
+ }>>;
1361
+ /**
1362
+ * Get invoices for customer
1363
+ */
1364
+ getCustomerInvoices(customerId: string, params?: {
1365
+ page?: number;
1366
+ limit?: number;
1367
+ status?: string;
1368
+ }): Promise<ApiResponse<Array<{
1369
+ id: string;
1370
+ number: string;
1371
+ status: string;
1372
+ amountPaid: number;
1373
+ amountDue: number;
1374
+ currency: string;
1375
+ dueDate?: string;
1376
+ createdAt: string;
1377
+ }>>>;
1378
+ }
1379
+
1380
+ /**
1381
+ * Contact Forms client for PerspectAPI SDK
1382
+ */
1383
+
1384
+ declare class ContactClient extends BaseClient {
1385
+ constructor(http: any);
1386
+ /**
1387
+ * Build a contact endpoint scoped to a site (without /sites prefix)
1388
+ */
1389
+ private contactEndpoint;
1390
+ /**
1391
+ * Submit contact form
1392
+ */
1393
+ submitContact(siteName: string, data: CreateContactRequest): Promise<ApiResponse<{
1394
+ id: string;
1395
+ message: string;
1396
+ status: string;
1397
+ }>>;
1398
+ /**
1399
+ * Get contact submission status
1400
+ */
1401
+ getContactStatus(siteName: string, id: string): Promise<ApiResponse<{
1402
+ id: string;
1403
+ status: string;
1404
+ submittedAt: string;
1405
+ processedAt?: string;
1406
+ }>>;
1407
+ /**
1408
+ * Get all contact submissions (admin only)
1409
+ */
1410
+ getContactSubmissions(siteName: string, params?: {
1411
+ page?: number;
1412
+ limit?: number;
1413
+ status?: string;
1414
+ startDate?: string;
1415
+ endDate?: string;
1416
+ search?: string;
1417
+ }): Promise<PaginatedResponse<ContactSubmission>>;
1418
+ /**
1419
+ * Get contact submission by ID (admin only)
1420
+ */
1421
+ getContactSubmissionById(siteName: string, id: string): Promise<ApiResponse<ContactSubmission & {
1422
+ ipAddress?: string;
1423
+ userAgent?: string;
1424
+ metadata?: Record<string, any>;
1425
+ }>>;
1426
+ /**
1427
+ * Update contact submission status (admin only)
1428
+ */
1429
+ updateContactStatus(siteName: string, id: string, status: string, notes?: string): Promise<ApiResponse<{
1430
+ message: string;
1431
+ status: string;
1432
+ }>>;
1433
+ /**
1434
+ * Mark contact as read (admin only)
1435
+ */
1436
+ markContactAsRead(siteName: string, id: string): Promise<ApiResponse<{
1437
+ message: string;
1438
+ }>>;
1439
+ /**
1440
+ * Mark contact as unread (admin only)
1441
+ */
1442
+ markContactAsUnread(siteName: string, id: string): Promise<ApiResponse<{
1443
+ message: string;
1444
+ }>>;
1445
+ /**
1446
+ * Archive contact submission (admin only)
1447
+ */
1448
+ archiveContact(siteName: string, id: string): Promise<ApiResponse<{
1449
+ message: string;
1450
+ }>>;
1451
+ /**
1452
+ * Delete contact submission (admin only)
1453
+ */
1454
+ deleteContact(siteName: string, id: string): Promise<ApiResponse<{
1455
+ message: string;
1456
+ }>>;
1457
+ /**
1458
+ * Bulk update contact submissions (admin only)
1459
+ */
1460
+ bulkUpdateContacts(siteName: string, data: {
1461
+ ids: string[];
1462
+ status?: string;
1463
+ action: 'mark_read' | 'mark_unread' | 'archive' | 'delete';
1464
+ }): Promise<ApiResponse<{
1465
+ success: boolean;
1466
+ updatedCount: number;
1467
+ failedCount: number;
1468
+ }>>;
1469
+ /**
1470
+ * Get contact form statistics (admin only)
1471
+ */
1472
+ getContactStats(siteName: string, params?: {
1473
+ startDate?: string;
1474
+ endDate?: string;
1475
+ }): Promise<ApiResponse<{
1476
+ totalSubmissions: number;
1477
+ unreadSubmissions: number;
1478
+ readSubmissions: number;
1479
+ archivedSubmissions: number;
1480
+ submissionsByDay: Array<{
1481
+ date: string;
1482
+ count: number;
1483
+ }>;
1484
+ submissionsByStatus: Record<string, number>;
1485
+ averageResponseTime?: number;
1486
+ }>>;
1487
+ /**
1488
+ * Export contact submissions (admin only)
1489
+ */
1490
+ exportContacts(siteName: string, params?: {
1491
+ format?: 'csv' | 'json' | 'xlsx';
1492
+ startDate?: string;
1493
+ endDate?: string;
1494
+ status?: string;
1495
+ }): Promise<ApiResponse<{
1496
+ downloadUrl: string;
1497
+ expiresAt: string;
1498
+ }>>;
1499
+ /**
1500
+ * Get contact form configuration
1501
+ */
1502
+ getContactConfig(siteName: string): Promise<ApiResponse<{
1503
+ turnstileEnabled: boolean;
1504
+ rateLimitEnabled: boolean;
1505
+ rateLimitWindow: number;
1506
+ rateLimitMax: number;
1507
+ requiredFields: string[];
1508
+ customFields?: Array<{
1509
+ name: string;
1510
+ type: string;
1511
+ required: boolean;
1512
+ label: string;
1513
+ }>;
1514
+ }>>;
1515
+ /**
1516
+ * Update contact form configuration (admin only)
1517
+ */
1518
+ updateContactConfig(siteName: string, data: {
1519
+ turnstileEnabled?: boolean;
1520
+ rateLimitEnabled?: boolean;
1521
+ rateLimitWindow?: number;
1522
+ rateLimitMax?: number;
1523
+ requiredFields?: string[];
1524
+ customFields?: Array<{
1525
+ name: string;
1526
+ type: string;
1527
+ required: boolean;
1528
+ label: string;
1529
+ }>;
1530
+ }): Promise<ApiResponse<{
1531
+ message: string;
1532
+ }>>;
1533
+ }
1534
+
1535
+ /**
1536
+ * Main PerspectAPI SDK Client
1537
+ * Cloudflare Workers compatible TypeScript SDK
1538
+ */
1539
+
1540
+ declare class PerspectApiClient {
1541
+ private http;
1542
+ readonly auth: AuthClient;
1543
+ readonly content: ContentClient;
1544
+ readonly apiKeys: ApiKeysClient;
1545
+ readonly organizations: OrganizationsClient;
1546
+ readonly sites: SitesClient;
1547
+ readonly products: ProductsClient;
1548
+ readonly categories: CategoriesClient;
1549
+ readonly webhooks: WebhooksClient;
1550
+ readonly checkout: CheckoutClient;
1551
+ readonly contact: ContactClient;
1552
+ constructor(config: PerspectApiConfig);
1553
+ /**
1554
+ * Update authentication token
1555
+ */
1556
+ setAuth(jwt: string): void;
1557
+ /**
1558
+ * Update API key
1559
+ */
1560
+ setApiKey(apiKey: string): void;
1561
+ /**
1562
+ * Clear authentication
1563
+ */
1564
+ clearAuth(): void;
1565
+ /**
1566
+ * Health check endpoint
1567
+ */
1568
+ health(): Promise<ApiResponse<{
1569
+ status: string;
1570
+ timestamp: string;
1571
+ version?: string;
1572
+ uptime?: number;
1573
+ }>>;
1574
+ /**
1575
+ * Get API version info
1576
+ */
1577
+ getVersion(): Promise<ApiResponse<{
1578
+ version: string;
1579
+ buildDate: string;
1580
+ gitCommit?: string;
1581
+ }>>;
1582
+ /**
1583
+ * Get API status and statistics
1584
+ */
1585
+ getStatus(): Promise<ApiResponse<{
1586
+ status: string;
1587
+ database: {
1588
+ connected: boolean;
1589
+ latency?: number;
1590
+ };
1591
+ cache: {
1592
+ connected: boolean;
1593
+ hitRate?: number;
1594
+ };
1595
+ queues: {
1596
+ connected: boolean;
1597
+ pendingJobs?: number;
1598
+ };
1599
+ uptime: number;
1600
+ requestsPerMinute: number;
1601
+ }>>;
1602
+ /**
1603
+ * Test API connectivity and authentication
1604
+ */
1605
+ test(): Promise<ApiResponse<{
1606
+ success: boolean;
1607
+ authenticated: boolean;
1608
+ user?: {
1609
+ id: string;
1610
+ email: string;
1611
+ };
1612
+ permissions?: string[];
1613
+ timestamp: string;
1614
+ }>>;
1615
+ /**
1616
+ * Get CSRF token (for form submissions)
1617
+ * @param siteName - Optional site name for site-specific token (recommended for development)
1618
+ */
1619
+ getCsrfToken(siteName?: string): Promise<ApiResponse<{
1620
+ token?: string;
1621
+ csrf_token?: string;
1622
+ site_id?: string;
1623
+ site_name?: string;
1624
+ }>>;
1625
+ /**
1626
+ * Validate CSRF token
1627
+ */
1628
+ validateCsrfToken(token: string): Promise<ApiResponse<{
1629
+ valid: boolean;
1630
+ message?: string;
1631
+ }>>;
1632
+ }
1633
+ /**
1634
+ * Create a new PerspectAPI client instance
1635
+ */
1636
+ declare function createPerspectApiClient(config: PerspectApiConfig): PerspectApiClient;
1637
+
1638
+ /**
1639
+ * High-level data loading helpers that wrap the PerspectAPI SDK clients.
1640
+ * These helpers provide convenient product and content loading utilities with
1641
+ * graceful fallbacks that can be reused across applications.
1642
+ */
1643
+
1644
+ /**
1645
+ * Logger interface so consumers can supply custom logging behaviour (or noop).
1646
+ */
1647
+ interface LoaderLogger {
1648
+ debug?(...args: unknown[]): void;
1649
+ info?(...args: unknown[]): void;
1650
+ warn?(...args: unknown[]): void;
1651
+ error?(...args: unknown[]): void;
1652
+ }
1653
+ /**
1654
+ * Transform a PerspectAPI product payload into a friendlier shape for UI layers.
1655
+ */
1656
+ declare const transformProduct: (perspectProduct: any, logger?: LoaderLogger) => Product;
1657
+ /**
1658
+ * Transform PerspectAPI content payload to a simplified BlogPost structure.
1659
+ */
1660
+ declare const transformContent: (perspectContent: Content | (Content & Record<string, unknown>)) => BlogPost;
1661
+ interface LoaderOptions {
1662
+ /**
1663
+ * Pre-configured PerspectAPI client. Pass null/undefined to force fallback behaviour.
1664
+ */
1665
+ client?: PerspectApiClient | null;
1666
+ /**
1667
+ * Site name used for API calls and fallback data generation.
1668
+ */
1669
+ siteName: string;
1670
+ /**
1671
+ * Optional logger to capture debug/warn/error output.
1672
+ */
1673
+ logger?: LoaderLogger;
1674
+ /**
1675
+ * Optional fallback datasets.
1676
+ */
1677
+ fallbackProducts?: Product[];
1678
+ fallbackPosts?: BlogPost[];
1679
+ /**
1680
+ * Limit for list fetching (defaults to 100).
1681
+ */
1682
+ limit?: number;
1683
+ }
1684
+ interface LoadProductsOptions extends LoaderOptions {
1685
+ /**
1686
+ * Optional search term applied server-side.
1687
+ */
1688
+ search?: string;
1689
+ /**
1690
+ * Offset for manual pagination.
1691
+ */
1692
+ offset?: number;
1693
+ /**
1694
+ * Filter products by category name (case-insensitive). Accepts a single name or multiple names.
1695
+ */
1696
+ category?: string | string[];
1697
+ /**
1698
+ * Filter products by category IDs (mixed string/number values supported).
1699
+ */
1700
+ categoryIds?: Array<number | string>;
1701
+ }
1702
+ /**
1703
+ * Load products for a site with graceful fallbacks.
1704
+ */
1705
+ declare function loadProducts(options: LoadProductsOptions): Promise<Product[]>;
1706
+ interface LoadProductBySlugOptions extends LoaderOptions {
1707
+ slug: string;
1708
+ }
1709
+ /**
1710
+ * Load single product by slug.
1711
+ */
1712
+ declare function loadProductBySlug(options: LoadProductBySlugOptions): Promise<Product | null>;
1713
+ interface LoadContentOptions extends LoaderOptions {
1714
+ /**
1715
+ * Additional query parameters for content filtering.
1716
+ */
1717
+ params?: Partial<{
1718
+ page_status: string;
1719
+ page_type: string;
1720
+ limit: number;
1721
+ search: string;
1722
+ }>;
1723
+ }
1724
+ /**
1725
+ * Load published pages for a site.
1726
+ */
1727
+ declare function loadPages(options: LoadContentOptions): Promise<BlogPost[]>;
1728
+ /**
1729
+ * Load published blog posts for a site.
1730
+ */
1731
+ declare function loadPosts(options: LoadContentOptions): Promise<BlogPost[]>;
1732
+ interface LoadContentBySlugOptions extends LoaderOptions {
1733
+ slug: string;
1734
+ }
1735
+ /**
1736
+ * Load a single content item (post or page) by slug.
1737
+ */
1738
+ declare function loadContentBySlug(options: LoadContentBySlugOptions): Promise<BlogPost | null>;
1739
+ /**
1740
+ * Load all published content (pages + posts).
1741
+ */
1742
+ declare function loadAllContent(options: LoaderOptions): Promise<BlogPost[]>;
1743
+ interface CheckoutSessionOptions {
1744
+ client?: PerspectApiClient | null;
1745
+ siteName: string;
1746
+ items: Array<{
1747
+ productId: string;
1748
+ quantity: number;
1749
+ }>;
1750
+ successUrl: string;
1751
+ cancelUrl: string;
1752
+ customerEmail?: string;
1753
+ mode?: 'live' | 'test';
1754
+ logger?: LoaderLogger;
1755
+ fallbackProducts?: Product[];
1756
+ metadata?: CheckoutMetadata;
1757
+ /**
1758
+ * Optional resolver to convert a product record into a Stripe price ID.
1759
+ */
1760
+ priceIdResolver?: (product: Product, mode: 'live' | 'test') => string | undefined;
1761
+ }
1762
+ /**
1763
+ * Convenience helper that creates a checkout session by looking up Stripe price IDs
1764
+ * from product metadata. Falls back to gateway price IDs if Stripe IDs are missing.
1765
+ */
1766
+ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise<ApiResponse<CheckoutSession> | {
1767
+ error: string;
1768
+ }>;
1769
+
1770
+ export { type ApiError, type ApiKey, ApiKeysClient, type ApiResponse, AuthClient, type AuthResponse, BaseClient, type BlogPost, CategoriesClient, type Category, CheckoutClient, type CheckoutMetadata, type CheckoutMetadataValue, type CheckoutSession, type CheckoutSessionOptions, ContactClient, type ContactSubmission, type Content, ContentClient, type ContentQueryParams, type ContentStatus, type ContentType, type CreateApiKeyRequest, type CreateCategoryRequest, type CreateCheckoutSessionRequest, type CreateContactRequest, type CreateContentRequest, type CreateOrganizationRequest, type CreatePaymentGatewayRequest, type CreateProductRequest, type CreateSiteRequest, type CreateWebhookRequest, HttpClient, type HttpMethod, type LoadContentBySlugOptions, type LoadContentOptions, type LoadProductBySlugOptions, type LoadProductsOptions, type LoaderLogger, type LoaderOptions, type MediaItem, type Organization, OrganizationsClient, type PaginatedResponse, type PaginationParams, type PaymentGateway, PerspectApiClient, type PerspectApiConfig, type Product, type ProductQueryParams, ProductsClient, type RequestOptions, type SignInRequest, type SignUpRequest, type Site, SitesClient, type UpdateApiKeyRequest, type UpdateContentRequest, type User, type Webhook, WebhooksClient, createApiError, createCheckoutSession, createPerspectApiClient, PerspectApiClient as default, loadAllContent, loadContentBySlug, loadPages, loadPosts, loadProductBySlug, loadProducts, transformContent, transformProduct };