perspectapi-ts-sdk 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -2
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +16 -5
- package/dist/index.mjs +16 -5
- package/package.json +1 -1
- package/src/client/categories-client.ts +5 -1
- package/src/client/checkout-client.ts +1 -1
- package/src/client/products-client.ts +10 -3
- package/src/types/index.ts +3 -0
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(
|
|
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(
|
|
872
|
+
this.siteScopedEndpoint(
|
|
873
|
+
siteName,
|
|
874
|
+
`/products/category/${encodeURIComponent(categorySlug)}`,
|
|
875
|
+
{ includeSitesSegment: false }
|
|
876
|
+
)
|
|
870
877
|
), queryParams);
|
|
871
878
|
}
|
|
872
879
|
};
|
|
@@ -899,7 +906,11 @@ var CategoriesClient = class extends BaseClient {
|
|
|
899
906
|
*/
|
|
900
907
|
async getProductCategoryBySlug(siteName, slug) {
|
|
901
908
|
return this.http.get(this.buildPath(
|
|
902
|
-
this.siteScopedEndpoint(
|
|
909
|
+
this.siteScopedEndpoint(
|
|
910
|
+
siteName,
|
|
911
|
+
`/product_category/slug/${encodeURIComponent(slug)}`,
|
|
912
|
+
{ includeSitesSegment: false }
|
|
913
|
+
)
|
|
903
914
|
));
|
|
904
915
|
}
|
|
905
916
|
/**
|
|
@@ -1098,7 +1109,7 @@ var CheckoutClient = class extends BaseClient {
|
|
|
1098
1109
|
token = csrfToken2;
|
|
1099
1110
|
}
|
|
1100
1111
|
return this.http.request(this.buildPath(
|
|
1101
|
-
this.siteScopedEndpoint(siteName, "/checkout/create-session")
|
|
1112
|
+
this.siteScopedEndpoint(siteName, "/checkout/create-session", { includeSitesSegment: false })
|
|
1102
1113
|
), {
|
|
1103
1114
|
method: "POST",
|
|
1104
1115
|
body: data,
|
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(
|
|
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(
|
|
814
|
+
this.siteScopedEndpoint(
|
|
815
|
+
siteName,
|
|
816
|
+
`/products/category/${encodeURIComponent(categorySlug)}`,
|
|
817
|
+
{ includeSitesSegment: false }
|
|
818
|
+
)
|
|
812
819
|
), queryParams);
|
|
813
820
|
}
|
|
814
821
|
};
|
|
@@ -841,7 +848,11 @@ var CategoriesClient = class extends BaseClient {
|
|
|
841
848
|
*/
|
|
842
849
|
async getProductCategoryBySlug(siteName, slug) {
|
|
843
850
|
return this.http.get(this.buildPath(
|
|
844
|
-
this.siteScopedEndpoint(
|
|
851
|
+
this.siteScopedEndpoint(
|
|
852
|
+
siteName,
|
|
853
|
+
`/product_category/slug/${encodeURIComponent(slug)}`,
|
|
854
|
+
{ includeSitesSegment: false }
|
|
855
|
+
)
|
|
845
856
|
));
|
|
846
857
|
}
|
|
847
858
|
/**
|
|
@@ -1040,7 +1051,7 @@ var CheckoutClient = class extends BaseClient {
|
|
|
1040
1051
|
token = csrfToken2;
|
|
1041
1052
|
}
|
|
1042
1053
|
return this.http.request(this.buildPath(
|
|
1043
|
-
this.siteScopedEndpoint(siteName, "/checkout/create-session")
|
|
1054
|
+
this.siteScopedEndpoint(siteName, "/checkout/create-session", { includeSitesSegment: false })
|
|
1044
1055
|
), {
|
|
1045
1056
|
method: "POST",
|
|
1046
1057
|
body: data,
|
package/package.json
CHANGED
|
@@ -46,7 +46,11 @@ export class CategoriesClient extends BaseClient {
|
|
|
46
46
|
*/
|
|
47
47
|
async getProductCategoryBySlug(siteName: string, slug: string): Promise<ApiResponse<Category>> {
|
|
48
48
|
return this.http.get(this.buildPath(
|
|
49
|
-
this.siteScopedEndpoint(
|
|
49
|
+
this.siteScopedEndpoint(
|
|
50
|
+
siteName,
|
|
51
|
+
`/product_category/slug/${encodeURIComponent(slug)}`,
|
|
52
|
+
{ includeSitesSegment: false }
|
|
53
|
+
)
|
|
50
54
|
));
|
|
51
55
|
}
|
|
52
56
|
|
|
@@ -52,7 +52,7 @@ export class CheckoutClient extends BaseClient {
|
|
|
52
52
|
|
|
53
53
|
// Make the checkout request with CSRF token in headers
|
|
54
54
|
return this.http.request(this.buildPath(
|
|
55
|
-
this.siteScopedEndpoint(siteName, '/checkout/create-session')
|
|
55
|
+
this.siteScopedEndpoint(siteName, '/checkout/create-session', { includeSitesSegment: false })
|
|
56
56
|
), {
|
|
57
57
|
method: 'POST',
|
|
58
58
|
body: data,
|
|
@@ -50,7 +50,10 @@ export class ProductsClient extends BaseClient {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
return this.http.get(
|
|
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(
|
|
247
|
+
this.siteScopedEndpoint(
|
|
248
|
+
siteName,
|
|
249
|
+
`/products/category/${encodeURIComponent(categorySlug)}`,
|
|
250
|
+
{ includeSitesSegment: false }
|
|
251
|
+
)
|
|
245
252
|
), queryParams);
|
|
246
253
|
}
|
|
247
254
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -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 {
|