@phystack/products 4.3.40-dev
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 +2736 -0
- package/dist/api.d.ts +11 -0
- package/dist/api.js +49 -0
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +11 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +29 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +1423 -0
- package/dist/services/grid-product-service-admin.d.ts +23 -0
- package/dist/services/grid-product-service-admin.js +120 -0
- package/dist/services/grid-product-service-client.d.ts +80 -0
- package/dist/services/grid-product-service-client.js +633 -0
- package/dist/services/grid-product-service-interface.d.ts +47 -0
- package/dist/services/grid-product-service-interface.js +2 -0
- package/dist/services/http-service.d.ts +14 -0
- package/dist/services/http-service.js +44 -0
- package/dist/types/grid-product.d.ts +458 -0
- package/dist/types/grid-product.js +38 -0
- package/dist/types/iso-currency-codes.d.ts +182 -0
- package/dist/types/iso-currency-codes.js +186 -0
- package/dist/types/iso-language-ids.d.ts +170 -0
- package/dist/types/iso-language-ids.js +174 -0
- package/dist/types/parameters.d.ts +242 -0
- package/dist/types/parameters.js +99 -0
- package/dist/utils.d.ts +27 -0
- package/dist/utils.js +187 -0
- package/jest.config.js +10 -0
- package/jest.setup.js +1 -0
- package/package.json +31 -0
- package/src/api.ts +47 -0
- package/src/helpers.ts +7 -0
- package/src/index.test.ts +1526 -0
- package/src/index.ts +8 -0
- package/src/services/grid-product-service-admin.ts +123 -0
- package/src/services/grid-product-service-client.ts +995 -0
- package/src/services/grid-product-service-interface.ts +105 -0
- package/src/services/http-service.ts +50 -0
- package/src/types/grid-product.ts +548 -0
- package/src/types/iso-currency-codes.ts +182 -0
- package/src/types/iso-language-ids.ts +170 -0
- package/src/types/parameters.ts +231 -0
- package/src/utils.ts +325 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import HttpService from './http-service';
|
|
2
|
+
import { DataResidencyEnum, GridProduct, GridProductPushPayload, ProductType, UpdateVariantsParams } from '../types/grid-product';
|
|
3
|
+
import GridProductServiceClient from './grid-product-service-client';
|
|
4
|
+
import { IsoLanguageIds } from '../types/iso-language-ids';
|
|
5
|
+
type Options = {
|
|
6
|
+
tenantId: string;
|
|
7
|
+
environment: string;
|
|
8
|
+
dataResidency: DataResidencyEnum;
|
|
9
|
+
accessToken?: string;
|
|
10
|
+
locale: IsoLanguageIds;
|
|
11
|
+
};
|
|
12
|
+
export declare class GridProductServiceAdmin extends GridProductServiceClient {
|
|
13
|
+
readonly httpService: HttpService;
|
|
14
|
+
constructor({ tenantId, accessToken, environment, dataResidency, locale }: Options);
|
|
15
|
+
updateProductFields: (data: Array<Partial<GridProduct>>) => Promise<any>;
|
|
16
|
+
pushProducts: (data: Array<GridProductPushPayload>) => Promise<any>;
|
|
17
|
+
removeProducts: (data: Array<string>) => Promise<any>;
|
|
18
|
+
removeSpaceProducts: (spaceId: string, data: Array<string>) => Promise<any>;
|
|
19
|
+
pushProductTypes: (data: Array<ProductType>) => Promise<any>;
|
|
20
|
+
removeProductTypes: (data: Array<string>) => Promise<any>;
|
|
21
|
+
updateVariants: (params: UpdateVariantsParams) => Promise<any>;
|
|
22
|
+
}
|
|
23
|
+
export default GridProductServiceAdmin;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GridProductServiceAdmin = void 0;
|
|
16
|
+
const http_service_1 = __importDefault(require("./http-service"));
|
|
17
|
+
const api_1 = require("../api");
|
|
18
|
+
const grid_product_service_client_1 = __importDefault(require("./grid-product-service-client"));
|
|
19
|
+
class GridProductServiceAdmin extends grid_product_service_client_1.default {
|
|
20
|
+
constructor({ tenantId, accessToken, environment, dataResidency, locale }) {
|
|
21
|
+
super({ tenantId, environment, dataResidency, locale });
|
|
22
|
+
this.updateProductFields = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
24
|
+
try {
|
|
25
|
+
const result = yield this.httpService.patch('/products', { data });
|
|
26
|
+
return result.data;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.pushProducts = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
var _a;
|
|
35
|
+
try {
|
|
36
|
+
const result = yield this.httpService.post('/products-push', { data });
|
|
37
|
+
return result.data;
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
this.removeProducts = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
var _a;
|
|
46
|
+
try {
|
|
47
|
+
const result = yield this.httpService.delete('/products', {
|
|
48
|
+
data: { data },
|
|
49
|
+
});
|
|
50
|
+
return result.data;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.removeSpaceProducts = (spaceId, data) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
var _a;
|
|
59
|
+
try {
|
|
60
|
+
const result = yield this.httpService.delete(`/spaces/${spaceId}/products`, {
|
|
61
|
+
data: { data },
|
|
62
|
+
});
|
|
63
|
+
return result.data;
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.pushProductTypes = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
var _a;
|
|
72
|
+
try {
|
|
73
|
+
const result = yield this.httpService.post('/product-types', { data });
|
|
74
|
+
return result.data;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.removeProductTypes = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
var _a;
|
|
83
|
+
try {
|
|
84
|
+
const result = yield this.httpService.delete('/product-types', {
|
|
85
|
+
data: { data },
|
|
86
|
+
});
|
|
87
|
+
return result.data;
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
this.updateVariants = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
var _a;
|
|
96
|
+
try {
|
|
97
|
+
const result = yield this.httpService.patch(`/variants`, params);
|
|
98
|
+
return result.data;
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
throw new Error((_a = err.response.data.message) !== null && _a !== void 0 ? _a : err.message);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (!tenantId) {
|
|
106
|
+
throw new Error('Error: tenantId is required');
|
|
107
|
+
}
|
|
108
|
+
if (!environment) {
|
|
109
|
+
throw new Error('Error: environment is required');
|
|
110
|
+
}
|
|
111
|
+
const apiEndpoint = (0, api_1.setApiEndpoint)(dataResidency);
|
|
112
|
+
this.httpService = new http_service_1.default({
|
|
113
|
+
baseUrl: `${apiEndpoint}/tenants/${tenantId}/${environment}`,
|
|
114
|
+
accessToken,
|
|
115
|
+
});
|
|
116
|
+
this.locale = locale;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.GridProductServiceAdmin = GridProductServiceAdmin;
|
|
120
|
+
exports.default = GridProductServiceAdmin;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import HttpService from './http-service';
|
|
2
|
+
import { ProductDetailsByCodeQueryParameters, ProductDetailsQueryParameters, ProductFiltersQueryParameters, ProductGroupStoresInventoryParam, ProductGroupStoresInventoryResponse, ProductQueryParameters, ProductRecommendationsQueryParameters, ProductTypesListQueryParameters, ProductTypesListWithSpaceProductsQueryParameters, SearchQueryParameters } from '../types/parameters';
|
|
3
|
+
import { DataResidencyEnum, FilterByGroup, FilterByLanguage, GetCartPromotionsParams, GetCartPromotionsResponse, GetVariantActivePriceParams, GetVariantActivePriceResponse, GridProduct, InventoryItem, ProductRecommendationLibraryResponse, ProductType, SelectablePartialProduct, SortOptionsResponse, VariantInfo, VariantInventory } from '../types/grid-product';
|
|
4
|
+
import { IsoLanguageIds } from '../types/iso-language-ids';
|
|
5
|
+
import GridProductServiceInterface from './grid-product-service-interface';
|
|
6
|
+
interface GetProductListResponse {
|
|
7
|
+
list: Partial<GridProduct>[];
|
|
8
|
+
attributeFilters: FilterByLanguage;
|
|
9
|
+
}
|
|
10
|
+
interface GetProductListLibraryResponse extends GetProductListResponse {
|
|
11
|
+
list: SelectablePartialProduct[];
|
|
12
|
+
}
|
|
13
|
+
type Options = {
|
|
14
|
+
tenantId: string;
|
|
15
|
+
environment: string;
|
|
16
|
+
dataResidency: DataResidencyEnum;
|
|
17
|
+
locale: IsoLanguageIds;
|
|
18
|
+
fallbackLocale?: IsoLanguageIds;
|
|
19
|
+
};
|
|
20
|
+
type JSONValue = string | number | boolean | null | JSONObject | JSONArray;
|
|
21
|
+
interface JSONObject {
|
|
22
|
+
[key: string]: JSONValue;
|
|
23
|
+
}
|
|
24
|
+
type JSONArray = JSONValue[];
|
|
25
|
+
export declare class GridProductServiceClient implements GridProductServiceInterface {
|
|
26
|
+
readonly httpService: HttpService;
|
|
27
|
+
locale: IsoLanguageIds;
|
|
28
|
+
fallbackLocale?: IsoLanguageIds;
|
|
29
|
+
apiEndpoint: string;
|
|
30
|
+
tenantId: string;
|
|
31
|
+
constructor({ tenantId, environment, dataResidency, locale, fallbackLocale }: Options);
|
|
32
|
+
getLocalizedValue: <T extends {
|
|
33
|
+
isoLanguageId?: IsoLanguageIds | "*";
|
|
34
|
+
}>(list: T[], locale: IsoLanguageIds | "*") => T | undefined;
|
|
35
|
+
getLocalizedList: <T extends {
|
|
36
|
+
isoLanguageId?: IsoLanguageIds | "*";
|
|
37
|
+
}>(list: T[], locale: IsoLanguageIds | "*") => T[];
|
|
38
|
+
getFilteredList: <T>(list: T[], filterFn: ((item: T) => boolean) | undefined) => T[];
|
|
39
|
+
buildSelectableProduct: (product: Partial<GridProduct>) => SelectablePartialProduct;
|
|
40
|
+
getProductById: (id: string, params: ProductDetailsQueryParameters) => Promise<SelectablePartialProduct>;
|
|
41
|
+
getProductByBarcode: (code: string, params: ProductDetailsByCodeQueryParameters) => Promise<{
|
|
42
|
+
productDetails: SelectablePartialProduct;
|
|
43
|
+
productId: string;
|
|
44
|
+
}>;
|
|
45
|
+
getProductList: (params?: ProductQueryParameters) => Promise<GetProductListLibraryResponse>;
|
|
46
|
+
getProductListV2: (params?: ProductQueryParameters) => Promise<GetProductListLibraryResponse>;
|
|
47
|
+
search: (params: SearchQueryParameters) => Promise<{
|
|
48
|
+
products: SelectablePartialProduct[];
|
|
49
|
+
productTypes: Array<ProductType>;
|
|
50
|
+
}>;
|
|
51
|
+
getProductTypesList: (params?: ProductTypesListQueryParameters) => Promise<ProductType[]>;
|
|
52
|
+
getProductTypesListWithSpaceProducts: (params: ProductTypesListWithSpaceProductsQueryParameters) => Promise<ProductType[]>;
|
|
53
|
+
getProductType: (id: string) => Promise<ProductType>;
|
|
54
|
+
getProductFilters: (params: ProductFiltersQueryParameters) => Promise<FilterByGroup>;
|
|
55
|
+
getProductSortOptions: (isoLanguageId?: IsoLanguageIds) => Promise<SortOptionsResponse>;
|
|
56
|
+
getProductRecommendations: (id: string) => Promise<SelectablePartialProduct[]>;
|
|
57
|
+
getProductRecommendationsByProductId: (id: string, params: Partial<ProductRecommendationsQueryParameters>) => Promise<ProductRecommendationLibraryResponse>;
|
|
58
|
+
getProductRecommendationsByProductIdV2: (id: string, payload: JSONValue) => Promise<SelectablePartialProduct[]>;
|
|
59
|
+
getVariantsList: (productIds: string[]) => Promise<VariantInfo[]>;
|
|
60
|
+
getVariantsListByIds: (productIds: string[]) => Promise<VariantInfo[]>;
|
|
61
|
+
getVariantDetails: (productId: string) => Promise<VariantInfo>;
|
|
62
|
+
getProductEanByEpc: (epc: string) => Promise<string>;
|
|
63
|
+
getProductByEpc: (code: string, params: ProductDetailsByCodeQueryParameters) => Promise<{
|
|
64
|
+
productDetails: SelectablePartialProduct;
|
|
65
|
+
productId: string;
|
|
66
|
+
}>;
|
|
67
|
+
getProductInventory: ({ deviceId, requestedQty, skuId, }: {
|
|
68
|
+
deviceId?: string;
|
|
69
|
+
requestedQty: number;
|
|
70
|
+
skuId: string;
|
|
71
|
+
}) => Promise<InventoryItem | null>;
|
|
72
|
+
getVariantInventory: ({ productId, spaceId, }: {
|
|
73
|
+
productId: string;
|
|
74
|
+
spaceId?: string;
|
|
75
|
+
}) => Promise<VariantInventory>;
|
|
76
|
+
getProductGroupStoresInventory: (params: ProductGroupStoresInventoryParam) => Promise<ProductGroupStoresInventoryResponse | null>;
|
|
77
|
+
getCartPromotions: (params: GetCartPromotionsParams) => Promise<GetCartPromotionsResponse | null>;
|
|
78
|
+
getVariantActivePrice: (params: GetVariantActivePriceParams) => Promise<GetVariantActivePriceResponse | null>;
|
|
79
|
+
}
|
|
80
|
+
export default GridProductServiceClient;
|