@faststore/api 1.10.6 → 1.10.8
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/CHANGELOG.md +11 -0
- package/dist/api.cjs.development.js +38 -3
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +38 -3
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/commerce/index.d.ts +4 -2
- package/dist/platforms/vtex/clients/commerce/types/SalesChannel.d.ts +24 -0
- package/dist/platforms/vtex/clients/index.d.ts +1 -0
- package/dist/platforms/vtex/loaders/index.d.ts +1 -0
- package/dist/platforms/vtex/loaders/salesChannel.d.ts +5 -0
- package/package.json +2 -2
- package/src/platforms/vtex/clients/commerce/index.ts +8 -4
- package/src/platforms/vtex/clients/commerce/types/SalesChannel.ts +25 -0
- package/src/platforms/vtex/loaders/index.ts +3 -0
- package/src/platforms/vtex/loaders/salesChannel.ts +15 -0
- package/src/platforms/vtex/resolvers/aggregateOffer.ts +10 -1
- package/src/platforms/vtex/resolvers/offer.ts +10 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FACET_CROSS_SELLING_MAP } from
|
|
2
|
-
import type { PortalProduct } from
|
|
1
|
+
import { FACET_CROSS_SELLING_MAP } from '../../utils/facets';
|
|
2
|
+
import type { PortalProduct } from './types/Product';
|
|
3
3
|
import type { Context, Options } from '../../index';
|
|
4
4
|
import type { Brand } from './types/Brand';
|
|
5
5
|
import type { CategoryTree } from './types/CategoryTree';
|
|
@@ -9,9 +9,11 @@ import type { Region, RegionInput } from './types/Region';
|
|
|
9
9
|
import type { Simulation, SimulationArgs, SimulationOptions } from './types/Simulation';
|
|
10
10
|
import type { Session } from './types/Session';
|
|
11
11
|
import type { Channel } from '../../utils/channel';
|
|
12
|
+
import type { SalesChannel } from './types/SalesChannel';
|
|
12
13
|
declare type ValueOf<T> = T extends Record<string, infer K> ? K : never;
|
|
13
14
|
export declare const VtexCommerce: ({ account, environment }: Options, ctx: Context) => {
|
|
14
15
|
catalog: {
|
|
16
|
+
salesChannel: (sc: string) => Promise<SalesChannel>;
|
|
15
17
|
brand: {
|
|
16
18
|
list: () => Promise<Brand[]>;
|
|
17
19
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface SalesChannel {
|
|
2
|
+
Id: number;
|
|
3
|
+
Name: string;
|
|
4
|
+
IsActive: boolean;
|
|
5
|
+
ProductClusterId: null;
|
|
6
|
+
CountryCode: string;
|
|
7
|
+
CultureInfo: string;
|
|
8
|
+
TimeZone: string;
|
|
9
|
+
CurrencyCode: string;
|
|
10
|
+
CurrencySymbol: string;
|
|
11
|
+
CurrencyLocale: number;
|
|
12
|
+
CurrencyFormatInfo: CurrencyFormatInfo;
|
|
13
|
+
Origin: null;
|
|
14
|
+
Position: number;
|
|
15
|
+
ConditionRule: null;
|
|
16
|
+
CurrencyDecimalDigits: null;
|
|
17
|
+
}
|
|
18
|
+
export interface CurrencyFormatInfo {
|
|
19
|
+
CurrencyDecimalDigits: number;
|
|
20
|
+
CurrencyDecimalSeparator: string;
|
|
21
|
+
CurrencyGroupSeparator: string;
|
|
22
|
+
CurrencyGroupSize: number;
|
|
23
|
+
StartsWithCurrencySymbol: boolean;
|
|
24
|
+
}
|
|
@@ -9,6 +9,7 @@ export declare const getClients: (options: Options, ctx: Context) => {
|
|
|
9
9
|
};
|
|
10
10
|
commerce: {
|
|
11
11
|
catalog: {
|
|
12
|
+
salesChannel: (sc: string) => Promise<import("./commerce/types/SalesChannel").SalesChannel>;
|
|
12
13
|
brand: {
|
|
13
14
|
list: () => Promise<import("./commerce/types/Brand").Brand[]>;
|
|
14
15
|
};
|
|
@@ -4,4 +4,5 @@ export declare const getLoaders: (options: Options, { clients }: Context) => {
|
|
|
4
4
|
skuLoader: import("dataloader")<string, import("../utils/enhanceSku").EnhancedSku, string>;
|
|
5
5
|
simulationLoader: import("dataloader")<import("../clients/commerce/types/Simulation").PayloadItem[], import("../clients/commerce/types/Simulation").Simulation, import("../clients/commerce/types/Simulation").PayloadItem[]>;
|
|
6
6
|
collectionLoader: import("dataloader")<string, import("../clients/commerce/types/Portal").CollectionPageType, string>;
|
|
7
|
+
salesChannelLoader: import("dataloader")<string, import("../clients/commerce/types/SalesChannel").SalesChannel, string>;
|
|
7
8
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
import { Options } from "..";
|
|
3
|
+
import { Clients } from "../clients";
|
|
4
|
+
import type { SalesChannel } from "./../clients/commerce/types/SalesChannel";
|
|
5
|
+
export declare const getSalesChannelLoader: (_: Options, clients: Clients) => DataLoader<string, SalesChannel, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/api",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"graphql": "^15.6.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "a1cee56b400b1309489843f7be6d1cf1b0eab65e"
|
|
50
50
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { FACET_CROSS_SELLING_MAP } from
|
|
2
|
-
import { fetchAPI } from
|
|
3
|
-
|
|
1
|
+
import { FACET_CROSS_SELLING_MAP } from '../../utils/facets'
|
|
2
|
+
import { fetchAPI } from '../fetch'
|
|
3
|
+
|
|
4
|
+
import type { PortalProduct } from './types/Product'
|
|
4
5
|
import type { Context, Options } from '../../index'
|
|
5
6
|
import type { Brand } from './types/Brand'
|
|
6
7
|
import type { CategoryTree } from './types/CategoryTree'
|
|
@@ -14,8 +15,9 @@ import type {
|
|
|
14
15
|
} from './types/Simulation'
|
|
15
16
|
import type { Session } from './types/Session'
|
|
16
17
|
import type { Channel } from '../../utils/channel'
|
|
18
|
+
import type { SalesChannel } from './types/SalesChannel'
|
|
17
19
|
|
|
18
|
-
type ValueOf<T> = T extends Record<string, infer K> ? K : never
|
|
20
|
+
type ValueOf<T> = T extends Record<string, infer K> ? K : never
|
|
19
21
|
|
|
20
22
|
const BASE_INIT = {
|
|
21
23
|
method: 'POST',
|
|
@@ -32,6 +34,8 @@ export const VtexCommerce = (
|
|
|
32
34
|
|
|
33
35
|
return {
|
|
34
36
|
catalog: {
|
|
37
|
+
salesChannel: (sc: string): Promise<SalesChannel> =>
|
|
38
|
+
fetchAPI(`${base}/api/catalog_system/pub/saleschannel/${sc}`),
|
|
35
39
|
brand: {
|
|
36
40
|
list: (): Promise<Brand[]> =>
|
|
37
41
|
fetchAPI(`${base}/api/catalog_system/pub/brand/list`),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface SalesChannel {
|
|
2
|
+
Id: number;
|
|
3
|
+
Name: string;
|
|
4
|
+
IsActive: boolean;
|
|
5
|
+
ProductClusterId: null;
|
|
6
|
+
CountryCode: string;
|
|
7
|
+
CultureInfo: string;
|
|
8
|
+
TimeZone: string;
|
|
9
|
+
CurrencyCode: string;
|
|
10
|
+
CurrencySymbol: string;
|
|
11
|
+
CurrencyLocale: number;
|
|
12
|
+
CurrencyFormatInfo: CurrencyFormatInfo;
|
|
13
|
+
Origin: null;
|
|
14
|
+
Position: number;
|
|
15
|
+
ConditionRule: null;
|
|
16
|
+
CurrencyDecimalDigits: null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CurrencyFormatInfo {
|
|
20
|
+
CurrencyDecimalDigits: number;
|
|
21
|
+
CurrencyDecimalSeparator: string;
|
|
22
|
+
CurrencyGroupSeparator: string;
|
|
23
|
+
CurrencyGroupSize: number;
|
|
24
|
+
StartsWithCurrencySymbol: boolean;
|
|
25
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getSalesChannelLoader } from './salesChannel';
|
|
1
2
|
import { getSimulationLoader } from './simulation'
|
|
2
3
|
import { getSkuLoader } from './sku'
|
|
3
4
|
import { getCollectionLoader } from './collection'
|
|
@@ -9,10 +10,12 @@ export const getLoaders = (options: Options, { clients }: Context) => {
|
|
|
9
10
|
const skuLoader = getSkuLoader(options, clients)
|
|
10
11
|
const simulationLoader = getSimulationLoader(options, clients)
|
|
11
12
|
const collectionLoader = getCollectionLoader(options, clients)
|
|
13
|
+
const salesChannelLoader = getSalesChannelLoader(options, clients)
|
|
12
14
|
|
|
13
15
|
return {
|
|
14
16
|
skuLoader,
|
|
15
17
|
simulationLoader,
|
|
16
18
|
collectionLoader,
|
|
19
|
+
salesChannelLoader
|
|
17
20
|
}
|
|
18
21
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import DataLoader from "dataloader";
|
|
2
|
+
|
|
3
|
+
import { Options } from "..";
|
|
4
|
+
import { Clients } from "../clients";
|
|
5
|
+
|
|
6
|
+
import type { SalesChannel } from "./../clients/commerce/types/SalesChannel";
|
|
7
|
+
|
|
8
|
+
export const getSalesChannelLoader = (_: Options, clients: Clients) => {
|
|
9
|
+
const loader = async (channels: readonly string[]) =>
|
|
10
|
+
Promise.all(
|
|
11
|
+
channels.map((sc) => clients.commerce.catalog.salesChannel(sc)),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return new DataLoader<string, SalesChannel>(loader);
|
|
15
|
+
};
|
|
@@ -20,6 +20,15 @@ export const StoreAggregateOffer: Record<string, Resolver<Root>> & {
|
|
|
20
20
|
return lowOffer ? price(lowOffer) : 0
|
|
21
21
|
},
|
|
22
22
|
offerCount: (offers) => offers.length,
|
|
23
|
-
priceCurrency: () =>
|
|
23
|
+
priceCurrency: async (_, __, ctx) => {
|
|
24
|
+
const {
|
|
25
|
+
loaders: { salesChannelLoader },
|
|
26
|
+
storage: { channel }
|
|
27
|
+
} = ctx
|
|
28
|
+
|
|
29
|
+
const sc = await salesChannelLoader.load(channel.salesChannel);
|
|
30
|
+
|
|
31
|
+
return sc.CurrencyCode ?? '';
|
|
32
|
+
},
|
|
24
33
|
offers: (offers) => offers,
|
|
25
34
|
}
|
|
@@ -24,7 +24,16 @@ const isOrderFormItem = (item: Root): item is OrderFormProduct =>
|
|
|
24
24
|
'skuName' in item
|
|
25
25
|
|
|
26
26
|
export const StoreOffer: Record<string, Resolver<Root>> = {
|
|
27
|
-
priceCurrency: () =>
|
|
27
|
+
priceCurrency: async (_, __, ctx) => {
|
|
28
|
+
const {
|
|
29
|
+
loaders: { salesChannelLoader },
|
|
30
|
+
storage: { channel }
|
|
31
|
+
} = ctx
|
|
32
|
+
|
|
33
|
+
const sc = await salesChannelLoader.load(channel.salesChannel);
|
|
34
|
+
|
|
35
|
+
return sc.CurrencyCode ?? '';
|
|
36
|
+
},
|
|
28
37
|
priceValidUntil: (root) => {
|
|
29
38
|
if (isSearchItem(root)) {
|
|
30
39
|
return root.PriceValidUntil ?? ''
|