Skip to content

Commit bba6da2

Browse files
committed
fix(fraudlabspro): address coderabbit review comments
1 parent 3c832fb commit bba6da2

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

components/fraudlabs_pro/actions/custom-api-call/custom-api-call.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,20 @@ export default {
5353
requestBody,
5454
} = this;
5555

56-
if (!relativeUrl || !relativeUrl.startsWith("/")) {
56+
const path = relativeUrl?.trim();
57+
if (!path || !path.startsWith("/")) {
5758
throw new ConfigurationError("**Relative URL** must start with `/`, for example `/order/screen`.");
5859
}
5960

6061
const response = await this.fraudlabsProApp._apiRequest({
6162
$,
6263
method: requestMethod,
63-
path: relativeUrl,
64+
path,
6465
params,
6566
data: requestBody,
6667
});
6768

68-
$.export("$summary", `Successfully called \`${requestMethod.toUpperCase()} ${relativeUrl}\``);
69+
$.export("$summary", `Successfully called \`${requestMethod.toUpperCase()} ${path}\``);
6970
return response;
7071
},
7172
};

components/fraudlabs_pro/actions/send-sms-verification/send-sms-verification.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default {
5353

5454
const response = await this.fraudlabsProApp.sendSmsVerification({
5555
$,
56-
params: {
56+
data: {
5757
tel,
5858
mesg,
5959
...(format && {

components/fraudlabs_pro/fraudlabs_pro.app.mjs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,42 @@ export default {
6565
_apiRequest({
6666
$ = this, method = "get", path, params, data, ...args
6767
}) {
68-
const fields = {
68+
const auth = {
6969
format: "json",
70-
...params,
71-
...data,
7270
key: this.$auth.api_key,
7371
};
74-
if (FORM_BODY_METHODS.includes(method.toLowerCase())) {
72+
const isFormBody = FORM_BODY_METHODS.includes(method.toLowerCase());
73+
// `params` always go on the query string. For write verbs `data` is the
74+
// form body; for read verbs there is no body, so fold `data` into the query.
75+
const queryParams = isFormBody
76+
? {
77+
...auth,
78+
...params,
79+
}
80+
: {
81+
...auth,
82+
...params,
83+
...data,
84+
};
85+
if (isFormBody) {
7586
return axios($, {
7687
url: `${this._apiBaseUrl()}${path}`,
7788
method,
89+
params: queryParams,
7890
headers: {
7991
"Content-Type": "application/x-www-form-urlencoded",
8092
},
81-
data: new URLSearchParams(fields).toString(),
93+
data: new URLSearchParams({
94+
...auth,
95+
...data,
96+
}).toString(),
8297
...args,
8398
});
8499
}
85100
return axios($, {
86101
url: `${this._apiBaseUrl()}${path}`,
87102
method,
88-
params: fields,
103+
params: queryParams,
89104
...args,
90105
});
91106
},

components/fraudlabs_pro/sources/status-changed/status-changed.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export default {
8686
this.http.respond({
8787
status: 200,
8888
body: {
89-
message: "Success",
90-
},
89+
message: "Success",
90+
},
9191
});
9292
},
9393
};

0 commit comments

Comments
 (0)