perspectapi-ts-sdk 1.3.1 → 1.4.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/dist/index.d.mts CHANGED
@@ -5,7 +5,8 @@ interface ApiResponse<T = any> {
5
5
  data?: T;
6
6
  message?: string;
7
7
  error?: string;
8
- success?: boolean;
8
+ success: boolean;
9
+ code?: string;
9
10
  }
10
11
  interface PaginationParams {
11
12
  page?: number;
@@ -141,6 +142,8 @@ interface NewsletterPreferences {
141
142
  track_clicks?: boolean;
142
143
  }
143
144
  interface NewsletterStatusResponse {
145
+ success: boolean;
146
+ code?: string;
144
147
  subscribed: boolean;
145
148
  status: string;
146
149
  frequency?: string;
@@ -148,12 +151,17 @@ interface NewsletterStatusResponse {
148
151
  confirmed_at?: string;
149
152
  }
150
153
  interface NewsletterSubscribeResponse {
154
+ success: boolean;
155
+ code: string;
151
156
  message: string;
152
157
  status: string;
153
158
  subscription_id?: string;
154
159
  }
155
160
  interface NewsletterConfirmResponse {
161
+ success: boolean;
162
+ code: string;
156
163
  message: string;
164
+ status?: string;
157
165
  subscription?: {
158
166
  email: string;
159
167
  name?: string;
@@ -165,6 +173,12 @@ interface NewsletterUnsubscribeRequest {
165
173
  email?: string;
166
174
  reason?: string;
167
175
  }
176
+ interface NewsletterUnsubscribeResponse {
177
+ success: boolean;
178
+ code: string;
179
+ message: string;
180
+ status?: string;
181
+ }
168
182
  type ContentStatus = 'draft' | 'publish' | 'private' | 'trash';
169
183
  type ContentType = 'post' | 'page';
170
184
  interface Content {
@@ -374,6 +388,22 @@ interface CreateContactRequest {
374
388
  subject?: string;
375
389
  message: string;
376
390
  }
391
+ interface ContactSubmitResponse {
392
+ success: boolean;
393
+ code: string;
394
+ contact_id: string;
395
+ message: string;
396
+ status: string;
397
+ }
398
+ interface ContactStatusResponse {
399
+ success: boolean;
400
+ code: string;
401
+ contact_id: string;
402
+ status: string;
403
+ submitted_at: string;
404
+ processed_at?: string;
405
+ metadata?: Record<string, any>;
406
+ }
377
407
  interface ApiError {
378
408
  message: string;
379
409
  code?: string;
@@ -1460,20 +1490,11 @@ declare class ContactClient extends BaseClient {
1460
1490
  * @param data - Contact form data
1461
1491
  * @param csrfToken - CSRF token (required for browser-based submissions)
1462
1492
  */
1463
- submitContact(siteName: string, data: CreateContactRequest, csrfToken?: string): Promise<ApiResponse<{
1464
- id: string;
1465
- message: string;
1466
- status: string;
1467
- }>>;
1493
+ submitContact(siteName: string, data: CreateContactRequest, csrfToken?: string): Promise<ApiResponse<ContactSubmitResponse>>;
1468
1494
  /**
1469
1495
  * Get contact submission status
1470
1496
  */
1471
- getContactStatus(siteName: string, id: string): Promise<ApiResponse<{
1472
- id: string;
1473
- status: string;
1474
- submittedAt: string;
1475
- processedAt?: string;
1476
- }>>;
1497
+ getContactStatus(siteName: string, id: string): Promise<ApiResponse<ContactStatusResponse>>;
1477
1498
  /**
1478
1499
  * Get all contact submissions (admin only)
1479
1500
  */
@@ -1627,9 +1648,7 @@ declare class NewsletterClient extends BaseClient {
1627
1648
  * @param data - Unsubscribe data
1628
1649
  * @param csrfToken - CSRF token (required for browser-based submissions)
1629
1650
  */
1630
- unsubscribe(siteName: string, data: NewsletterUnsubscribeRequest, csrfToken?: string): Promise<ApiResponse<{
1631
- message: string;
1632
- }>>;
1651
+ unsubscribe(siteName: string, data: NewsletterUnsubscribeRequest, csrfToken?: string): Promise<ApiResponse<NewsletterUnsubscribeResponse>>;
1633
1652
  /**
1634
1653
  * One-click unsubscribe via token (GET request)
1635
1654
  */
@@ -2038,4 +2057,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
2038
2057
  error: string;
2039
2058
  }>;
2040
2059
 
2041
- 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 CreateNewsletterSubscriptionRequest, 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, NewsletterClient, type NewsletterConfirmResponse, type NewsletterList, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterUnsubscribeRequest, 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 };
2060
+ 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 ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, 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, HttpClient, type HttpMethod, 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, 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 };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,8 @@ interface ApiResponse<T = any> {
5
5
  data?: T;
6
6
  message?: string;
7
7
  error?: string;
8
- success?: boolean;
8
+ success: boolean;
9
+ code?: string;
9
10
  }
10
11
  interface PaginationParams {
11
12
  page?: number;
@@ -141,6 +142,8 @@ interface NewsletterPreferences {
141
142
  track_clicks?: boolean;
142
143
  }
143
144
  interface NewsletterStatusResponse {
145
+ success: boolean;
146
+ code?: string;
144
147
  subscribed: boolean;
145
148
  status: string;
146
149
  frequency?: string;
@@ -148,12 +151,17 @@ interface NewsletterStatusResponse {
148
151
  confirmed_at?: string;
149
152
  }
150
153
  interface NewsletterSubscribeResponse {
154
+ success: boolean;
155
+ code: string;
151
156
  message: string;
152
157
  status: string;
153
158
  subscription_id?: string;
154
159
  }
155
160
  interface NewsletterConfirmResponse {
161
+ success: boolean;
162
+ code: string;
156
163
  message: string;
164
+ status?: string;
157
165
  subscription?: {
158
166
  email: string;
159
167
  name?: string;
@@ -165,6 +173,12 @@ interface NewsletterUnsubscribeRequest {
165
173
  email?: string;
166
174
  reason?: string;
167
175
  }
176
+ interface NewsletterUnsubscribeResponse {
177
+ success: boolean;
178
+ code: string;
179
+ message: string;
180
+ status?: string;
181
+ }
168
182
  type ContentStatus = 'draft' | 'publish' | 'private' | 'trash';
169
183
  type ContentType = 'post' | 'page';
170
184
  interface Content {
@@ -374,6 +388,22 @@ interface CreateContactRequest {
374
388
  subject?: string;
375
389
  message: string;
376
390
  }
391
+ interface ContactSubmitResponse {
392
+ success: boolean;
393
+ code: string;
394
+ contact_id: string;
395
+ message: string;
396
+ status: string;
397
+ }
398
+ interface ContactStatusResponse {
399
+ success: boolean;
400
+ code: string;
401
+ contact_id: string;
402
+ status: string;
403
+ submitted_at: string;
404
+ processed_at?: string;
405
+ metadata?: Record<string, any>;
406
+ }
377
407
  interface ApiError {
378
408
  message: string;
379
409
  code?: string;
@@ -1460,20 +1490,11 @@ declare class ContactClient extends BaseClient {
1460
1490
  * @param data - Contact form data
1461
1491
  * @param csrfToken - CSRF token (required for browser-based submissions)
1462
1492
  */
1463
- submitContact(siteName: string, data: CreateContactRequest, csrfToken?: string): Promise<ApiResponse<{
1464
- id: string;
1465
- message: string;
1466
- status: string;
1467
- }>>;
1493
+ submitContact(siteName: string, data: CreateContactRequest, csrfToken?: string): Promise<ApiResponse<ContactSubmitResponse>>;
1468
1494
  /**
1469
1495
  * Get contact submission status
1470
1496
  */
1471
- getContactStatus(siteName: string, id: string): Promise<ApiResponse<{
1472
- id: string;
1473
- status: string;
1474
- submittedAt: string;
1475
- processedAt?: string;
1476
- }>>;
1497
+ getContactStatus(siteName: string, id: string): Promise<ApiResponse<ContactStatusResponse>>;
1477
1498
  /**
1478
1499
  * Get all contact submissions (admin only)
1479
1500
  */
@@ -1627,9 +1648,7 @@ declare class NewsletterClient extends BaseClient {
1627
1648
  * @param data - Unsubscribe data
1628
1649
  * @param csrfToken - CSRF token (required for browser-based submissions)
1629
1650
  */
1630
- unsubscribe(siteName: string, data: NewsletterUnsubscribeRequest, csrfToken?: string): Promise<ApiResponse<{
1631
- message: string;
1632
- }>>;
1651
+ unsubscribe(siteName: string, data: NewsletterUnsubscribeRequest, csrfToken?: string): Promise<ApiResponse<NewsletterUnsubscribeResponse>>;
1633
1652
  /**
1634
1653
  * One-click unsubscribe via token (GET request)
1635
1654
  */
@@ -2038,4 +2057,4 @@ declare function createCheckoutSession(options: CheckoutSessionOptions): Promise
2038
2057
  error: string;
2039
2058
  }>;
2040
2059
 
2041
- 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 CreateNewsletterSubscriptionRequest, 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, NewsletterClient, type NewsletterConfirmResponse, type NewsletterList, type NewsletterPreferences, type NewsletterStatusResponse, type NewsletterSubscribeResponse, type NewsletterSubscription, type NewsletterUnsubscribeRequest, 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 };
2060
+ 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 ContactStatusResponse, type ContactSubmission, type ContactSubmitResponse, type Content, 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, HttpClient, type HttpMethod, 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, 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 };
package/dist/index.js CHANGED
@@ -1195,7 +1195,11 @@ var ContactClient = class extends BaseClient {
1195
1195
  if (typeof window !== "undefined" && !csrfToken) {
1196
1196
  console.warn("CSRF token recommended for browser-based contact form submissions");
1197
1197
  }
1198
- return this.create(this.contactEndpoint(siteName, "/contact/submit"), data, csrfToken);
1198
+ return this.create(
1199
+ this.contactEndpoint(siteName, "/contact/submit"),
1200
+ data,
1201
+ csrfToken
1202
+ );
1199
1203
  }
1200
1204
  /**
1201
1205
  * Get contact submission status
package/dist/index.mjs CHANGED
@@ -1144,7 +1144,11 @@ var ContactClient = class extends BaseClient {
1144
1144
  if (typeof window !== "undefined" && !csrfToken) {
1145
1145
  console.warn("CSRF token recommended for browser-based contact form submissions");
1146
1146
  }
1147
- return this.create(this.contactEndpoint(siteName, "/contact/submit"), data, csrfToken);
1147
+ return this.create(
1148
+ this.contactEndpoint(siteName, "/contact/submit"),
1149
+ data,
1150
+ csrfToken
1151
+ );
1148
1152
  }
1149
1153
  /**
1150
1154
  * Get contact submission status
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perspectapi-ts-sdk",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "TypeScript SDK for PerspectAPI - Cloudflare Workers compatible",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -6,6 +6,8 @@ import { BaseClient } from './base-client';
6
6
  import type {
7
7
  ContactSubmission,
8
8
  CreateContactRequest,
9
+ ContactSubmitResponse,
10
+ ContactStatusResponse,
9
11
  PaginatedResponse,
10
12
  ApiResponse,
11
13
  } from '../types';
@@ -32,32 +34,23 @@ export class ContactClient extends BaseClient {
32
34
  siteName: string,
33
35
  data: CreateContactRequest,
34
36
  csrfToken?: string
35
- ): Promise<ApiResponse<{
36
- id: string;
37
- message: string;
38
- status: string;
39
- }>> {
37
+ ): Promise<ApiResponse<ContactSubmitResponse>> {
40
38
  // CSRF token is required for browser submissions
41
39
  if (typeof window !== 'undefined' && !csrfToken) {
42
40
  console.warn('CSRF token recommended for browser-based contact form submissions');
43
41
  }
44
42
 
45
- return this.create<CreateContactRequest, {
46
- id: string;
47
- message: string;
48
- status: string;
49
- }>(this.contactEndpoint(siteName, '/contact/submit'), data, csrfToken);
43
+ return this.create<CreateContactRequest, ContactSubmitResponse>(
44
+ this.contactEndpoint(siteName, '/contact/submit'),
45
+ data,
46
+ csrfToken
47
+ );
50
48
  }
51
49
 
52
50
  /**
53
51
  * Get contact submission status
54
52
  */
55
- async getContactStatus(siteName: string, id: string): Promise<ApiResponse<{
56
- id: string;
57
- status: string;
58
- submittedAt: string;
59
- processedAt?: string;
60
- }>> {
53
+ async getContactStatus(siteName: string, id: string): Promise<ApiResponse<ContactStatusResponse>> {
61
54
  return this.getSingle(this.contactEndpoint(siteName, `/contact/status/${encodeURIComponent(id)}`));
62
55
  }
63
56
 
@@ -12,6 +12,7 @@ import type {
12
12
  NewsletterSubscribeResponse,
13
13
  NewsletterConfirmResponse,
14
14
  NewsletterUnsubscribeRequest,
15
+ NewsletterUnsubscribeResponse,
15
16
  PaginatedResponse,
16
17
  ApiResponse,
17
18
  } from '../types';
@@ -73,8 +74,8 @@ export class NewsletterClient extends BaseClient {
73
74
  siteName: string,
74
75
  data: NewsletterUnsubscribeRequest,
75
76
  csrfToken?: string
76
- ): Promise<ApiResponse<{ message: string }>> {
77
- return this.create<NewsletterUnsubscribeRequest, { message: string }>(
77
+ ): Promise<ApiResponse<NewsletterUnsubscribeResponse>> {
78
+ return this.create<NewsletterUnsubscribeRequest, NewsletterUnsubscribeResponse>(
78
79
  this.newsletterEndpoint(siteName, '/newsletter/unsubscribe'),
79
80
  data,
80
81
  csrfToken
package/src/index.ts CHANGED
@@ -80,4 +80,7 @@ export type {
80
80
  NewsletterSubscribeResponse,
81
81
  NewsletterConfirmResponse,
82
82
  NewsletterUnsubscribeRequest,
83
+ NewsletterUnsubscribeResponse,
84
+ ContactSubmitResponse,
85
+ ContactStatusResponse,
83
86
  } from './types';
@@ -7,7 +7,8 @@ export interface ApiResponse<T = any> {
7
7
  data?: T;
8
8
  message?: string;
9
9
  error?: string;
10
- success?: boolean;
10
+ success: boolean;
11
+ code?: string;
11
12
  }
12
13
 
13
14
  // Pagination
@@ -167,6 +168,8 @@ export interface NewsletterPreferences {
167
168
  }
168
169
 
169
170
  export interface NewsletterStatusResponse {
171
+ success: boolean;
172
+ code?: string;
170
173
  subscribed: boolean;
171
174
  status: string;
172
175
  frequency?: string;
@@ -175,13 +178,18 @@ export interface NewsletterStatusResponse {
175
178
  }
176
179
 
177
180
  export interface NewsletterSubscribeResponse {
181
+ success: boolean;
182
+ code: string;
178
183
  message: string;
179
184
  status: string;
180
185
  subscription_id?: string;
181
186
  }
182
187
 
183
188
  export interface NewsletterConfirmResponse {
189
+ success: boolean;
190
+ code: string;
184
191
  message: string;
192
+ status?: string;
185
193
  subscription?: {
186
194
  email: string;
187
195
  name?: string;
@@ -195,6 +203,13 @@ export interface NewsletterUnsubscribeRequest {
195
203
  reason?: string;
196
204
  }
197
205
 
206
+ export interface NewsletterUnsubscribeResponse {
207
+ success: boolean;
208
+ code: string;
209
+ message: string;
210
+ status?: string;
211
+ }
212
+
198
213
  // Content Management
199
214
  export type ContentStatus = 'draft' | 'publish' | 'private' | 'trash';
200
215
  export type ContentType = 'post' | 'page';
@@ -443,6 +458,24 @@ export interface CreateContactRequest {
443
458
  message: string;
444
459
  }
445
460
 
461
+ export interface ContactSubmitResponse {
462
+ success: boolean;
463
+ code: string;
464
+ contact_id: string;
465
+ message: string;
466
+ status: string;
467
+ }
468
+
469
+ export interface ContactStatusResponse {
470
+ success: boolean;
471
+ code: string;
472
+ contact_id: string;
473
+ status: string;
474
+ submitted_at: string;
475
+ processed_at?: string;
476
+ metadata?: Record<string, any>;
477
+ }
478
+
446
479
  // Error Types
447
480
  export interface ApiError {
448
481
  message: string;