Skip to content

Commit

Permalink
chore(utils): soap support return raw
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjue666 committed Jun 4, 2024
1 parent d0b0d90 commit afdc77a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/santai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cn-international-express-sdk/santai",
"version": "3.0.2",
"version": "3.0.4",
"types": "./dist/types/index.d.ts",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand All @@ -13,7 +13,7 @@
"upgrade": "modern upgrade"
},
"dependencies": {
"@cn-international-express-sdk/utils": "workspace:*"
"@cn-international-express-sdk/utils": "^0.1.3"
},
"devDependencies": {
"@modern-js/eslint-config": "2.42.0",
Expand Down
32 changes: 20 additions & 12 deletions packages/santai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export class SanTai {
this.config = config;
}

async getRates(sendData: Recordable) {
const { country, state, zip_code } = sendData;
let { weight, length, width, height } = sendData;
async getRates(obj: Recordable) {
const { country, state, zip_code } = obj;
let { weight, length, width, height } = obj;
width = width || '10';
height = height || '10';
length = length || '10';
weight = weight || 1;
const obj = {
const sendData = {
ratesRequestInfo: {
country,
state,
Expand All @@ -35,23 +35,31 @@ export class SanTai {
priceType: '1',
},
};
const result = await promiseStrongSoap(this.url, 'getRates', obj);
const result = await promiseStrongSoap(
this.url,
'getRates',
Object.assign(sendData, this.getCommonObj()),
true,
);
return result;
}

async genRequest<T>(action: string, sendData: Recordable) {
const commonObj = {
const res = await promiseSoap<T>(
this.url,
action,
Object.assign(sendData, this.getCommonObj()),
);
return res;
}

getCommonObj() {
return {
HeaderRequest: {
appKey: this.config.app_key,
token: this.config.app_token,
userId: this.config.user_id,
},
};
const res = await promiseSoap<T>(
this.url,
action,
Object.assign(sendData, commonObj),
);
return res;
}
}
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cn-international-express-sdk/utils",
"version": "4.0.0",
"version": "4.0.1",
"types": "./dist/types/index.d.ts",
"main": "./dist/lib/index.js",
"module": "./dist/es/index.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/fetch/soap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ export function promiseStrongSoap<T>(
url: string,
action: string,
obj: Recordable,
isRaw = false, // 是否返回原始数据
): Promise<T> {
return new Promise(resolve => {
strongSoap.createClient(url, {}, function (err: any, client: any) {
const method = client[action];
method(obj, (err: any, result: any, envelope: any) => {
resolve(parseXml(envelope));
resolve(isRaw ? envelope : parseXml(envelope));
});
});
});
Expand Down
17 changes: 15 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit afdc77a

Please sign in to comment.