@spree/next 0.6.9 → 0.7.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/dist/actions/addresses.d.ts +5 -5
- package/dist/actions/addresses.js +9 -9
- package/dist/actions/addresses.js.map +1 -1
- package/dist/actions/auth.d.ts +3 -3
- package/dist/actions/auth.js +10 -10
- package/dist/actions/auth.js.map +1 -1
- package/dist/actions/cart.d.ts +7 -7
- package/dist/actions/cart.js +10 -10
- package/dist/actions/cart.js.map +1 -1
- package/dist/actions/checkout.d.ts +10 -10
- package/dist/actions/checkout.js +11 -11
- package/dist/actions/checkout.js.map +1 -1
- package/dist/actions/credit-cards.d.ts +2 -2
- package/dist/actions/credit-cards.js +6 -6
- package/dist/actions/credit-cards.js.map +1 -1
- package/dist/actions/gift-cards.d.ts +3 -3
- package/dist/actions/gift-cards.js +6 -6
- package/dist/actions/gift-cards.js.map +1 -1
- package/dist/actions/locale.js +2 -2
- package/dist/actions/locale.js.map +1 -1
- package/dist/actions/orders.d.ts +3 -3
- package/dist/actions/orders.js +6 -6
- package/dist/actions/orders.js.map +1 -1
- package/dist/actions/payment-sessions.d.ts +5 -5
- package/dist/actions/payment-sessions.js +6 -6
- package/dist/actions/payment-sessions.js.map +1 -1
- package/dist/actions/payment-setup-sessions.d.ts +4 -4
- package/dist/actions/payment-setup-sessions.js +7 -7
- package/dist/actions/payment-setup-sessions.js.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/data/countries.d.ts +3 -3
- package/dist/data/countries.js +4 -4
- package/dist/data/countries.js.map +1 -1
- package/dist/data/currencies.d.ts +2 -2
- package/dist/data/currencies.js +3 -3
- package/dist/data/currencies.js.map +1 -1
- package/dist/data/locales.d.ts +2 -2
- package/dist/data/locales.js +3 -3
- package/dist/data/locales.js.map +1 -1
- package/dist/data/markets.d.ts +6 -6
- package/dist/data/markets.js +7 -7
- package/dist/data/markets.js.map +1 -1
- package/dist/data/products.d.ts +3 -3
- package/dist/data/products.js +5 -5
- package/dist/data/products.js.map +1 -1
- package/dist/data/taxonomies.d.ts +3 -3
- package/dist/data/taxonomies.js +4 -4
- package/dist/data/taxonomies.js.map +1 -1
- package/dist/data/taxons.d.ts +4 -4
- package/dist/data/taxons.js +5 -5
- package/dist/data/taxons.js.map +1 -1
- package/dist/index.d.ts +35 -35
- package/dist/index.js +62 -62
- package/dist/index.js.map +1 -1
- package/dist/locale.js +2 -2
- package/dist/locale.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/products.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/products.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,GAAyB,IAAA;AAC7B,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,YAAA,CAAa;AAAA,IACrB,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAoB;AAClC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,GAA6B;AAC3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{ createClient, type Client } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: Client | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the Client instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): Client {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_COUNTRY_COOKIE = 'spree_country';\nconst DEFAULT_LOCALE_COOKIE = 'spree_locale';\n\n/**\n * Read locale/currency/country from cookies (set by middleware).\n * Falls back to config defaults.\n * @internal\n */\nexport async function getLocaleOptions(): Promise<{\n locale?: string;\n currency?: string;\n country?: string;\n}> {\n const config = getConfig();\n const cookieStore = await cookies();\n\n const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;\n const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;\n\n return {\n locale: locale || config.defaultLocale,\n country: country || config.defaultCountry,\n // No currency — backend resolves from country via X-Spree-Country header\n };\n}\n","import type { Product, PaginatedResponse, ProductFiltersResponse, ProductListParams } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List products with optional filtering, sorting, and pagination.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listProducts(\n params?: ProductListParams,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<Product>> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().products.list(params, resolved);\n}\n\n/**\n * Get a single product by slug or ID.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getProduct(\n slugOrId: string,\n params?: { expand?: string[] },\n options?: SpreeNextOptions\n): Promise<Product> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().products.get(slugOrId, params, resolved);\n}\n\n/**\n * Get available product filters (price ranges, option values, etc.).\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getProductFilters(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<ProductFiltersResponse> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().products.filters(params, resolved);\n}\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Taxonomy, PaginatedResponse } from '@spree/sdk';
|
|
2
2
|
import { SpreeNextOptions } from '../types.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* List taxonomies with optional filtering and pagination.
|
|
6
6
|
* Locale/country are auto-read from cookies when not provided.
|
|
7
7
|
*/
|
|
8
|
-
declare function listTaxonomies(params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<PaginatedResponse<
|
|
8
|
+
declare function listTaxonomies(params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<PaginatedResponse<Taxonomy>>;
|
|
9
9
|
/**
|
|
10
10
|
* Get a single taxonomy by ID.
|
|
11
11
|
* Locale/country are auto-read from cookies when not provided.
|
|
12
12
|
*/
|
|
13
|
-
declare function getTaxonomy(id: string, params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<
|
|
13
|
+
declare function getTaxonomy(id: string, params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<Taxonomy>;
|
|
14
14
|
|
|
15
15
|
export { getTaxonomy, listTaxonomies };
|
package/dist/data/taxonomies.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createClient } from '@spree/sdk';
|
|
2
2
|
import { cookies } from 'next/headers';
|
|
3
3
|
|
|
4
4
|
// src/config.ts
|
|
@@ -6,7 +6,7 @@ var _client = null;
|
|
|
6
6
|
var _config = null;
|
|
7
7
|
function initSpreeNext(config) {
|
|
8
8
|
_config = config;
|
|
9
|
-
_client =
|
|
9
|
+
_client = createClient({
|
|
10
10
|
baseUrl: config.baseUrl,
|
|
11
11
|
publishableKey: config.publishableKey
|
|
12
12
|
});
|
|
@@ -48,11 +48,11 @@ async function getLocaleOptions() {
|
|
|
48
48
|
// src/data/taxonomies.ts
|
|
49
49
|
async function listTaxonomies(params, options) {
|
|
50
50
|
const resolved = options ?? await getLocaleOptions();
|
|
51
|
-
return getClient().
|
|
51
|
+
return getClient().taxonomies.list(params, resolved);
|
|
52
52
|
}
|
|
53
53
|
async function getTaxonomy(id, params, options) {
|
|
54
54
|
const resolved = options ?? await getLocaleOptions();
|
|
55
|
-
return getClient().
|
|
55
|
+
return getClient().taxonomies.get(id, params, resolved);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export { getTaxonomy, listTaxonomies };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/taxonomies.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/taxonomies.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,GAAyB,IAAA;AAC7B,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAA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sB,cAAA,CACpB,QACA,OAAA,EACsC;AACtC,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,SAAA,EAAU,CAAE,UAAA,CAAW,IAAA,CAAK,QAAQ,QAAQ,CAAA;AACrD;AAMA,eAAsB,WAAA,CACpB,EAAA,EACA,MAAA,EACA,OAAA,EACmB;AACnB,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,UAAA,CAAW,GAAA,CAAI,EAAA,EAAI,QAAQ,QAAQ,CAAA;AACxD","file":"taxonomies.js","sourcesContent":["import { createClient, type Client } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: Client | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the Client instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): Client {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_COUNTRY_COOKIE = 'spree_country';\nconst DEFAULT_LOCALE_COOKIE = 'spree_locale';\n\n/**\n * Read locale/currency/country from cookies (set by middleware).\n * Falls back to config defaults.\n * @internal\n */\nexport async function getLocaleOptions(): Promise<{\n locale?: string;\n currency?: string;\n country?: string;\n}> {\n const config = getConfig();\n const cookieStore = await cookies();\n\n const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;\n const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;\n\n return {\n locale: locale || config.defaultLocale,\n country: country || config.defaultCountry,\n // No currency — backend resolves from country via X-Spree-Country header\n };\n}\n","import type { Taxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<Taxonomy>> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().taxonomies.list(params, resolved);\n}\n\n/**\n * Get a single taxonomy by ID.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getTaxonomy(\n id: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<Taxonomy> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().taxonomies.get(id, params, resolved);\n}\n"]}
|
package/dist/data/taxons.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Taxon, ProductListParams, PaginatedResponse, Product, TaxonListParams } from '@spree/sdk';
|
|
2
2
|
import { SpreeNextOptions } from '../types.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* List taxons (categories) with optional filtering and pagination.
|
|
6
6
|
* Locale/country are auto-read from cookies when not provided.
|
|
7
7
|
*/
|
|
8
|
-
declare function listTaxons(params?: TaxonListParams, options?: SpreeNextOptions): Promise<PaginatedResponse<
|
|
8
|
+
declare function listTaxons(params?: TaxonListParams, options?: SpreeNextOptions): Promise<PaginatedResponse<Taxon>>;
|
|
9
9
|
/**
|
|
10
10
|
* Get a single taxon by ID or permalink.
|
|
11
11
|
* Locale/country are auto-read from cookies when not provided.
|
|
12
12
|
*/
|
|
13
|
-
declare function getTaxon(idOrPermalink: string, params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<
|
|
13
|
+
declare function getTaxon(idOrPermalink: string, params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<Taxon>;
|
|
14
14
|
/**
|
|
15
15
|
* List products within a taxon.
|
|
16
16
|
* Locale/country are auto-read from cookies when not provided.
|
|
17
17
|
*/
|
|
18
|
-
declare function listTaxonProducts(taxonId: string, params?: ProductListParams, options?: SpreeNextOptions): Promise<PaginatedResponse<
|
|
18
|
+
declare function listTaxonProducts(taxonId: string, params?: ProductListParams, options?: SpreeNextOptions): Promise<PaginatedResponse<Product>>;
|
|
19
19
|
|
|
20
20
|
export { getTaxon, listTaxonProducts, listTaxons };
|
package/dist/data/taxons.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createClient } from '@spree/sdk';
|
|
2
2
|
import { cookies } from 'next/headers';
|
|
3
3
|
|
|
4
4
|
// src/config.ts
|
|
@@ -6,7 +6,7 @@ var _client = null;
|
|
|
6
6
|
var _config = null;
|
|
7
7
|
function initSpreeNext(config) {
|
|
8
8
|
_config = config;
|
|
9
|
-
_client =
|
|
9
|
+
_client = createClient({
|
|
10
10
|
baseUrl: config.baseUrl,
|
|
11
11
|
publishableKey: config.publishableKey
|
|
12
12
|
});
|
|
@@ -48,15 +48,15 @@ async function getLocaleOptions() {
|
|
|
48
48
|
// src/data/taxons.ts
|
|
49
49
|
async function listTaxons(params, options) {
|
|
50
50
|
const resolved = options ?? await getLocaleOptions();
|
|
51
|
-
return getClient().
|
|
51
|
+
return getClient().taxons.list(params, resolved);
|
|
52
52
|
}
|
|
53
53
|
async function getTaxon(idOrPermalink, params, options) {
|
|
54
54
|
const resolved = options ?? await getLocaleOptions();
|
|
55
|
-
return getClient().
|
|
55
|
+
return getClient().taxons.get(idOrPermalink, params, resolved);
|
|
56
56
|
}
|
|
57
57
|
async function listTaxonProducts(taxonId, params, options) {
|
|
58
58
|
const resolved = options ?? await getLocaleOptions();
|
|
59
|
-
return getClient().
|
|
59
|
+
return getClient().taxons.products.list(taxonId, params, resolved);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export { getTaxon, listTaxonProducts, listTaxons };
|
package/dist/data/taxons.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/taxons.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/taxons.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,GAAyB,IAAA;AAC7B,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,YAAA,CAAa;AAAA,IACrB,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAoB;AAClC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;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AA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,MAAA,CAAO,SAAS,IAAA,CAAK,OAAA,EAAS,QAAQ,QAAQ,CAAA;AACnE","file":"taxons.js","sourcesContent":["import { createClient, type Client } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: Client | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the Client instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): Client {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_COUNTRY_COOKIE = 'spree_country';\nconst DEFAULT_LOCALE_COOKIE = 'spree_locale';\n\n/**\n * Read locale/currency/country from cookies (set by middleware).\n * Falls back to config defaults.\n * @internal\n */\nexport async function getLocaleOptions(): Promise<{\n locale?: string;\n currency?: string;\n country?: string;\n}> {\n const config = getConfig();\n const cookieStore = await cookies();\n\n const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;\n const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;\n\n return {\n locale: locale || config.defaultLocale,\n country: country || config.defaultCountry,\n // No currency — backend resolves from country via X-Spree-Country header\n };\n}\n","import type { Taxon, Product, PaginatedResponse, TaxonListParams, ProductListParams } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxons (categories) with optional filtering and pagination.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listTaxons(\n params?: TaxonListParams,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<Taxon>> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().taxons.list(params, resolved);\n}\n\n/**\n * Get a single taxon by ID or permalink.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getTaxon(\n idOrPermalink: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<Taxon> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().taxons.get(idOrPermalink, params, resolved);\n}\n\n/**\n * List products within a taxon.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listTaxonProducts(\n taxonId: string,\n params?: ProductListParams,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<Product>> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().taxons.products.list(taxonId, params, resolved);\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,27 +7,27 @@ export { getCountry, listCountries } from './data/countries.js';
|
|
|
7
7
|
export { listCurrencies } from './data/currencies.js';
|
|
8
8
|
export { listLocales } from './data/locales.js';
|
|
9
9
|
export { getMarket, getMarketCountry, listMarketCountries, listMarkets, resolveMarket } from './data/markets.js';
|
|
10
|
-
import {
|
|
11
|
-
export { AddressParams, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, CreateCartParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams,
|
|
10
|
+
import { Order, CreateCartParams, Shipment, UpdateOrderParams, Customer, AddressParams, Address, OrderListParams, PaginatedResponse, CreditCard, GiftCard, CompletePaymentSessionParams, PaymentSession, CreatePaymentSessionParams, UpdatePaymentSessionParams, CompletePaymentSetupSessionParams, PaymentSetupSession, CreatePaymentSetupSessionParams } from '@spree/sdk';
|
|
11
|
+
export { Address, AddressParams, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, Country, CreateCartParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, CreditCard, Currency, Customer, DigitalLink, GiftCard, Image, LineItem, LineItemInput, Locale, Market, OptionType, OptionValue, Order, OrderPromotion, PaginatedResponse, Payment, PaymentMethod, PaymentSession, PaymentSetupSession, Price, Product, ProductFiltersResponse, Shipment, ShippingRate, SpreeError, Taxon, Taxonomy, UpdateOrderParams, UpdatePaymentSessionParams, Variant } from '@spree/sdk';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Get the current cart. Returns null if no cart exists.
|
|
15
15
|
*/
|
|
16
|
-
declare function getCart(): Promise<(
|
|
16
|
+
declare function getCart(): Promise<(Order & {
|
|
17
17
|
token: string;
|
|
18
18
|
}) | null>;
|
|
19
19
|
/**
|
|
20
20
|
* Get existing cart or create a new one.
|
|
21
21
|
* @param params - Optional cart creation params (metadata, line_items)
|
|
22
22
|
*/
|
|
23
|
-
declare function getOrCreateCart(params?: CreateCartParams): Promise<
|
|
23
|
+
declare function getOrCreateCart(params?: CreateCartParams): Promise<Order & {
|
|
24
24
|
token: string;
|
|
25
25
|
}>;
|
|
26
26
|
/**
|
|
27
27
|
* Add an item to the cart. Creates a cart if none exists.
|
|
28
28
|
* Returns the updated order with recalculated totals.
|
|
29
29
|
*/
|
|
30
|
-
declare function addItem(variantId: string, quantity?: number, metadata?: Record<string, unknown>): Promise<
|
|
30
|
+
declare function addItem(variantId: string, quantity?: number, metadata?: Record<string, unknown>): Promise<Order>;
|
|
31
31
|
/**
|
|
32
32
|
* Update a line item in the cart (quantity and/or metadata).
|
|
33
33
|
* Returns the updated order with recalculated totals.
|
|
@@ -45,12 +45,12 @@ declare function addItem(variantId: string, quantity?: number, metadata?: Record
|
|
|
45
45
|
declare function updateItem(lineItemId: string, params: {
|
|
46
46
|
quantity?: number;
|
|
47
47
|
metadata?: Record<string, unknown>;
|
|
48
|
-
}): Promise<
|
|
48
|
+
}): Promise<Order>;
|
|
49
49
|
/**
|
|
50
50
|
* Remove a line item from the cart.
|
|
51
51
|
* Returns the updated order with recalculated totals.
|
|
52
52
|
*/
|
|
53
|
-
declare function removeItem(lineItemId: string): Promise<
|
|
53
|
+
declare function removeItem(lineItemId: string): Promise<Order>;
|
|
54
54
|
/**
|
|
55
55
|
* Clear the cart (abandons the current cart).
|
|
56
56
|
*/
|
|
@@ -59,7 +59,7 @@ declare function clearCart(): Promise<void>;
|
|
|
59
59
|
* Associate a guest cart with the currently authenticated user.
|
|
60
60
|
* Call this after login/register when the user has an existing guest cart.
|
|
61
61
|
*/
|
|
62
|
-
declare function associateCart(): Promise<(
|
|
62
|
+
declare function associateCart(): Promise<(Order & {
|
|
63
63
|
token: string;
|
|
64
64
|
}) | null>;
|
|
65
65
|
|
|
@@ -67,42 +67,42 @@ declare function associateCart(): Promise<(StoreOrder & {
|
|
|
67
67
|
* Get the current checkout order state.
|
|
68
68
|
* Includes line_items, shipments, and addresses by default.
|
|
69
69
|
*/
|
|
70
|
-
declare function getCheckout(orderId: string): Promise<
|
|
70
|
+
declare function getCheckout(orderId: string): Promise<Order>;
|
|
71
71
|
/**
|
|
72
72
|
* Update an order (addresses, email, currency, locale, metadata, etc.).
|
|
73
73
|
*/
|
|
74
|
-
declare function updateOrder(orderId: string, params: UpdateOrderParams): Promise<
|
|
74
|
+
declare function updateOrder(orderId: string, params: UpdateOrderParams): Promise<Order>;
|
|
75
75
|
/**
|
|
76
76
|
* Advance the checkout to the next step.
|
|
77
77
|
*/
|
|
78
|
-
declare function advance(orderId: string): Promise<
|
|
78
|
+
declare function advance(orderId: string): Promise<Order>;
|
|
79
79
|
/**
|
|
80
80
|
* Move the checkout to the next step (alias for advance).
|
|
81
81
|
*/
|
|
82
|
-
declare function next(orderId: string): Promise<
|
|
82
|
+
declare function next(orderId: string): Promise<Order>;
|
|
83
83
|
/**
|
|
84
84
|
* Get shipments for the order (includes available shipping rates).
|
|
85
85
|
*/
|
|
86
86
|
declare function getShipments(orderId: string): Promise<{
|
|
87
|
-
data:
|
|
87
|
+
data: Shipment[];
|
|
88
88
|
}>;
|
|
89
89
|
/**
|
|
90
90
|
* Select a shipping rate for a shipment.
|
|
91
91
|
* Returns the updated order with recalculated totals.
|
|
92
92
|
*/
|
|
93
|
-
declare function selectShippingRate(orderId: string, shipmentId: string, shippingRateId: string): Promise<
|
|
93
|
+
declare function selectShippingRate(orderId: string, shipmentId: string, shippingRateId: string): Promise<Order>;
|
|
94
94
|
/**
|
|
95
95
|
* Apply a coupon code to the order.
|
|
96
96
|
*/
|
|
97
|
-
declare function applyCoupon(orderId: string, code: string): Promise<
|
|
97
|
+
declare function applyCoupon(orderId: string, code: string): Promise<Order>;
|
|
98
98
|
/**
|
|
99
99
|
* Remove a coupon/promotion from the order.
|
|
100
100
|
*/
|
|
101
|
-
declare function removeCoupon(orderId: string, promotionId: string): Promise<
|
|
101
|
+
declare function removeCoupon(orderId: string, promotionId: string): Promise<Order>;
|
|
102
102
|
/**
|
|
103
103
|
* Complete the checkout and place the order.
|
|
104
104
|
*/
|
|
105
|
-
declare function complete(orderId: string): Promise<
|
|
105
|
+
declare function complete(orderId: string): Promise<Order>;
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* Login with email and password.
|
|
@@ -139,7 +139,7 @@ declare function logout(): Promise<void>;
|
|
|
139
139
|
/**
|
|
140
140
|
* Get the currently authenticated customer. Returns null if not logged in.
|
|
141
141
|
*/
|
|
142
|
-
declare function getCustomer(): Promise<
|
|
142
|
+
declare function getCustomer(): Promise<Customer | null>;
|
|
143
143
|
/**
|
|
144
144
|
* Update the current customer's profile.
|
|
145
145
|
*/
|
|
@@ -147,26 +147,26 @@ declare function updateCustomer(data: {
|
|
|
147
147
|
first_name?: string;
|
|
148
148
|
last_name?: string;
|
|
149
149
|
email?: string;
|
|
150
|
-
}): Promise<
|
|
150
|
+
}): Promise<Customer>;
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
153
|
* List the authenticated customer's addresses.
|
|
154
154
|
*/
|
|
155
155
|
declare function listAddresses(): Promise<{
|
|
156
|
-
data:
|
|
156
|
+
data: Address[];
|
|
157
157
|
}>;
|
|
158
158
|
/**
|
|
159
159
|
* Get a single address by ID.
|
|
160
160
|
*/
|
|
161
|
-
declare function getAddress(id: string): Promise<
|
|
161
|
+
declare function getAddress(id: string): Promise<Address>;
|
|
162
162
|
/**
|
|
163
163
|
* Create a new address for the customer.
|
|
164
164
|
*/
|
|
165
|
-
declare function createAddress(params: AddressParams): Promise<
|
|
165
|
+
declare function createAddress(params: AddressParams): Promise<Address>;
|
|
166
166
|
/**
|
|
167
167
|
* Update an existing address.
|
|
168
168
|
*/
|
|
169
|
-
declare function updateAddress(id: string, params: Partial<AddressParams>): Promise<
|
|
169
|
+
declare function updateAddress(id: string, params: Partial<AddressParams>): Promise<Address>;
|
|
170
170
|
/**
|
|
171
171
|
* Delete an address.
|
|
172
172
|
*/
|
|
@@ -175,11 +175,11 @@ declare function deleteAddress(id: string): Promise<void>;
|
|
|
175
175
|
/**
|
|
176
176
|
* List the authenticated customer's orders.
|
|
177
177
|
*/
|
|
178
|
-
declare function listOrders(params?: OrderListParams): Promise<PaginatedResponse<
|
|
178
|
+
declare function listOrders(params?: OrderListParams): Promise<PaginatedResponse<Order>>;
|
|
179
179
|
/**
|
|
180
180
|
* Get a single order by ID or number.
|
|
181
181
|
*/
|
|
182
|
-
declare function getOrder(idOrNumber: string, params?: Record<string, unknown>): Promise<
|
|
182
|
+
declare function getOrder(idOrNumber: string, params?: Record<string, unknown>): Promise<Order>;
|
|
183
183
|
|
|
184
184
|
/**
|
|
185
185
|
* Set locale/country cookies for subsequent requests.
|
|
@@ -194,7 +194,7 @@ declare function setLocale(params: {
|
|
|
194
194
|
* List the authenticated customer's credit cards.
|
|
195
195
|
*/
|
|
196
196
|
declare function listCreditCards(): Promise<{
|
|
197
|
-
data:
|
|
197
|
+
data: CreditCard[];
|
|
198
198
|
}>;
|
|
199
199
|
/**
|
|
200
200
|
* Delete a credit card.
|
|
@@ -205,46 +205,46 @@ declare function deleteCreditCard(id: string): Promise<void>;
|
|
|
205
205
|
* List the authenticated customer's gift cards.
|
|
206
206
|
*/
|
|
207
207
|
declare function listGiftCards(): Promise<{
|
|
208
|
-
data:
|
|
208
|
+
data: GiftCard[];
|
|
209
209
|
}>;
|
|
210
210
|
/**
|
|
211
211
|
* Get a single gift card by ID.
|
|
212
212
|
*/
|
|
213
|
-
declare function getGiftCard(id: string): Promise<
|
|
213
|
+
declare function getGiftCard(id: string): Promise<GiftCard>;
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
216
|
* Create a payment session for an order.
|
|
217
217
|
* Delegates to the payment gateway to initialize a provider-specific session.
|
|
218
218
|
*/
|
|
219
|
-
declare function createPaymentSession(orderId: string, params: CreatePaymentSessionParams): Promise<
|
|
219
|
+
declare function createPaymentSession(orderId: string, params: CreatePaymentSessionParams): Promise<PaymentSession>;
|
|
220
220
|
/**
|
|
221
221
|
* Get a payment session by ID.
|
|
222
222
|
*/
|
|
223
|
-
declare function getPaymentSession(orderId: string, sessionId: string): Promise<
|
|
223
|
+
declare function getPaymentSession(orderId: string, sessionId: string): Promise<PaymentSession>;
|
|
224
224
|
/**
|
|
225
225
|
* Update a payment session.
|
|
226
226
|
* Delegates to the payment gateway to sync changes with the provider.
|
|
227
227
|
*/
|
|
228
|
-
declare function updatePaymentSession(orderId: string, sessionId: string, params: UpdatePaymentSessionParams): Promise<
|
|
228
|
+
declare function updatePaymentSession(orderId: string, sessionId: string, params: UpdatePaymentSessionParams): Promise<PaymentSession>;
|
|
229
229
|
/**
|
|
230
230
|
* Complete a payment session.
|
|
231
231
|
* Confirms the payment with the provider, triggering capture/authorization.
|
|
232
232
|
*/
|
|
233
|
-
declare function completePaymentSession(orderId: string, sessionId: string, params?: CompletePaymentSessionParams): Promise<
|
|
233
|
+
declare function completePaymentSession(orderId: string, sessionId: string, params?: CompletePaymentSessionParams): Promise<PaymentSession>;
|
|
234
234
|
|
|
235
235
|
/**
|
|
236
236
|
* Create a payment setup session for saving a payment method.
|
|
237
237
|
* Delegates to the payment gateway to initialize a setup flow.
|
|
238
238
|
*/
|
|
239
|
-
declare function createPaymentSetupSession(params: CreatePaymentSetupSessionParams): Promise<
|
|
239
|
+
declare function createPaymentSetupSession(params: CreatePaymentSetupSessionParams): Promise<PaymentSetupSession>;
|
|
240
240
|
/**
|
|
241
241
|
* Get a payment setup session by ID.
|
|
242
242
|
*/
|
|
243
|
-
declare function getPaymentSetupSession(id: string): Promise<
|
|
243
|
+
declare function getPaymentSetupSession(id: string): Promise<PaymentSetupSession>;
|
|
244
244
|
/**
|
|
245
245
|
* Complete a payment setup session.
|
|
246
246
|
* Confirms the setup with the provider, resulting in a saved payment method.
|
|
247
247
|
*/
|
|
248
|
-
declare function completePaymentSetupSession(id: string, params?: CompletePaymentSetupSessionParams): Promise<
|
|
248
|
+
declare function completePaymentSetupSession(id: string, params?: CompletePaymentSetupSessionParams): Promise<PaymentSetupSession>;
|
|
249
249
|
|
|
250
250
|
export { addItem, advance, applyCoupon, associateCart, clearCart, complete, completePaymentSession, completePaymentSetupSession, createAddress, createPaymentSession, createPaymentSetupSession, deleteAddress, deleteCreditCard, getAddress, getCart, getCheckout, getCustomer, getGiftCard, getOrCreateCart, getOrder, getPaymentSession, getPaymentSetupSession, getShipments, listAddresses, listCreditCards, listGiftCards, listOrders, login, logout, next, register, removeCoupon, removeItem, selectShippingRate, setLocale, updateAddress, updateCustomer, updateItem, updateOrder, updatePaymentSession };
|