diff --git a/src/APL/index.ts b/src/APL/index.ts index 7b1636b..3e06c20 100644 --- a/src/APL/index.ts +++ b/src/APL/index.ts @@ -1,6 +1,6 @@ export * from "./apl"; export * from "./env-apl"; export * from "./file-apl"; +export * from "./redis-apl"; export * from "./saleor-cloud-apl"; export * from "./upstash-apl"; -export * from "./redis-apl" diff --git a/src/APL/redis-apl.ts b/src/APL/redis-apl.ts index 8e0d85e..187efe9 100644 --- a/src/APL/redis-apl.ts +++ b/src/APL/redis-apl.ts @@ -14,18 +14,18 @@ const debug = createAPLDebug("UpstashAPL"); export class RedisAPL implements APL { private client; - private appID; + private appApiBaseUrl; - constructor(redisURL: URL, appID: string) { + constructor(redisURL: URL, appApiBaseUrl: string) { if (!redisURL) throw new Error("No redis url defined"); - if (!appID) throw new Error("The RedisAPL requires to know the app ID beforehand"); - this.appID = appID; + if (!appApiBaseUrl) throw new Error("The RedisAPL requires to know the app ID beforehand"); + this.appApiBaseUrl = appApiBaseUrl; this.client = createClient({ url: redisURL.toString() }); debug("RedisAPL: createClient.url : %j", redisURL.toString()); } private prepareKey(saleorApiUrl: string) { - return `${this.appID}:${saleorApiUrl}`; + return `${this.appApiBaseUrl}:${saleorApiUrl}`; } async get(saleorApiUrl: string): Promise { @@ -34,16 +34,15 @@ export class RedisAPL implements APL { const res = await this.client.get(this.prepareKey(saleorApiUrl)); debug("RedisAPL: get - received: %j", res); if (res) { + await this.client.disconnect(); return JSON.parse(res) as AuthData; } + await this.client.disconnect(); return undefined; - } catch (e) { await this.client.disconnect(); return undefined; } - - await this.client.disconnect(); } async set(authData: AuthData): Promise {