perspectapi-ts-sdk 6.5.9 → 7.0.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.
Files changed (57) hide show
  1. package/README.md +46 -1011
  2. package/dist/chunk-MZ22HQBX.mjs +1451 -0
  3. package/dist/index-BL9-AZpq.d.mts +2227 -0
  4. package/dist/index-BL9-AZpq.d.ts +2227 -0
  5. package/dist/index.d.mts +130 -2221
  6. package/dist/index.d.ts +130 -2221
  7. package/dist/index.js +71 -7
  8. package/dist/index.mjs +13 -1364
  9. package/dist/v2/index.d.mts +1 -0
  10. package/dist/v2/index.d.ts +1 -0
  11. package/dist/v2/index.js +1477 -0
  12. package/dist/v2/index.mjs +40 -0
  13. package/docs/README.md +15 -0
  14. package/docs/v1-deprecated/README.md +9 -0
  15. package/docs/v1-deprecated/examples/README.md +324 -0
  16. package/docs/v1-deprecated/examples/basic-usage.ts +258 -0
  17. package/docs/v1-deprecated/examples/cloudflare-worker.ts +274 -0
  18. package/docs/v1-deprecated/examples/content-query-with-slug-prefix.ts +237 -0
  19. package/docs/v1-deprecated/examples/image-transforms.ts +200 -0
  20. package/docs/v1-deprecated/examples/site-user-checkout.ts +186 -0
  21. package/docs/v1-deprecated/examples/slug-prefix-examples.ts +491 -0
  22. package/docs/v1-deprecated/legacy-docs/caching.md +667 -0
  23. package/docs/v1-deprecated/legacy-docs/contact.md +1396 -0
  24. package/docs/v1-deprecated/legacy-docs/csrf-protection.md +664 -0
  25. package/docs/v1-deprecated/legacy-docs/image-transforms.md +523 -0
  26. package/docs/v1-deprecated/legacy-docs/loaders.md +304 -0
  27. package/docs/v1-deprecated/legacy-docs/newsletter.md +811 -0
  28. package/docs/v1-deprecated/legacy-docs/site-users.md +817 -0
  29. package/docs/v1-deprecated/legacy-notes/CHANGELOG-CHECKOUT.md +143 -0
  30. package/docs/v1-deprecated/legacy-notes/CSRF-CHECKOUT.md +271 -0
  31. package/docs/v1-deprecated/legacy-notes/IMAGE_TRANSFORMS_PORT.md +298 -0
  32. package/docs/v1-deprecated/sdk-readme.md +1076 -0
  33. package/examples/README.md +19 -0
  34. package/examples/basic-v2.ts +37 -0
  35. package/llms.txt +25 -0
  36. package/package.json +18 -7
  37. package/src/client/api-keys-client.ts +4 -0
  38. package/src/client/auth-client.ts +4 -0
  39. package/src/client/base-client.ts +7 -0
  40. package/src/client/bundles-client.ts +4 -0
  41. package/src/client/categories-client.ts +4 -0
  42. package/src/client/checkout-client.ts +4 -0
  43. package/src/client/contact-client.ts +4 -0
  44. package/src/client/content-client.ts +4 -0
  45. package/src/client/newsletter-client.ts +4 -0
  46. package/src/client/newsletter-management-client.ts +4 -0
  47. package/src/client/organizations-client.ts +4 -0
  48. package/src/client/products-client.ts +4 -0
  49. package/src/client/site-users-client.ts +10 -1
  50. package/src/client/sites-client.ts +4 -0
  51. package/src/client/webhooks-client.ts +4 -0
  52. package/src/deprecation.ts +2 -1
  53. package/src/index.ts +2 -1
  54. package/src/loaders.ts +59 -0
  55. package/src/perspect-api-client.ts +2 -2
  56. package/src/v2/client/orders-client.ts +89 -6
  57. package/src/v2/types.ts +3 -0
@@ -0,0 +1,40 @@
1
+ import {
2
+ ApiKeysV2Client,
3
+ BaseV2Client,
4
+ CategoriesV2Client,
5
+ CollectionsV2Client,
6
+ ContactsV2Client,
7
+ ContentV2Client,
8
+ CreditsV2Client,
9
+ NewsletterV2Client,
10
+ OrdersV2Client,
11
+ OrganizationsV2Client,
12
+ PerspectApiV2Client,
13
+ PerspectV2Error,
14
+ ProductsV2Client,
15
+ SiteUsersV2Client,
16
+ SitesV2Client,
17
+ SubscriptionsV2Client,
18
+ WebhooksV2Client,
19
+ createPerspectApiV2Client
20
+ } from "../chunk-MZ22HQBX.mjs";
21
+ export {
22
+ ApiKeysV2Client,
23
+ BaseV2Client,
24
+ CategoriesV2Client,
25
+ CollectionsV2Client,
26
+ ContactsV2Client,
27
+ ContentV2Client,
28
+ CreditsV2Client,
29
+ NewsletterV2Client,
30
+ OrdersV2Client,
31
+ OrganizationsV2Client,
32
+ PerspectApiV2Client,
33
+ PerspectV2Error,
34
+ ProductsV2Client,
35
+ SiteUsersV2Client,
36
+ SitesV2Client,
37
+ SubscriptionsV2Client,
38
+ WebhooksV2Client,
39
+ createPerspectApiV2Client
40
+ };
package/docs/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # PerspectAPI SDK Docs
2
+
3
+ The current SDK and REST API surface is v2.
4
+
5
+ Use:
6
+
7
+ ```typescript
8
+ import { createPerspectApiV2Client } from 'perspectapi-ts-sdk/v2';
9
+ ```
10
+
11
+ Do not use `/api/v1`, `PerspectApiClient`, `createPerspectApiClient`, or
12
+ `src/client/*` for new code. v1 sunsets on **2026-06-01**.
13
+
14
+ Historical v1 material lives under [v1-deprecated](./v1-deprecated/) for
15
+ migration reference only.
@@ -0,0 +1,9 @@
1
+ # Deprecated v1 Material
2
+
3
+ This directory contains historical v1 SDK docs, examples, and migration notes.
4
+
5
+ Do not copy these examples into new code. v1 (`/api/v1`, `PerspectApiClient`,
6
+ `createPerspectApiClient`, and `src/client/*`) sunsets on **2026-06-01**.
7
+
8
+ Use `createPerspectApiV2Client` from `perspectapi-ts-sdk/v2` and `/api/v2`
9
+ for all new integrations.
@@ -0,0 +1,324 @@
1
+ # PerspectAPI SDK Examples
2
+
3
+ These are historical v1 examples kept for migration reference only.
4
+
5
+ Do not copy these examples into new code. v1 (`/api/v1`, `PerspectApiClient`,
6
+ `createPerspectApiClient`, and `src/client/*`) sunsets on **2026-06-01**. New
7
+ integrations must use `createPerspectApiV2Client` from `perspectapi-ts-sdk/v2`
8
+ and `/api/v2`.
9
+
10
+ This directory contains practical examples of how the deprecated v1 PerspectAPI
11
+ TypeScript SDK was used in different environments and scenarios.
12
+
13
+ ## Examples
14
+
15
+ ### 1. Image Transformations (`image-transforms.ts`)
16
+
17
+ Demonstrates how to transform images using Cloudflare Image Resizing:
18
+ - Transform product images to multiple sizes
19
+ - Custom transformations (resize, crop, format)
20
+ - Generate responsive images with srcset
21
+ - High DPR (Retina) support
22
+ - React component examples
23
+
24
+ **Run:**
25
+ ```bash
26
+ npx tsx docs/v1-deprecated/examples/image-transforms.ts
27
+ ```
28
+
29
+ **Key features:**
30
+ - `transformMediaItem()` - Transform MediaItem objects
31
+ - `buildImageUrl()` - Custom transformations
32
+ - `generateResponsiveUrls()` - Multiple sizes at once
33
+ - `generateSrcSet()` - For responsive images
34
+ - `generateResponsiveImageHtml()` - Complete HTML generation
35
+
36
+ ### 2. Basic Usage (`basic-usage.ts`)
37
+
38
+ Comprehensive example showing all major SDK features:
39
+ - Authentication and user management
40
+ - Content management (CRUD operations)
41
+ - Product management
42
+ - Organization and site management
43
+ - API key management
44
+ - Categories
45
+ - Contact forms
46
+ - Webhooks
47
+
48
+ **Run the example:**
49
+ ```bash
50
+ # Install dependencies
51
+ npm install
52
+
53
+ # Set environment variables
54
+ export PERSPECT_API_URL="https://your-api-instance.com"
55
+ export PERSPECT_API_KEY="your-api-key"
56
+
57
+ # Run the deprecated v1 example
58
+ npx tsx docs/v1-deprecated/examples/basic-usage.ts
59
+ ```
60
+
61
+ ### 2. Cloudflare Worker (`cloudflare-worker.ts`)
62
+
63
+ Complete Cloudflare Worker implementation demonstrating:
64
+ - SDK initialization in Workers environment
65
+ - Request routing and handling
66
+ - Error handling for edge environments
67
+ - Optimized timeout and retry settings
68
+ - JSON API responses
69
+
70
+ **Deploy to Cloudflare Workers:**
71
+ ```bash
72
+ # Install Wrangler CLI
73
+ npm install -g wrangler
74
+
75
+ # Create wrangler.toml
76
+ cat > wrangler.toml << EOF
77
+ name = "perspectapi-sdk-demo"
78
+ main = "docs/v1-deprecated/examples/cloudflare-worker.ts"
79
+ compatibility_date = "2024-01-01"
80
+
81
+ [vars]
82
+ PERSPECT_API_URL = "https://your-api-instance.com"
83
+
84
+ [[env.production.vars]]
85
+ PERSPECT_API_KEY = "your-production-api-key"
86
+ EOF
87
+
88
+ # Deploy
89
+ wrangler deploy
90
+ ```
91
+
92
+ ## Environment Variables
93
+
94
+ All examples require these environment variables:
95
+
96
+ ```bash
97
+ # Required
98
+ PERSPECT_API_URL="https://your-perspectapi-instance.com"
99
+ PERSPECT_SITE_NAME="your-site-name"
100
+
101
+ # Authentication (choose one)
102
+ PERSPECT_API_KEY="pk_your_api_key_here"
103
+ # OR
104
+ PERSPECT_JWT_TOKEN="your.jwt.token"
105
+
106
+ # Optional
107
+ PERSPECT_TIMEOUT="30000" # Request timeout in milliseconds
108
+ PERSPECT_RETRIES="3" # Number of retry attempts
109
+ ```
110
+
111
+ > **Note:** Site-scoped endpoints (content, products, contact) require a site name. In the snippets below, assume `const siteName = process.env.PERSPECT_SITE_NAME || 'your-site-name';`.
112
+
113
+ ## Common Patterns
114
+
115
+ ### Error Handling
116
+
117
+ ```typescript
118
+ import { createApiError } from 'perspectapi-ts-sdk';
119
+
120
+ try {
121
+ const content = await client.content.getContent();
122
+ console.log(content.data);
123
+ } catch (error) {
124
+ const apiError = createApiError(error);
125
+
126
+ if (apiError.status === 401) {
127
+ console.log('Authentication required');
128
+ } else if (apiError.status === 429) {
129
+ console.log('Rate limited, retry later');
130
+ } else {
131
+ console.error('API Error:', apiError.message);
132
+ }
133
+ }
134
+ ```
135
+
136
+ ### Pagination
137
+
138
+ ```typescript
139
+ // Get all content with pagination
140
+ let page = 1;
141
+ const allContent = [];
142
+
143
+ while (true) {
144
+ const response = await client.content.getContent({
145
+ page,
146
+ limit: 50,
147
+ page_status: 'publish'
148
+ });
149
+
150
+ if (!response.data || response.data.length === 0) {
151
+ break;
152
+ }
153
+
154
+ allContent.push(...response.data);
155
+ page++;
156
+
157
+ // Check if we've reached the last page
158
+ if (response.pagination && page > response.pagination.totalPages) {
159
+ break;
160
+ }
161
+ }
162
+
163
+ console.log(`Total content items: ${allContent.length}`);
164
+ ```
165
+
166
+ ### Batch Operations
167
+
168
+ ```typescript
169
+ // Create multiple products
170
+ const products = [
171
+ { name: 'Product 1', price: 29.99, currency: 'USD' },
172
+ { name: 'Product 2', price: 39.99, currency: 'USD' },
173
+ { name: 'Product 3', price: 49.99, currency: 'USD' }
174
+ ];
175
+
176
+ const createdProducts = await Promise.all(
177
+ products.map(product => client.products.createProduct(product))
178
+ );
179
+
180
+ console.log(`Created ${createdProducts.length} products`);
181
+ ```
182
+
183
+ ### Dynamic Authentication
184
+
185
+ ```typescript
186
+ // Initialize without auth
187
+ const client = createPerspectApiClient({
188
+ baseUrl: 'https://api.example.com'
189
+ });
190
+
191
+ // Authenticate user
192
+ const authResult = await client.auth.signIn({
193
+ email: 'user@example.com',
194
+ password: 'password'
195
+ });
196
+
197
+ // SDK automatically updates auth headers
198
+ console.log('Authenticated as:', authResult.data?.user?.email);
199
+
200
+ // Or manually set auth
201
+ client.setAuth('your-jwt-token');
202
+ client.setApiKey('your-api-key');
203
+
204
+ // Clear auth when done
205
+ client.clearAuth();
206
+ ```
207
+
208
+ ### Webhook Processing
209
+
210
+ ```typescript
211
+ // Create webhook for Stripe events
212
+ const webhook = await client.webhooks.createWebhook({
213
+ name: 'Stripe Payment Events',
214
+ url: 'https://myapp.com/webhooks/stripe',
215
+ provider: 'stripe',
216
+ events: [
217
+ 'payment_intent.succeeded',
218
+ 'payment_intent.payment_failed',
219
+ 'customer.subscription.created'
220
+ ],
221
+ isActive: true
222
+ });
223
+
224
+ console.log('Webhook created:', webhook.data.id);
225
+
226
+ // Test the webhook
227
+ const testResult = await client.webhooks.testWebhook(webhook.data.id);
228
+ console.log('Test result:', testResult.data);
229
+
230
+ // Get webhook events
231
+ const events = await client.webhooks.getWebhookEvents(webhook.data.id, {
232
+ status: 'failed',
233
+ limit: 10
234
+ });
235
+
236
+ console.log('Failed events:', events.data);
237
+ ```
238
+
239
+ ## Best Practices
240
+
241
+ ### 1. Environment-Specific Configuration
242
+
243
+ ```typescript
244
+ const config = {
245
+ baseUrl: process.env.PERSPECT_API_URL!,
246
+ apiKey: process.env.PERSPECT_API_KEY,
247
+ timeout: process.env.NODE_ENV === 'production' ? 30000 : 60000,
248
+ retries: process.env.NODE_ENV === 'production' ? 3 : 1
249
+ };
250
+
251
+ const client = createPerspectApiClient(config);
252
+ ```
253
+
254
+ ### 2. Graceful Degradation
255
+
256
+ ```typescript
257
+ async function getContentSafely() {
258
+ try {
259
+ const content = await client.content.getContent({ limit: 10 });
260
+ return content.data || [];
261
+ } catch (error) {
262
+ console.warn('Failed to fetch content, using fallback');
263
+ return []; // Return empty array as fallback
264
+ }
265
+ }
266
+ ```
267
+
268
+ ### 3. Caching Responses
269
+
270
+ ```typescript
271
+ const cache = new Map();
272
+
273
+ async function getCachedContent(cacheKey: string) {
274
+ if (cache.has(cacheKey)) {
275
+ return cache.get(cacheKey);
276
+ }
277
+
278
+ const content = await client.content.getContent();
279
+ cache.set(cacheKey, content.data);
280
+
281
+ // Clear cache after 5 minutes
282
+ setTimeout(() => cache.delete(cacheKey), 5 * 60 * 1000);
283
+
284
+ return content.data;
285
+ }
286
+ ```
287
+
288
+ ### 4. Rate Limit Handling
289
+
290
+ ```typescript
291
+ async function withRateLimit<T>(operation: () => Promise<T>): Promise<T> {
292
+ try {
293
+ return await operation();
294
+ } catch (error) {
295
+ const apiError = createApiError(error);
296
+
297
+ if (apiError.status === 429) {
298
+ // Wait and retry after rate limit
299
+ const retryAfter = parseInt(apiError.details?.headers?.['retry-after'] || '60');
300
+ console.log(`Rate limited, waiting ${retryAfter} seconds...`);
301
+
302
+ await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
303
+ return await operation();
304
+ }
305
+
306
+ throw error;
307
+ }
308
+ }
309
+
310
+ // Usage
311
+ const content = await withRateLimit(() =>
312
+ client.content.getContent({ limit: 100 })
313
+ );
314
+ ```
315
+
316
+ ## Testing
317
+
318
+ Each example includes basic error handling and logging to help you understand the SDK behavior. For production use, implement proper error handling, logging, and monitoring based on your application's requirements.
319
+
320
+ ## Need Help?
321
+
322
+ - 📖 [Main Documentation](../README.md)
323
+ - 🐛 [Report Issues](https://github.com/perspectapi/perspectapi-ts-sdk/issues)
324
+ - 💬 [Discussions](https://github.com/perspectapi/perspectapi-ts-sdk/discussions)
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Basic usage examples for PerspectAPI TypeScript SDK
3
+ *
4
+ * @deprecated Historical v1 example. Do not copy into new code. v1 sunsets on
5
+ * 2026-06-01; use createPerspectApiV2Client from perspectapi-ts-sdk/v2.
6
+ */
7
+
8
+ import { createPerspectApiClient } from '../../../src';
9
+
10
+ // Initialize client
11
+ const client = createPerspectApiClient({
12
+ baseUrl: 'https://your-perspectapi-instance.com',
13
+ apiKey: 'your-api-key'
14
+ });
15
+
16
+ async function basicExamples() {
17
+ try {
18
+ // 1. Health check
19
+ console.log('=== Health Check ===');
20
+ const health = await client.health();
21
+ console.log('API Status:', health.data);
22
+ const siteName = 'your-site-name';
23
+
24
+ // 2. Admin authentication (OTP-based, see site-user-checkout.ts for site user auth)
25
+ console.log('\n=== Authentication ===');
26
+ const csrfToken = await client.getCsrfToken();
27
+ console.log('CSRF token:', csrfToken.data);
28
+
29
+ // After OTP verification, set the JWT token:
30
+ // client.setAuth(jwtToken);
31
+
32
+ // 3. Get admin user profile (requires JWT)
33
+ // const profile = await client.auth.getUserProfile();
34
+ // console.log('User profile:', profile.data);
35
+
36
+ // 4. Content management
37
+ console.log('\n=== Content Management ===');
38
+
39
+ // Get all content
40
+ const content = await client.content.getContent(siteName, {
41
+ page: 1,
42
+ limit: 5,
43
+ page_status: 'publish'
44
+ });
45
+ console.log('Published content:', content.data?.length, 'items');
46
+
47
+ // Create new content
48
+ const newContent = await client.content.createContent({
49
+ page_title: 'SDK Test Post',
50
+ page_content: '<p>This post was created using the TypeScript SDK!</p>',
51
+ content_markdown: '# SDK Test Post\n\nThis post was created using the TypeScript SDK!',
52
+ page_status: 'draft',
53
+ page_type: 'post',
54
+ slug: 'sdk-test-post'
55
+ });
56
+ console.log('Created content:', newContent.data?.id);
57
+
58
+ // Update content
59
+ if (newContent.data?.id) {
60
+ const updated = await client.content.updateContent(newContent.data.id, {
61
+ page_status: 'publish'
62
+ });
63
+ console.log('Published content:', updated.data?.pageTitle);
64
+ }
65
+
66
+ // Get individual content by slug (SEO-friendly)
67
+ try {
68
+ const blogPost = await client.content.getContentBySlug(siteName, 'sdk-test-post');
69
+ console.log('Retrieved by slug:', blogPost.data?.pageTitle);
70
+ console.log('Post type:', blogPost.data?.pageType);
71
+ console.log('Status:', blogPost.data?.pageStatus);
72
+ } catch (error) {
73
+ console.log('Content slug not found');
74
+ }
75
+
76
+ // Get content by ID
77
+ try {
78
+ const pageById = await client.content.getContentById(1);
79
+ console.log('Retrieved by ID:', pageById.data?.pageTitle);
80
+ } catch (error) {
81
+ console.log('Content ID not found');
82
+ }
83
+
84
+ // 5. Products
85
+ console.log('\n=== Products ===');
86
+
87
+ // Get products
88
+ const products = await client.products.getProducts(siteName, {
89
+ page: 1,
90
+ limit: 5,
91
+ isActive: true
92
+ });
93
+ console.log('Active products:', products.data?.length, 'items');
94
+
95
+ // Create new product
96
+ const newProduct = await client.products.createProduct({
97
+ name: 'SDK Test Product',
98
+ description: 'A product created via the TypeScript SDK',
99
+ price: 29.99,
100
+ currency: 'USD',
101
+ sku: 'SDK-TEST-001',
102
+ isActive: true
103
+ });
104
+ console.log('Created product:', newProduct.data?.name);
105
+
106
+ // Get individual product by ID
107
+ try {
108
+ const singleProduct = await client.products.getProductById(123);
109
+ console.log('Product details:', singleProduct.data?.name);
110
+ console.log('Price:', singleProduct.data?.price);
111
+ } catch (error) {
112
+ console.log('Product not found');
113
+ }
114
+
115
+ // Get product by SKU
116
+ try {
117
+ const productBySku = await client.products.getProductBySku('PROD-001');
118
+ console.log('Product by SKU:', productBySku.data?.name);
119
+ } catch (error) {
120
+ console.log('Product SKU not found');
121
+ }
122
+
123
+ // Get product by slug and site name (NEW!)
124
+ try {
125
+ const productBySlug = await client.products.getProductBySlug(siteName, 'awesome-product');
126
+ console.log('Product by slug:', productBySlug.data?.name);
127
+ console.log('Product variants:', productBySlug.data?.variants?.length);
128
+ } catch (error) {
129
+ console.log('Product slug not found');
130
+ }
131
+
132
+ // Get products by category slug (new feature)
133
+ try {
134
+ const categoryProducts = await client.products.getProductsByCategorySlug(
135
+ siteName,
136
+ 'electronics',
137
+ {
138
+ page: 1,
139
+ limit: 10,
140
+ published: true
141
+ }
142
+ );
143
+ console.log('Products in electronics category:', categoryProducts.data?.data.length);
144
+ console.log('Category info:', categoryProducts.data?.category);
145
+ } catch (error) {
146
+ console.log('No electronics category found or no products in category');
147
+ }
148
+
149
+ // 6. Organizations and Sites
150
+ console.log('\n=== Organizations & Sites ===');
151
+
152
+ // Get organizations
153
+ const orgs = await client.organizations.getOrganizations();
154
+ console.log('Organizations:', orgs.data?.length, 'found');
155
+
156
+ // Get sites
157
+ const sites = await client.sites.getSites();
158
+ console.log('Sites:', sites.data?.length, 'found');
159
+
160
+ // 7. API Keys
161
+ console.log('\n=== API Keys ===');
162
+
163
+ // Get API keys
164
+ const apiKeys = await client.apiKeys.getApiKeys();
165
+ console.log('API Keys:', apiKeys.data?.length, 'found');
166
+
167
+ // Create new API key
168
+ const newApiKey = await client.apiKeys.createApiKey({
169
+ name: 'SDK Test Key',
170
+ description: 'API key created via TypeScript SDK',
171
+ permissions: ['content:read', 'products:read']
172
+ });
173
+ console.log('Created API key:', newApiKey.data?.name);
174
+ console.log('Key value:', newApiKey.data?.key);
175
+
176
+ // 8. Categories
177
+ console.log('\n=== Categories ===');
178
+
179
+ // Get categories
180
+ const categories = await client.categories.getCategories();
181
+ console.log('Categories:', categories.data?.length, 'found');
182
+
183
+ // Create new category
184
+ const newCategory = await client.categories.createCategory({
185
+ name: 'SDK Test Category',
186
+ slug: 'sdk-test-category',
187
+ description: 'A category created via the TypeScript SDK'
188
+ });
189
+ console.log('Created category:', newCategory.data?.name);
190
+
191
+ // Get product category by slug (NEW!)
192
+ try {
193
+ const productCategory = await client.categories.getProductCategoryBySlug(siteName, 'electronics');
194
+ console.log('Product category by slug:', productCategory.data?.name);
195
+ } catch (error) {
196
+ console.log('Product category slug not found');
197
+ }
198
+
199
+ // 9. Contact form submission
200
+ console.log('\n=== Contact Form ===');
201
+
202
+ const contactSubmission = await client.contact.submitContact(siteName, {
203
+ name: 'SDK Test User',
204
+ email: 'test@example.com',
205
+ subject: 'SDK Test Message',
206
+ message: 'This is a test message submitted via the TypeScript SDK.'
207
+ });
208
+ console.log('Contact submitted:', contactSubmission.data?.id);
209
+
210
+ // 10. Webhooks
211
+ console.log('\n=== Webhooks ===');
212
+
213
+ // Get webhooks
214
+ const webhooks = await client.webhooks.getWebhooks();
215
+ console.log('Webhooks:', webhooks.data?.length, 'found');
216
+
217
+ // Get supported providers
218
+ const providers = await client.webhooks.getWebhookProviders();
219
+ console.log('Supported providers:', providers.data?.map(p => p.name).join(', '));
220
+
221
+ // 11. Checkout & Payments
222
+ console.log('\n=== Checkout & Payments ===');
223
+
224
+ // Create checkout session
225
+ try {
226
+ const checkoutSession = await client.checkout.createCheckoutSession({
227
+ priceId: 'price_test_123',
228
+ successUrl: 'https://example.com/success',
229
+ cancelUrl: 'https://example.com/cancel',
230
+ customerEmail: 'customer@example.com'
231
+ });
232
+ console.log('Checkout session created:', checkoutSession.data?.id);
233
+ console.log('Checkout URL:', checkoutSession.data?.url);
234
+ } catch (error) {
235
+ console.log('Failed to create checkout session');
236
+ }
237
+
238
+ // Get Stripe configuration
239
+ try {
240
+ const stripeConfig = await client.checkout.getStripePublishableKey();
241
+ console.log('Stripe mode:', stripeConfig.data?.mode);
242
+ } catch (error) {
243
+ console.log('Stripe not configured');
244
+ }
245
+
246
+ console.log('\n=== All examples completed successfully! ===');
247
+
248
+ } catch (error) {
249
+ console.error('Error in examples:', error);
250
+ }
251
+ }
252
+
253
+ // Run examples
254
+ if (require.main === module) {
255
+ basicExamples();
256
+ }
257
+
258
+ export { basicExamples };