Skip to content

Commit

Permalink
Ensure API returns predefined types #4
Browse files Browse the repository at this point in the history
  • Loading branch information
moh3a committed Sep 21, 2023
1 parent 1b0b35c commit e1b2897
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ae_sdk

## 0.4.9

### Patch Changes

- Ensure API returns predefined types #4

## 0.4.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ae_sdk",
"version": "0.4.8",
"version": "0.4.9",
"description": "A simple SDK for Aliexpress (dropshipping and affiliate) APIs.",
"private": false,
"main": "./dist/index.js",
Expand Down
3 changes: 2 additions & 1 deletion src/types/ae.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
DS_Shipping_Info_Result,
DS_Tracking_Info_Params,
DS_Tracking_Info_Result,
DS_Categories_Result,
} from ".";

export type AE_API_NAMES =
Expand Down Expand Up @@ -212,7 +213,7 @@ export type AliexpressMethod<T extends AE_API_NAMES> =
? {
method: T;
params: Affiliate_Categories_Params;
result: Affiliate_Categories_Result;
result: DS_Categories_Result;
}
: T extends "aliexpress.ds.commissionorder.listbyindex"
? {
Expand Down
15 changes: 15 additions & 0 deletions src/types/ds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
YES_NO,
AE_Sort_Filter,
AE_Sort_Promo_Filter,
Affiliate_Categories,
} from ".";
/**
*
Expand Down Expand Up @@ -674,3 +675,17 @@ export type DS_Tracking_Info_Response =
export interface DS_Tracking_Info_Result {
aliexpress_logistics_ds_trackinginfo_query_response: DS_Tracking_Info_Response;
}

/**
* DROPSHIPPER API
* CATEGORIES
*/
export interface DS_Categories_Result {
aliexpress_ds_category_get_response: {
resp_result: {
resp_code: number;
resp_msg: string;
result: Affiliate_Categories;
};
};
}
30 changes: 24 additions & 6 deletions src/utils/ds_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export class DropshipperClient extends AESystemClient {
data.result.aeop_freight_calculate_result_for_buyer_d_t_o_list = (
data.result.aeop_freight_calculate_result_for_buyer_d_t_o_list as any
).aeop_freight_calculate_result_for_buyer_dto;
delete (
data.result.aeop_freight_calculate_result_for_buyer_d_t_o_list as any
).aeop_freight_calculate_result_for_buyer_dto;
}
}

Expand Down Expand Up @@ -144,13 +141,19 @@ export class DropshipperClient extends AESystemClient {

let data = response.data.aliexpress_trade_ds_order_get_response.result;

if ((data.child_order_list as any).ae_child_order_info) {
if (
data.child_order_list &&
(data.child_order_list as any).ae_child_order_info
) {
data.child_order_list = (
data.child_order_list as any
).ae_child_order_info;
}

if ((data.logistics_info_list as any).ae_order_logistics_info) {
if (
data.logistics_info_list &&
(data.logistics_info_list as any).ae_order_logistics_info
) {
data.logistics_info_list = (
data.logistics_info_list as any
).ae_order_logistics_info;
Expand All @@ -171,7 +174,22 @@ export class DropshipperClient extends AESystemClient {
* @link https://open.aliexpress.com/doc/api.htm#/api?cid=21038&path=aliexpress.ds.category.get&methodType=GET/POST
*/
async getCategories(args: Affiliate_Categories_Params) {
return await this.execute("aliexpress.ds.category.get", args);
let response = await this.execute("aliexpress.ds.category.get", args);

if (
response.ok &&
(
response.data.aliexpress_ds_category_get_response.resp_result.result
.categories as any
).category
)
response.data.aliexpress_ds_category_get_response.resp_result.result.categories =
(
response.data.aliexpress_ds_category_get_response.resp_result.result
.categories as any
).category;

return response;
}

/**
Expand Down

0 comments on commit e1b2897

Please sign in to comment.