Fix data serialization in the UpstashAPL (#228)
This commit is contained in:
parent
5057d3491e
commit
5a68bec557
3 changed files with 12 additions and 8 deletions
5
.changeset/eight-wombats-drop.md
Normal file
5
.changeset/eight-wombats-drop.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@saleor/app-sdk": patch
|
||||
---
|
||||
|
||||
Fix serialization of the nested values in the UpstashAPL.
|
|
@ -57,8 +57,7 @@ describe("APL", () => {
|
|||
"https://example.com",
|
||||
|
||||
{
|
||||
// eslint-disable-next-line quotes
|
||||
body: `["SET", "${stubAuthData.saleorApiUrl}", "${JSON.stringify(stubAuthData)}"]`,
|
||||
body: JSON.stringify(["SET", stubAuthData.saleorApiUrl, JSON.stringify(stubAuthData)]),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer token",
|
||||
|
|
|
@ -54,7 +54,7 @@ export class UpstashAPL implements APL {
|
|||
this.restToken = restToken;
|
||||
}
|
||||
|
||||
private async upstashRequest(requestBody: string) {
|
||||
private async upstashRequest(request: string[]) {
|
||||
debug("Sending request to Upstash");
|
||||
if (!this.restURL || !this.restToken) {
|
||||
throw new Error(
|
||||
|
@ -66,7 +66,7 @@ export class UpstashAPL implements APL {
|
|||
response = await fetch(this.restURL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.restToken}` },
|
||||
body: requestBody,
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
} catch (error) {
|
||||
debug("Error during sending the data:", error);
|
||||
|
@ -97,17 +97,17 @@ export class UpstashAPL implements APL {
|
|||
});
|
||||
|
||||
const data = JSON.stringify(authData);
|
||||
await this.upstashRequest(`["SET", "${authData.saleorApiUrl}", "${data}"]`);
|
||||
await this.upstashRequest(["SET", authData.saleorApiUrl, data]);
|
||||
}
|
||||
|
||||
private async deleteDataFromUpstash(saleorApiUrl: string) {
|
||||
await this.upstashRequest(`["DEL", "${saleorApiUrl}"]`);
|
||||
await this.upstashRequest(["DEL", saleorApiUrl]);
|
||||
}
|
||||
|
||||
private async fetchDataFromUpstash(saleorApiUrl: string) {
|
||||
const result = await this.upstashRequest(`["GET", "${saleorApiUrl}"]`);
|
||||
const result = await this.upstashRequest(["GET", saleorApiUrl]);
|
||||
if (result) {
|
||||
const authData = JSON.parse(result);
|
||||
const authData = JSON.parse(result) as AuthData;
|
||||
return authData;
|
||||
}
|
||||
return undefined;
|
||||
|
|
Loading…
Reference in a new issue