ozon-api 1.0.2 → 1.0.3

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.
@@ -2,6 +2,7 @@ import { Category } from "../../types/Category";
2
2
  declare class CategoryClass {
3
3
  private readonly apiKeyInfo;
4
4
  constructor(apiId: string, apiKey: string);
5
+ tree(lang?: Global.ApiLanguage | string): Promise<Category.Tree[]>;
5
6
  attribute(description_category_id: number, type_id: number, lang?: Global.ApiLanguage | string): Promise<Category.Attribute[]>;
6
7
  attributeValue(query: Category.AttributeValueApiQuery): Promise<Category.AttributeValueApi>;
7
8
  attributeValueSearch(description_category_id: number, type_id: number, attribute_id: number, value: string): Promise<Category.AttributeValue[]>;
@@ -25,12 +25,11 @@ var CategoryClass = /*#__PURE__*/function () {
25
25
  };
26
26
  console.log('categoryClass constructor:', this.apiKeyInfo);
27
27
  }
28
- // 类别特征列表
29
- // https://api-seller.ozon.ru/v1/description-category/attribute
28
+ // 所有
30
29
  _createClass(CategoryClass, [{
31
- key: "attribute",
30
+ key: "tree",
32
31
  value: function () {
33
- var _attribute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(description_category_id, type_id) {
32
+ var _tree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
34
33
  var _this = this;
35
34
  var lang,
36
35
  language,
@@ -38,19 +37,7 @@ var CategoryClass = /*#__PURE__*/function () {
38
37
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
39
38
  while (1) switch (_context2.prev = _context2.next) {
40
39
  case 0:
41
- lang = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : 'ZH_HANS';
42
- if (description_category_id) {
43
- _context2.next = 3;
44
- break;
45
- }
46
- return _context2.abrupt("return", Promise.reject(new Error('请输入 descriptionCategoryId')));
47
- case 3:
48
- if (type_id) {
49
- _context2.next = 5;
50
- break;
51
- }
52
- return _context2.abrupt("return", Promise.reject(new Error('请输入 typeId')));
53
- case 5:
40
+ lang = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : 'ZH_HANS';
54
41
  language = getApiQueryLanguage(lang);
55
42
  return _context2.abrupt("return", new Promise( /*#__PURE__*/function () {
56
43
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve, reject) {
@@ -59,9 +46,7 @@ var CategoryClass = /*#__PURE__*/function () {
59
46
  while (1) switch (_context.prev = _context.next) {
60
47
  case 0:
61
48
  _context.next = 2;
62
- return CategoryController.attribute({
63
- description_category_id: description_category_id,
64
- type_id: type_id,
49
+ return CategoryController.tree({
65
50
  language: language
66
51
  }, {
67
52
  apiKey: _this.apiKeyInfo.apiKey,
@@ -84,49 +69,47 @@ var CategoryClass = /*#__PURE__*/function () {
84
69
  }
85
70
  }, _callee);
86
71
  }));
87
- return function (_x3, _x4) {
72
+ return function (_x, _x2) {
88
73
  return _ref.apply(this, arguments);
89
74
  };
90
75
  }()));
91
- case 7:
76
+ case 3:
92
77
  case "end":
93
78
  return _context2.stop();
94
79
  }
95
80
  }, _callee2);
96
81
  }));
97
- function attribute(_x, _x2) {
98
- return _attribute.apply(this, arguments);
82
+ function tree() {
83
+ return _tree.apply(this, arguments);
99
84
  }
100
- return attribute;
101
- }()
85
+ return tree;
86
+ }() // 类别特征列表
87
+ // https://api-seller.ozon.ru/v1/description-category/attribute
102
88
  }, {
103
- key: "attributeValue",
89
+ key: "attribute",
104
90
  value: function () {
105
- var _attributeValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(query) {
91
+ var _attribute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(description_category_id, type_id) {
106
92
  var _this2 = this;
107
- var language;
93
+ var lang,
94
+ language,
95
+ _args4 = arguments;
108
96
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
109
97
  while (1) switch (_context4.prev = _context4.next) {
110
98
  case 0:
111
- if (query !== null && query !== void 0 && query.description_category_id) {
112
- _context4.next = 2;
113
- break;
114
- }
115
- return _context4.abrupt("return", Promise.reject(new Error('请输入 description_category_id')));
116
- case 2:
117
- if (query !== null && query !== void 0 && query.type_id) {
118
- _context4.next = 4;
99
+ lang = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : 'ZH_HANS';
100
+ if (description_category_id) {
101
+ _context4.next = 3;
119
102
  break;
120
103
  }
121
- return _context4.abrupt("return", Promise.reject(new Error('请输入 type_id')));
122
- case 4:
123
- if (query !== null && query !== void 0 && query.attribute_id) {
124
- _context4.next = 6;
104
+ return _context4.abrupt("return", Promise.reject(new Error('请输入 descriptionCategoryId')));
105
+ case 3:
106
+ if (type_id) {
107
+ _context4.next = 5;
125
108
  break;
126
109
  }
127
- return _context4.abrupt("return", Promise.reject(new Error('请输入 attribute_id')));
128
- case 6:
129
- language = getApiQueryLanguage(query === null || query === void 0 ? void 0 : query.language);
110
+ return _context4.abrupt("return", Promise.reject(new Error('请输入 typeId')));
111
+ case 5:
112
+ language = getApiQueryLanguage(lang);
130
113
  return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
131
114
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve, reject) {
132
115
  var attributeResult;
@@ -134,9 +117,11 @@ var CategoryClass = /*#__PURE__*/function () {
134
117
  while (1) switch (_context3.prev = _context3.next) {
135
118
  case 0:
136
119
  _context3.next = 2;
137
- return CategoryController.attributeValue(_objectSpread(_objectSpread({}, query), {}, {
120
+ return CategoryController.attribute({
121
+ description_category_id: description_category_id,
122
+ type_id: type_id,
138
123
  language: language
139
- }), {
124
+ }, {
140
125
  apiKey: _this2.apiKeyInfo.apiKey,
141
126
  apiId: _this2.apiKeyInfo.apiId
142
127
  }).catch(function (err) {
@@ -157,53 +142,49 @@ var CategoryClass = /*#__PURE__*/function () {
157
142
  }
158
143
  }, _callee3);
159
144
  }));
160
- return function (_x6, _x7) {
145
+ return function (_x5, _x6) {
161
146
  return _ref2.apply(this, arguments);
162
147
  };
163
148
  }()));
164
- case 8:
149
+ case 7:
165
150
  case "end":
166
151
  return _context4.stop();
167
152
  }
168
153
  }, _callee4);
169
154
  }));
170
- function attributeValue(_x5) {
171
- return _attributeValue.apply(this, arguments);
155
+ function attribute(_x3, _x4) {
156
+ return _attribute.apply(this, arguments);
172
157
  }
173
- return attributeValue;
158
+ return attribute;
174
159
  }()
175
160
  }, {
176
- key: "attributeValueSearch",
161
+ key: "attributeValue",
177
162
  value: function () {
178
- var _attributeValueSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(description_category_id, type_id, attribute_id, value) {
163
+ var _attributeValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(query) {
179
164
  var _this3 = this;
165
+ var language;
180
166
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
181
167
  while (1) switch (_context6.prev = _context6.next) {
182
168
  case 0:
183
- if (description_category_id) {
169
+ if (query !== null && query !== void 0 && query.description_category_id) {
184
170
  _context6.next = 2;
185
171
  break;
186
172
  }
187
- return _context6.abrupt("return", Promise.reject(new Error('请输入 descriptionCategoryId')));
173
+ return _context6.abrupt("return", Promise.reject(new Error('请输入 description_category_id')));
188
174
  case 2:
189
- if (type_id) {
175
+ if (query !== null && query !== void 0 && query.type_id) {
190
176
  _context6.next = 4;
191
177
  break;
192
178
  }
193
- return _context6.abrupt("return", Promise.reject(new Error('请输入 typeId')));
179
+ return _context6.abrupt("return", Promise.reject(new Error('请输入 type_id')));
194
180
  case 4:
195
- if (attribute_id) {
181
+ if (query !== null && query !== void 0 && query.attribute_id) {
196
182
  _context6.next = 6;
197
183
  break;
198
184
  }
199
185
  return _context6.abrupt("return", Promise.reject(new Error('请输入 attribute_id')));
200
186
  case 6:
201
- if (!((value === null || value === void 0 ? void 0 : value.length) < 2)) {
202
- _context6.next = 8;
203
- break;
204
- }
205
- return _context6.abrupt("return", Promise.reject(new Error('搜索内容至少 2 个字符')));
206
- case 8:
187
+ language = getApiQueryLanguage(query === null || query === void 0 ? void 0 : query.language);
207
188
  return _context6.abrupt("return", new Promise( /*#__PURE__*/function () {
208
189
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(resolve, reject) {
209
190
  var attributeResult;
@@ -211,13 +192,9 @@ var CategoryClass = /*#__PURE__*/function () {
211
192
  while (1) switch (_context5.prev = _context5.next) {
212
193
  case 0:
213
194
  _context5.next = 2;
214
- return CategoryController.attributeValueSearch({
215
- description_category_id: description_category_id,
216
- type_id: type_id,
217
- attribute_id: attribute_id,
218
- limit: 100,
219
- value: value
220
- }, {
195
+ return CategoryController.attributeValue(_objectSpread(_objectSpread({}, query), {}, {
196
+ language: language
197
+ }), {
221
198
  apiKey: _this3.apiKeyInfo.apiKey,
222
199
  apiId: _this3.apiKeyInfo.apiId
223
200
  }).catch(function (err) {
@@ -238,17 +215,98 @@ var CategoryClass = /*#__PURE__*/function () {
238
215
  }
239
216
  }, _callee5);
240
217
  }));
241
- return function (_x12, _x13) {
218
+ return function (_x8, _x9) {
242
219
  return _ref3.apply(this, arguments);
243
220
  };
244
221
  }()));
245
- case 9:
222
+ case 8:
246
223
  case "end":
247
224
  return _context6.stop();
248
225
  }
249
226
  }, _callee6);
250
227
  }));
251
- function attributeValueSearch(_x8, _x9, _x10, _x11) {
228
+ function attributeValue(_x7) {
229
+ return _attributeValue.apply(this, arguments);
230
+ }
231
+ return attributeValue;
232
+ }()
233
+ }, {
234
+ key: "attributeValueSearch",
235
+ value: function () {
236
+ var _attributeValueSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(description_category_id, type_id, attribute_id, value) {
237
+ var _this4 = this;
238
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
239
+ while (1) switch (_context8.prev = _context8.next) {
240
+ case 0:
241
+ if (description_category_id) {
242
+ _context8.next = 2;
243
+ break;
244
+ }
245
+ return _context8.abrupt("return", Promise.reject(new Error('请输入 descriptionCategoryId')));
246
+ case 2:
247
+ if (type_id) {
248
+ _context8.next = 4;
249
+ break;
250
+ }
251
+ return _context8.abrupt("return", Promise.reject(new Error('请输入 typeId')));
252
+ case 4:
253
+ if (attribute_id) {
254
+ _context8.next = 6;
255
+ break;
256
+ }
257
+ return _context8.abrupt("return", Promise.reject(new Error('请输入 attribute_id')));
258
+ case 6:
259
+ if (!((value === null || value === void 0 ? void 0 : value.length) < 2)) {
260
+ _context8.next = 8;
261
+ break;
262
+ }
263
+ return _context8.abrupt("return", Promise.reject(new Error('搜索内容至少 2 个字符')));
264
+ case 8:
265
+ return _context8.abrupt("return", new Promise( /*#__PURE__*/function () {
266
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(resolve, reject) {
267
+ var attributeResult;
268
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
269
+ while (1) switch (_context7.prev = _context7.next) {
270
+ case 0:
271
+ _context7.next = 2;
272
+ return CategoryController.attributeValueSearch({
273
+ description_category_id: description_category_id,
274
+ type_id: type_id,
275
+ attribute_id: attribute_id,
276
+ limit: 100,
277
+ value: value
278
+ }, {
279
+ apiKey: _this4.apiKeyInfo.apiKey,
280
+ apiId: _this4.apiKeyInfo.apiId
281
+ }).catch(function (err) {
282
+ reject(err);
283
+ });
284
+ case 2:
285
+ attributeResult = _context7.sent;
286
+ if (attributeResult) {
287
+ _context7.next = 5;
288
+ break;
289
+ }
290
+ return _context7.abrupt("return");
291
+ case 5:
292
+ return _context7.abrupt("return", resolve(attributeResult));
293
+ case 6:
294
+ case "end":
295
+ return _context7.stop();
296
+ }
297
+ }, _callee7);
298
+ }));
299
+ return function (_x14, _x15) {
300
+ return _ref4.apply(this, arguments);
301
+ };
302
+ }()));
303
+ case 9:
304
+ case "end":
305
+ return _context8.stop();
306
+ }
307
+ }, _callee8);
308
+ }));
309
+ function attributeValueSearch(_x10, _x11, _x12, _x13) {
252
310
  return _attributeValueSearch.apply(this, arguments);
253
311
  }
254
312
  return attributeValueSearch;
@@ -1,4 +1,7 @@
1
1
  import { Category } from "../../types/Category";
2
+ export declare function tree(body: {
3
+ language: Global.ApiLanguage;
4
+ }, options?: Global.RequestOptions): Promise<Category.Tree[]>;
2
5
  export declare function attribute(body: Category.AttributeQuery, options?: Global.RequestOptions): Promise<Category.Attribute[]>;
3
6
  export declare function attributeValue(body: Category.AttributeValueApiQuery, options?: Global.RequestOptions): Promise<Category.AttributeValueApi>;
4
7
  export declare function attributeValueSearch(body: Category.AttributeValueSearchQuery, options?: Global.RequestOptions): Promise<Category.AttributeValueSearch[]>;
@@ -8,15 +8,15 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
9
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
10
  import request from "../../lib/Request";
11
- export function attribute(_x, _x2) {
12
- return _attribute.apply(this, arguments);
11
+ export function tree(_x, _x2) {
12
+ return _tree.apply(this, arguments);
13
13
  }
14
- function _attribute() {
15
- _attribute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(body, options) {
14
+ function _tree() {
15
+ _tree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(body, options) {
16
16
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17
17
  while (1) switch (_context.prev = _context.next) {
18
18
  case 0:
19
- return _context.abrupt("return", request("/v1/description-category/attribute", _objectSpread({
19
+ return _context.abrupt("return", request("/v1/description-category/tree", _objectSpread({
20
20
  method: 'POST',
21
21
  headers: {
22
22
  'Content-Type': 'application/json'
@@ -29,17 +29,17 @@ function _attribute() {
29
29
  }
30
30
  }, _callee);
31
31
  }));
32
- return _attribute.apply(this, arguments);
32
+ return _tree.apply(this, arguments);
33
33
  }
34
- export function attributeValue(_x3, _x4) {
35
- return _attributeValue.apply(this, arguments);
34
+ export function attribute(_x3, _x4) {
35
+ return _attribute.apply(this, arguments);
36
36
  }
37
- function _attributeValue() {
38
- _attributeValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(body, options) {
37
+ function _attribute() {
38
+ _attribute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(body, options) {
39
39
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
40
40
  while (1) switch (_context2.prev = _context2.next) {
41
41
  case 0:
42
- return _context2.abrupt("return", request("/v1/description-category/attribute/values", _objectSpread({
42
+ return _context2.abrupt("return", request("/v1/description-category/attribute", _objectSpread({
43
43
  method: 'POST',
44
44
  headers: {
45
45
  'Content-Type': 'application/json'
@@ -52,17 +52,17 @@ function _attributeValue() {
52
52
  }
53
53
  }, _callee2);
54
54
  }));
55
- return _attributeValue.apply(this, arguments);
55
+ return _attribute.apply(this, arguments);
56
56
  }
57
- export function attributeValueSearch(_x5, _x6) {
58
- return _attributeValueSearch.apply(this, arguments);
57
+ export function attributeValue(_x5, _x6) {
58
+ return _attributeValue.apply(this, arguments);
59
59
  }
60
- function _attributeValueSearch() {
61
- _attributeValueSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(body, options) {
60
+ function _attributeValue() {
61
+ _attributeValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(body, options) {
62
62
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
63
63
  while (1) switch (_context3.prev = _context3.next) {
64
64
  case 0:
65
- return _context3.abrupt("return", request("/v1/description-category/attribute/values/search", _objectSpread({
65
+ return _context3.abrupt("return", request("/v1/description-category/attribute/values", _objectSpread({
66
66
  method: 'POST',
67
67
  headers: {
68
68
  'Content-Type': 'application/json'
@@ -75,5 +75,28 @@ function _attributeValueSearch() {
75
75
  }
76
76
  }, _callee3);
77
77
  }));
78
+ return _attributeValue.apply(this, arguments);
79
+ }
80
+ export function attributeValueSearch(_x7, _x8) {
81
+ return _attributeValueSearch.apply(this, arguments);
82
+ }
83
+ function _attributeValueSearch() {
84
+ _attributeValueSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(body, options) {
85
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
86
+ while (1) switch (_context4.prev = _context4.next) {
87
+ case 0:
88
+ return _context4.abrupt("return", request("/v1/description-category/attribute/values/search", _objectSpread({
89
+ method: 'POST',
90
+ headers: {
91
+ 'Content-Type': 'application/json'
92
+ },
93
+ data: _objectSpread({}, body)
94
+ }, options || {})));
95
+ case 1:
96
+ case "end":
97
+ return _context4.stop();
98
+ }
99
+ }, _callee4);
100
+ }));
78
101
  return _attributeValueSearch.apply(this, arguments);
79
102
  }
@@ -1,4 +1,12 @@
1
1
  export declare namespace Category {
2
+ interface Tree {
3
+ "description_category_id": 0;
4
+ "category_name": "string";
5
+ "disabled": boolean;
6
+ children: Tree[];
7
+ type_id: number;
8
+ type_name: string;
9
+ }
2
10
  interface AttributeQuery {
3
11
  description_category_id: number;
4
12
  type_id: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ozon-api",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "OZON Seller API",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",