ozon-api 0.0.7 → 0.0.9
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/lib/getApiQueryLanguage.d.ts +2 -0
- package/dist/lib/getApiQueryLanguage.js +20 -0
- package/dist/ozon/category/index.d.ts +3 -2
- package/dist/ozon/category/index.js +111 -14
- package/dist/service/api/CategoryController.d.ts +1 -0
- package/dist/service/api/CategoryController.js +23 -0
- package/dist/types/Category.d.ts +19 -1
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var getApiQueryLanguage = function getApiQueryLanguage(language) {
|
|
2
|
+
var _language$split;
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
var lang = ((language === null || language === void 0 || (_language$split = language.split(/[-_]/)) === null || _language$split === void 0 ? void 0 : _language$split[0]) || '').toLocaleUpperCase();
|
|
5
|
+
var Dict = {
|
|
6
|
+
ZH: 'ZH_HANS'
|
|
7
|
+
};
|
|
8
|
+
if (Dict[lang]) {
|
|
9
|
+
lang = Dict[lang];
|
|
10
|
+
}
|
|
11
|
+
if (!lang) {
|
|
12
|
+
lang = 'ZH_HANS';
|
|
13
|
+
}
|
|
14
|
+
var ApiLanguageList = ["EN", 'RU', 'TR', 'ZH_HANS'];
|
|
15
|
+
if (!ApiLanguageList.includes(lang)) {
|
|
16
|
+
lang = 'EN';
|
|
17
|
+
}
|
|
18
|
+
return lang;
|
|
19
|
+
};
|
|
20
|
+
export default getApiQueryLanguage;
|
|
@@ -2,7 +2,8 @@ import { Category } from "../../types/Category";
|
|
|
2
2
|
declare class CategoryClass {
|
|
3
3
|
private readonly apiKeyInfo;
|
|
4
4
|
constructor(apiId: string, apiKey: string);
|
|
5
|
-
attribute(description_category_id: number, type_id: number,
|
|
6
|
-
attributeValue(description_category_id: number, type_id: number, attribute_id: number,
|
|
5
|
+
attribute(description_category_id: number, type_id: number, lang?: Global.ApiLanguage | string): Promise<Category.Attribute[]>;
|
|
6
|
+
attributeValue(description_category_id: number, type_id: number, attribute_id: number, lang?: Global.ApiLanguage | string, limit?: number, last_value_id?: number): Promise<Category.AttributeValue[]>;
|
|
7
|
+
attributeValueSearch(description_category_id: number, type_id: number, attribute_id: number, value: string): Promise<Category.AttributeValue[]>;
|
|
7
8
|
}
|
|
8
9
|
export default CategoryClass;
|
|
@@ -9,6 +9,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
9
9
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
10
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
11
|
import * as CategoryController from "../../service/api/CategoryController";
|
|
12
|
+
import getApiQueryLanguage from "../../lib/getApiQueryLanguage";
|
|
12
13
|
var CategoryClass = /*#__PURE__*/function () {
|
|
13
14
|
function CategoryClass(apiId, apiKey) {
|
|
14
15
|
_classCallCheck(this, CategoryClass);
|
|
@@ -29,12 +30,13 @@ var CategoryClass = /*#__PURE__*/function () {
|
|
|
29
30
|
value: function () {
|
|
30
31
|
var _attribute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(description_category_id, type_id) {
|
|
31
32
|
var _this = this;
|
|
32
|
-
var
|
|
33
|
+
var lang,
|
|
34
|
+
language,
|
|
33
35
|
_args2 = arguments;
|
|
34
36
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
35
37
|
while (1) switch (_context2.prev = _context2.next) {
|
|
36
38
|
case 0:
|
|
37
|
-
|
|
39
|
+
lang = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : 'ZH_HANS';
|
|
38
40
|
if (description_category_id) {
|
|
39
41
|
_context2.next = 3;
|
|
40
42
|
break;
|
|
@@ -47,6 +49,7 @@ var CategoryClass = /*#__PURE__*/function () {
|
|
|
47
49
|
}
|
|
48
50
|
return _context2.abrupt("return", Promise.reject(new Error('请输入 typeId')));
|
|
49
51
|
case 5:
|
|
52
|
+
language = getApiQueryLanguage(lang);
|
|
50
53
|
return _context2.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
51
54
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve, reject) {
|
|
52
55
|
var attributeResult;
|
|
@@ -89,7 +92,7 @@ var CategoryClass = /*#__PURE__*/function () {
|
|
|
89
92
|
return _ref.apply(this, arguments);
|
|
90
93
|
};
|
|
91
94
|
}()));
|
|
92
|
-
case
|
|
95
|
+
case 7:
|
|
93
96
|
case "end":
|
|
94
97
|
return _context2.stop();
|
|
95
98
|
}
|
|
@@ -105,30 +108,36 @@ var CategoryClass = /*#__PURE__*/function () {
|
|
|
105
108
|
value: function () {
|
|
106
109
|
var _attributeValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(description_category_id, type_id, attribute_id) {
|
|
107
110
|
var _this2 = this;
|
|
108
|
-
var
|
|
111
|
+
var lang,
|
|
112
|
+
limit,
|
|
113
|
+
last_value_id,
|
|
114
|
+
language,
|
|
109
115
|
_args4 = arguments;
|
|
110
116
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
111
117
|
while (1) switch (_context4.prev = _context4.next) {
|
|
112
118
|
case 0:
|
|
113
|
-
|
|
119
|
+
lang = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : 'ZH_HANS';
|
|
120
|
+
limit = _args4.length > 4 && _args4[4] !== undefined ? _args4[4] : 100;
|
|
121
|
+
last_value_id = _args4.length > 5 && _args4[5] !== undefined ? _args4[5] : 0;
|
|
114
122
|
if (description_category_id) {
|
|
115
|
-
_context4.next =
|
|
123
|
+
_context4.next = 5;
|
|
116
124
|
break;
|
|
117
125
|
}
|
|
118
126
|
return _context4.abrupt("return", Promise.reject(new Error('请输入 descriptionCategoryId')));
|
|
119
|
-
case
|
|
127
|
+
case 5:
|
|
120
128
|
if (type_id) {
|
|
121
|
-
_context4.next =
|
|
129
|
+
_context4.next = 7;
|
|
122
130
|
break;
|
|
123
131
|
}
|
|
124
132
|
return _context4.abrupt("return", Promise.reject(new Error('请输入 typeId')));
|
|
125
|
-
case
|
|
133
|
+
case 7:
|
|
126
134
|
if (attribute_id) {
|
|
127
|
-
_context4.next =
|
|
135
|
+
_context4.next = 9;
|
|
128
136
|
break;
|
|
129
137
|
}
|
|
130
138
|
return _context4.abrupt("return", Promise.reject(new Error('请输入 attribute_id')));
|
|
131
|
-
case
|
|
139
|
+
case 9:
|
|
140
|
+
language = getApiQueryLanguage(lang);
|
|
132
141
|
return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
133
142
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve, reject) {
|
|
134
143
|
var attributeResult;
|
|
@@ -141,8 +150,9 @@ var CategoryClass = /*#__PURE__*/function () {
|
|
|
141
150
|
type_id: type_id,
|
|
142
151
|
attribute_id: attribute_id,
|
|
143
152
|
language: language,
|
|
144
|
-
limit:
|
|
145
|
-
|
|
153
|
+
limit: limit,
|
|
154
|
+
// 2000,
|
|
155
|
+
last_value_id: last_value_id
|
|
146
156
|
}, {
|
|
147
157
|
apiKey: _this2.apiKeyInfo.apiKey,
|
|
148
158
|
apiId: _this2.apiKeyInfo.apiId
|
|
@@ -174,7 +184,7 @@ var CategoryClass = /*#__PURE__*/function () {
|
|
|
174
184
|
return _ref2.apply(this, arguments);
|
|
175
185
|
};
|
|
176
186
|
}()));
|
|
177
|
-
case
|
|
187
|
+
case 11:
|
|
178
188
|
case "end":
|
|
179
189
|
return _context4.stop();
|
|
180
190
|
}
|
|
@@ -185,6 +195,93 @@ var CategoryClass = /*#__PURE__*/function () {
|
|
|
185
195
|
}
|
|
186
196
|
return attributeValue;
|
|
187
197
|
}()
|
|
198
|
+
}, {
|
|
199
|
+
key: "attributeValueSearch",
|
|
200
|
+
value: function () {
|
|
201
|
+
var _attributeValueSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(description_category_id, type_id, attribute_id, value) {
|
|
202
|
+
var _this3 = this;
|
|
203
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
204
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
205
|
+
case 0:
|
|
206
|
+
if (description_category_id) {
|
|
207
|
+
_context6.next = 2;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
return _context6.abrupt("return", Promise.reject(new Error('请输入 descriptionCategoryId')));
|
|
211
|
+
case 2:
|
|
212
|
+
if (type_id) {
|
|
213
|
+
_context6.next = 4;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
return _context6.abrupt("return", Promise.reject(new Error('请输入 typeId')));
|
|
217
|
+
case 4:
|
|
218
|
+
if (attribute_id) {
|
|
219
|
+
_context6.next = 6;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
return _context6.abrupt("return", Promise.reject(new Error('请输入 attribute_id')));
|
|
223
|
+
case 6:
|
|
224
|
+
if (!((value === null || value === void 0 ? void 0 : value.length) < 2)) {
|
|
225
|
+
_context6.next = 8;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
return _context6.abrupt("return", Promise.reject(new Error('搜索内容至少 2 个字符')));
|
|
229
|
+
case 8:
|
|
230
|
+
return _context6.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
231
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(resolve, reject) {
|
|
232
|
+
var attributeResult;
|
|
233
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
234
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
235
|
+
case 0:
|
|
236
|
+
_context5.next = 2;
|
|
237
|
+
return CategoryController.attributeValueSearch({
|
|
238
|
+
description_category_id: description_category_id,
|
|
239
|
+
type_id: type_id,
|
|
240
|
+
attribute_id: attribute_id,
|
|
241
|
+
limit: 100,
|
|
242
|
+
value: value
|
|
243
|
+
}, {
|
|
244
|
+
apiKey: _this3.apiKeyInfo.apiKey,
|
|
245
|
+
apiId: _this3.apiKeyInfo.apiId
|
|
246
|
+
}).catch(function (err) {
|
|
247
|
+
reject(err);
|
|
248
|
+
});
|
|
249
|
+
case 2:
|
|
250
|
+
attributeResult = _context5.sent;
|
|
251
|
+
if (attributeResult) {
|
|
252
|
+
_context5.next = 5;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
return _context5.abrupt("return");
|
|
256
|
+
case 5:
|
|
257
|
+
if (attributeResult.result) {
|
|
258
|
+
_context5.next = 7;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
return _context5.abrupt("return", reject(new Error(attributeResult === null || attributeResult === void 0 ? void 0 : attributeResult.message)));
|
|
262
|
+
case 7:
|
|
263
|
+
return _context5.abrupt("return", resolve(attributeResult.result));
|
|
264
|
+
case 8:
|
|
265
|
+
case "end":
|
|
266
|
+
return _context5.stop();
|
|
267
|
+
}
|
|
268
|
+
}, _callee5);
|
|
269
|
+
}));
|
|
270
|
+
return function (_x14, _x15) {
|
|
271
|
+
return _ref3.apply(this, arguments);
|
|
272
|
+
};
|
|
273
|
+
}()));
|
|
274
|
+
case 9:
|
|
275
|
+
case "end":
|
|
276
|
+
return _context6.stop();
|
|
277
|
+
}
|
|
278
|
+
}, _callee6);
|
|
279
|
+
}));
|
|
280
|
+
function attributeValueSearch(_x10, _x11, _x12, _x13) {
|
|
281
|
+
return _attributeValueSearch.apply(this, arguments);
|
|
282
|
+
}
|
|
283
|
+
return attributeValueSearch;
|
|
284
|
+
}()
|
|
188
285
|
}]);
|
|
189
286
|
return CategoryClass;
|
|
190
287
|
}();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Category } from "../../types/Category";
|
|
2
2
|
export declare function attribute(body: Category.AttributeQuery, options?: Global.RequestOptions): Promise<Category.AttributeApi>;
|
|
3
3
|
export declare function attributeValue(body: Category.AttributeValueQuery, options?: Global.RequestOptions): Promise<Category.AttributeValueApi>;
|
|
4
|
+
export declare function attributeValueSearch(body: Category.AttributeValueSearchQuery, options?: Global.RequestOptions): Promise<Category.AttributeValueSearchApi>;
|
|
@@ -53,4 +53,27 @@ function _attributeValue() {
|
|
|
53
53
|
}, _callee2);
|
|
54
54
|
}));
|
|
55
55
|
return _attributeValue.apply(this, arguments);
|
|
56
|
+
}
|
|
57
|
+
export function attributeValueSearch(_x5, _x6) {
|
|
58
|
+
return _attributeValueSearch.apply(this, arguments);
|
|
59
|
+
}
|
|
60
|
+
function _attributeValueSearch() {
|
|
61
|
+
_attributeValueSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(body, options) {
|
|
62
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
63
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
return _context3.abrupt("return", request("/v1/description-category/attribute/values/search", _objectSpread({
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json'
|
|
69
|
+
},
|
|
70
|
+
data: _objectSpread({}, body)
|
|
71
|
+
}, options || {})));
|
|
72
|
+
case 1:
|
|
73
|
+
case "end":
|
|
74
|
+
return _context3.stop();
|
|
75
|
+
}
|
|
76
|
+
}, _callee3);
|
|
77
|
+
}));
|
|
78
|
+
return _attributeValueSearch.apply(this, arguments);
|
|
56
79
|
}
|
package/dist/types/Category.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare namespace Category {
|
|
|
4
4
|
type_id: number;
|
|
5
5
|
language: Global.ApiLanguage;
|
|
6
6
|
}
|
|
7
|
-
type AttributeType = 'Decimal' | 'String' | 'URL' | 'Integer';
|
|
7
|
+
type AttributeType = 'Decimal' | 'String' | 'URL' | 'Integer' | 'Boolean';
|
|
8
8
|
interface Attribute {
|
|
9
9
|
"id": number;
|
|
10
10
|
"attribute_complex_id": number;
|
|
@@ -46,4 +46,22 @@ export declare namespace Category {
|
|
|
46
46
|
"picture": string;
|
|
47
47
|
"value": string;
|
|
48
48
|
}
|
|
49
|
+
interface AttributeValueSearchQuery {
|
|
50
|
+
description_category_id: number;
|
|
51
|
+
type_id: number;
|
|
52
|
+
attribute_id: number;
|
|
53
|
+
limit: number;
|
|
54
|
+
value: string;
|
|
55
|
+
}
|
|
56
|
+
interface AttributeValueSearchApi {
|
|
57
|
+
result: AttributeValueSearch[];
|
|
58
|
+
success?: boolean;
|
|
59
|
+
message?: string;
|
|
60
|
+
}
|
|
61
|
+
interface AttributeValueSearch {
|
|
62
|
+
id: number;
|
|
63
|
+
info: string;
|
|
64
|
+
picture: string;
|
|
65
|
+
value: string;
|
|
66
|
+
}
|
|
49
67
|
}
|