diff --git a/.changeset/eight-wombats-drop.md b/.changeset/eight-wombats-drop.md new file mode 100644 index 0000000..49fcbb9 --- /dev/null +++ b/.changeset/eight-wombats-drop.md @@ -0,0 +1,5 @@ +--- +"@saleor/app-sdk": patch +--- + +Fix serialization of the nested values in the UpstashAPL. diff --git a/src/APL/upstash-apl.test.ts b/src/APL/upstash-apl.test.ts index a812839..03268a4 100644 --- a/src/APL/upstash-apl.test.ts +++ b/src/APL/upstash-apl.test.ts @@ -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", diff --git a/src/APL/upstash-apl.ts b/src/APL/upstash-apl.ts index 5ff7db7..f64e64a 100644 --- a/src/APL/upstash-apl.ts +++ b/src/APL/upstash-apl.ts @@ -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;