Skip to content

Commit

Permalink
Fix data serialization in the UpstashAPL (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofwolski authored Apr 12, 2023
1 parent 5057d34 commit 5a68bec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-wombats-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@saleor/app-sdk": patch
---

Fix serialization of the nested values in the UpstashAPL.
3 changes: 1 addition & 2 deletions src/APL/upstash-apl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/APL/upstash-apl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5a68bec

Please sign in to comment.