perspectapi-ts-sdk 1.5.0 → 1.5.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.
package/README.md CHANGED
@@ -234,7 +234,8 @@ const content = await client.content.getContent('your-site-name', {
234
234
  page: 1,
235
235
  limit: 20,
236
236
  page_status: 'publish',
237
- page_type: 'post'
237
+ page_type: 'post',
238
+ slug_prefix: 'blog' // Optional: filter by slug prefix
238
239
  });
239
240
 
240
241
  // Get content by ID
@@ -274,7 +275,8 @@ await client.content.unpublishContent(123);
274
275
  const products = await client.products.getProducts('my-site', {
275
276
  page: 1,
276
277
  limit: 20,
277
- isActive: true
278
+ isActive: true,
279
+ slug_prefix: 'shop' // Optional: filter by slug prefix
278
280
  });
279
281
 
280
282
  // Create new product
@@ -650,6 +652,54 @@ const client = createPerspectApiClient({
650
652
  });
651
653
  ```
652
654
 
655
+ ## Slug Prefix Filtering
656
+
657
+ The SDK supports filtering content and products by `slug_prefix` to organize your content by URL structure:
658
+
659
+ ```typescript
660
+ // Filter blog posts
661
+ const blogPosts = await client.content.getContent('mysite', {
662
+ slug_prefix: 'blog', // /blog/post-1, /blog/post-2
663
+ page_status: 'publish'
664
+ });
665
+
666
+ // Filter news articles
667
+ const news = await client.content.getContent('mysite', {
668
+ slug_prefix: 'news', // /news/article-1, /news/article-2
669
+ page_status: 'publish'
670
+ });
671
+
672
+ // Filter shop products
673
+ const shopProducts = await client.products.getProducts('mysite', {
674
+ slug_prefix: 'shop', // /shop/product-1, /shop/product-2
675
+ isActive: true
676
+ });
677
+
678
+ // Filter artwork products
679
+ const artwork = await client.products.getProducts('mysite', {
680
+ slug_prefix: 'artwork', // /artwork/painting-1, /artwork/sculpture-1
681
+ isActive: true
682
+ });
683
+
684
+ // Combine with other filters
685
+ const results = await client.content.getContent('mysite', {
686
+ slug_prefix: 'blog',
687
+ page_status: 'publish',
688
+ page_type: 'post',
689
+ search: 'javascript', // Search within blog posts only
690
+ page: 1,
691
+ limit: 20
692
+ });
693
+ ```
694
+
695
+ **Use Cases:**
696
+ - Organize blog posts, news, and documentation separately
697
+ - Separate shop products from artwork or digital downloads
698
+ - Create multi-section websites with distinct URL structures
699
+ - Filter content/products by section for navigation
700
+
701
+ **See `examples/slug-prefix-examples.ts` for 20+ real-world examples!**
702
+
653
703
  ## TypeScript Support
654
704
 
655
705
  The SDK is written in TypeScript and provides comprehensive type definitions:
package/dist/index.d.mts CHANGED
@@ -188,6 +188,7 @@ interface Content {
188
188
  contentMarkdown?: string;
189
189
  custom?: Record<string, any>;
190
190
  slug?: string;
191
+ slug_prefix?: string;
191
192
  pageStatus: ContentStatus;
192
193
  pageType: ContentType;
193
194
  userId?: number;
@@ -211,6 +212,7 @@ interface ContentQueryParams extends PaginationParams {
211
212
  page_type?: ContentType;
212
213
  search?: string;
213
214
  user_id?: number;
215
+ slug_prefix?: string;
214
216
  }
215
217
  interface Category {
216
218
  id: number;
@@ -277,6 +279,7 @@ interface ProductQueryParams extends PaginationParams {
277
279
  search?: string;
278
280
  category?: string | string[];
279
281
  category_id?: number | string | Array<number | string>;
282
+ slug_prefix?: string;
280
283
  }
281
284
  interface BlogPost {
282
285
  id: string | number;
package/dist/index.d.ts CHANGED
@@ -188,6 +188,7 @@ interface Content {
188
188
  contentMarkdown?: string;
189
189
  custom?: Record<string, any>;
190
190
  slug?: string;
191
+ slug_prefix?: string;
191
192
  pageStatus: ContentStatus;
192
193
  pageType: ContentType;
193
194
  userId?: number;
@@ -211,6 +212,7 @@ interface ContentQueryParams extends PaginationParams {
211
212
  page_type?: ContentType;
212
213
  search?: string;
213
214
  user_id?: number;
215
+ slug_prefix?: string;
214
216
  }
215
217
  interface Category {
216
218
  id: number;
@@ -277,6 +279,7 @@ interface ProductQueryParams extends PaginationParams {
277
279
  search?: string;
278
280
  category?: string | string[];
279
281
  category_id?: number | string | Array<number | string>;
282
+ slug_prefix?: string;
280
283
  }
281
284
  interface BlogPost {
282
285
  id: string | number;
package/dist/index.js CHANGED
@@ -749,7 +749,10 @@ var ProductsClient = class extends BaseClient {
749
749
  delete normalizedParams.category_id;
750
750
  }
751
751
  }
752
- return this.http.get(this.buildPath(this.siteScopedEndpoint(siteName, "/products")), normalizedParams);
752
+ return this.http.get(
753
+ this.buildPath(this.siteScopedEndpoint(siteName, "/products", { includeSitesSegment: false })),
754
+ normalizedParams
755
+ );
753
756
  }
754
757
  /**
755
758
  * Get product by ID
@@ -768,7 +771,7 @@ var ProductsClient = class extends BaseClient {
768
771
  */
769
772
  async getProductBySlug(siteName, slug) {
770
773
  return this.http.get(this.buildPath(
771
- this.siteScopedEndpoint(siteName, `/products/slug/${encodeURIComponent(slug)}`)
774
+ this.siteScopedEndpoint(siteName, `/products/slug/${encodeURIComponent(slug)}`, { includeSitesSegment: false })
772
775
  ));
773
776
  }
774
777
  /**
@@ -866,7 +869,11 @@ var ProductsClient = class extends BaseClient {
866
869
  search: params.search
867
870
  } : void 0;
868
871
  return this.http.get(this.buildPath(
869
- this.siteScopedEndpoint(siteName, `/products/category/${encodeURIComponent(categorySlug)}`)
872
+ this.siteScopedEndpoint(
873
+ siteName,
874
+ `/products/category/${encodeURIComponent(categorySlug)}`,
875
+ { includeSitesSegment: false }
876
+ )
870
877
  ), queryParams);
871
878
  }
872
879
  };
package/dist/index.mjs CHANGED
@@ -691,7 +691,10 @@ var ProductsClient = class extends BaseClient {
691
691
  delete normalizedParams.category_id;
692
692
  }
693
693
  }
694
- return this.http.get(this.buildPath(this.siteScopedEndpoint(siteName, "/products")), normalizedParams);
694
+ return this.http.get(
695
+ this.buildPath(this.siteScopedEndpoint(siteName, "/products", { includeSitesSegment: false })),
696
+ normalizedParams
697
+ );
695
698
  }
696
699
  /**
697
700
  * Get product by ID
@@ -710,7 +713,7 @@ var ProductsClient = class extends BaseClient {
710
713
  */
711
714
  async getProductBySlug(siteName, slug) {
712
715
  return this.http.get(this.buildPath(
713
- this.siteScopedEndpoint(siteName, `/products/slug/${encodeURIComponent(slug)}`)
716
+ this.siteScopedEndpoint(siteName, `/products/slug/${encodeURIComponent(slug)}`, { includeSitesSegment: false })
714
717
  ));
715
718
  }
716
719
  /**
@@ -808,7 +811,11 @@ var ProductsClient = class extends BaseClient {
808
811
  search: params.search
809
812
  } : void 0;
810
813
  return this.http.get(this.buildPath(
811
- this.siteScopedEndpoint(siteName, `/products/category/${encodeURIComponent(categorySlug)}`)
814
+ this.siteScopedEndpoint(
815
+ siteName,
816
+ `/products/category/${encodeURIComponent(categorySlug)}`,
817
+ { includeSitesSegment: false }
818
+ )
812
819
  ), queryParams);
813
820
  }
814
821
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perspectapi-ts-sdk",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "TypeScript SDK for PerspectAPI - Cloudflare Workers compatible",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -50,7 +50,10 @@ export class ProductsClient extends BaseClient {
50
50
  }
51
51
  }
52
52
 
53
- return this.http.get(this.buildPath(this.siteScopedEndpoint(siteName, '/products')), normalizedParams);
53
+ return this.http.get(
54
+ this.buildPath(this.siteScopedEndpoint(siteName, '/products', { includeSitesSegment: false })),
55
+ normalizedParams
56
+ );
54
57
  }
55
58
 
56
59
  /**
@@ -72,7 +75,7 @@ export class ProductsClient extends BaseClient {
72
75
  */
73
76
  async getProductBySlug(siteName: string, slug: string): Promise<ApiResponse<Product & { variants?: any[] }>> {
74
77
  return this.http.get(this.buildPath(
75
- this.siteScopedEndpoint(siteName, `/products/slug/${encodeURIComponent(slug)}`)
78
+ this.siteScopedEndpoint(siteName, `/products/slug/${encodeURIComponent(slug)}`, { includeSitesSegment: false })
76
79
  ));
77
80
  }
78
81
 
@@ -241,7 +244,11 @@ export class ProductsClient extends BaseClient {
241
244
  } : undefined;
242
245
 
243
246
  return this.http.get(this.buildPath(
244
- this.siteScopedEndpoint(siteName, `/products/category/${encodeURIComponent(categorySlug)}`)
247
+ this.siteScopedEndpoint(
248
+ siteName,
249
+ `/products/category/${encodeURIComponent(categorySlug)}`,
250
+ { includeSitesSegment: false }
251
+ )
245
252
  ), queryParams);
246
253
  }
247
254
  }
@@ -221,6 +221,7 @@ export interface Content {
221
221
  contentMarkdown?: string;
222
222
  custom?: Record<string, any>;
223
223
  slug?: string;
224
+ slug_prefix?: string;
224
225
  pageStatus: ContentStatus;
225
226
  pageType: ContentType;
226
227
  userId?: number;
@@ -246,6 +247,7 @@ export interface ContentQueryParams extends PaginationParams {
246
247
  page_type?: ContentType;
247
248
  search?: string;
248
249
  user_id?: number;
250
+ slug_prefix?: string;
249
251
  }
250
252
 
251
253
  // Categories
@@ -320,6 +322,7 @@ export interface ProductQueryParams extends PaginationParams {
320
322
  search?: string;
321
323
  category?: string | string[];
322
324
  category_id?: number | string | Array<number | string>;
325
+ slug_prefix?: string;
323
326
  }
324
327
 
325
328
  export interface BlogPost {