/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@shopify/shopify-app-session-storage-redis@6.0.0/dist/cjs/redis.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var ShopifyStorageOption,shopifyApi=require("@shopify/shopify-api"),migrations=require("./migrations.js"),redisConnection=require("./redis-connection.js"),redisMigrator=require("./redis-migrator.js");!function(i){i.sessionKeyPrefix="sessionKeyPrefix",i.migratorOptions="migratorOptions",i.onError="onError"}(ShopifyStorageOption||(ShopifyStorageOption={}));const defaultRedisSessionStorageOptions={sessionKeyPrefix:"shopify_sessions",migratorOptions:{migrationDBIdentifier:"migrations"}};class RedisSessionStorage{static withCredentials(i,t,s,e,n){return new RedisSessionStorage(new URL(`redis://${encodeURIComponent(s)}:${encodeURIComponent(e)}@${i}/${t}`),n)}ready;internalInit;options;client;migrator;constructor(i,t={}){const s=Object.keys(ShopifyStorageOption),e=Object.keys(t).filter((i=>!s.includes(i)));if("string"!=typeof i&&!(i instanceof URL)&&e.length>0)throw new Error("Passing a RedisClient instance is not supported with options. Set the options when creating the client instead.");this.options={...defaultRedisSessionStorageOptions,...t},this.internalInit=this.init(i),this.migrator=new redisMigrator.RedisSessionStorageMigrator(this.client,this.options.migratorOptions,migrations.migrationList),this.ready=this.migrator.applyMigrations(this.internalInit)}async storeSession(i){return await this.ready,await this.client.set(i.id,JSON.stringify(i.toPropertyArray(!0))),await this.addKeyToShopList(i),!0}async loadSession(i){await this.ready;let t=await this.client.get(i);if(t)return t=JSON.parse(t),shopifyApi.Session.fromPropertyArray(t,!0)}async deleteSession(i){await this.ready;const t=await this.loadSession(i);return t&&(await this.removeKeyFromShopList(t.shop,i),await this.client.del(i)),!0}async deleteSessions(i){return await this.ready,await Promise.all(i.map((i=>this.deleteSession(i)))),!0}async findSessionsByShop(i){await this.ready;const t=await this.client.get(i);if(!t)return[];const s=JSON.parse(t),e=[];for(const i of s){const t=await this.client.get(i,!1);if(!t)continue;const s=shopifyApi.Session.fromPropertyArray(JSON.parse(t),!0);e.push(s)}return e}async disconnect(){await this.client.disconnect()}async addKeyToShopList(i){const t=i.shop,s=this.client.generateFullKey(i.id),e=await this.client.get(t);if(e){const i=JSON.parse(e);i.includes(s)||(i.push(s),await this.client.set(t,JSON.stringify(i)))}else await this.client.set(t,JSON.stringify([s]))}async removeKeyFromShopList(i,t){const s=i,e=this.client.generateFullKey(t),n=await this.client.get(s);if(n){const i=JSON.parse(n),t=i.indexOf(e);t>-1&&(i.splice(t,1),await this.client.set(s,JSON.stringify(i)))}}async init(i){this.client=new redisConnection.RedisConnection(i,this.options,this.options.sessionKeyPrefix),await this.client.connect()}}exports.RedisSessionStorage=RedisSessionStorage;
//# sourceMappingURL=/sm/b1cf3f340bae1b0d00385b0e558d48ad19430d89e017eb2cb686453c3c87faf0.map