@putiikkipalvelu/storefront-sdk 0.11.1 → 0.12.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.cjs +74 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +162 -1
- package/dist/index.d.ts +162 -1
- package/dist/index.js +74 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1849,6 +1849,78 @@ function createWithdrawalResource(fetcher) {
|
|
|
1849
1849
|
};
|
|
1850
1850
|
}
|
|
1851
1851
|
|
|
1852
|
+
// src/resources/reviews.ts
|
|
1853
|
+
function createReviewsResource(fetcher) {
|
|
1854
|
+
return {
|
|
1855
|
+
/**
|
|
1856
|
+
* List approved reviews for a product, with the aggregate rating and a
|
|
1857
|
+
* 1–5 star distribution.
|
|
1858
|
+
*
|
|
1859
|
+
* @param slug - Product URL slug
|
|
1860
|
+
* @param options - Fetch options (caching, headers, etc.)
|
|
1861
|
+
* @returns Approved reviews, average rating, count, and distribution
|
|
1862
|
+
*
|
|
1863
|
+
* @example
|
|
1864
|
+
* ```typescript
|
|
1865
|
+
* const { reviews, averageRating, reviewCount } =
|
|
1866
|
+
* await client.reviews.list('my-product');
|
|
1867
|
+
* ```
|
|
1868
|
+
*/
|
|
1869
|
+
async list(slug, options) {
|
|
1870
|
+
return fetcher.request(
|
|
1871
|
+
`/api/storefront/v1/reviews/${encodeURIComponent(slug)}`,
|
|
1872
|
+
{
|
|
1873
|
+
...options
|
|
1874
|
+
}
|
|
1875
|
+
);
|
|
1876
|
+
},
|
|
1877
|
+
/**
|
|
1878
|
+
* Submit a product review. Anonymous by default; pass a sessionId to submit
|
|
1879
|
+
* as a logged-in customer (enables the verified-purchase check + reward code).
|
|
1880
|
+
* The review is created as PENDING and appears once the store owner approves it.
|
|
1881
|
+
*
|
|
1882
|
+
* @param params - Review data (slug, rating 1–5, body, optional title/authorName)
|
|
1883
|
+
* @param sessionId - Optional customer session id (logged-in submit)
|
|
1884
|
+
* @param options - Fetch options
|
|
1885
|
+
* @returns The created review (PENDING) and a reward code if revealed
|
|
1886
|
+
*
|
|
1887
|
+
* @example Anonymous
|
|
1888
|
+
* ```typescript
|
|
1889
|
+
* await client.reviews.submit({
|
|
1890
|
+
* slug: 'my-product',
|
|
1891
|
+
* rating: 5,
|
|
1892
|
+
* body: 'Loistava tuote!',
|
|
1893
|
+
* authorName: 'Matti',
|
|
1894
|
+
* });
|
|
1895
|
+
* ```
|
|
1896
|
+
*
|
|
1897
|
+
* @example Logged-in (may return a reward code)
|
|
1898
|
+
* ```typescript
|
|
1899
|
+
* const { reward } = await client.reviews.submit(
|
|
1900
|
+
* { slug: 'my-product', rating: 5, body: 'Loistava tuote!' },
|
|
1901
|
+
* sessionId
|
|
1902
|
+
* );
|
|
1903
|
+
* if (reward) console.log(`Käytä koodia ${reward.code}`);
|
|
1904
|
+
* ```
|
|
1905
|
+
*/
|
|
1906
|
+
async submit(params, sessionId, options) {
|
|
1907
|
+
const { headers: optionHeaders, ...restOptions } = options ?? {};
|
|
1908
|
+
return fetcher.request(
|
|
1909
|
+
"/api/storefront/v1/reviews",
|
|
1910
|
+
{
|
|
1911
|
+
method: "POST",
|
|
1912
|
+
body: params,
|
|
1913
|
+
headers: {
|
|
1914
|
+
...sessionId ? { "x-session-id": sessionId } : {},
|
|
1915
|
+
...optionHeaders ?? {}
|
|
1916
|
+
},
|
|
1917
|
+
...restOptions
|
|
1918
|
+
}
|
|
1919
|
+
);
|
|
1920
|
+
}
|
|
1921
|
+
};
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1852
1924
|
// src/client.ts
|
|
1853
1925
|
function createStorefrontClient(config) {
|
|
1854
1926
|
if (!config.apiKey) {
|
|
@@ -1876,7 +1948,8 @@ function createStorefrontClient(config) {
|
|
|
1876
1948
|
discountCode: createDiscountCodeResource(fetcher),
|
|
1877
1949
|
pages: createPagesResource(fetcher),
|
|
1878
1950
|
tickets: createTicketsResource(fetcher),
|
|
1879
|
-
withdrawal: createWithdrawalResource(fetcher)
|
|
1951
|
+
withdrawal: createWithdrawalResource(fetcher),
|
|
1952
|
+
reviews: createReviewsResource(fetcher)
|
|
1880
1953
|
};
|
|
1881
1954
|
}
|
|
1882
1955
|
|