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5.48.0.\n * Original file: /npm/@shopify/shopify-app-session-storage-redis@8.0.0/dist/cjs/redis.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import {RedisClientOptions, createClient} from 'redis';\nimport {Session} from '@shopify/shopify-api';\nimport {\n  SessionStorage,\n  SessionStorageMigratorOptions,\n  SessionStorageMigrator,\n} from '@shopify/shopify-app-session-storage';\n\nimport {migrationList} from './migrations';\nimport {RedisConnection} from './redis-connection';\nimport {RedisSessionStorageMigrator} from './redis-migrator';\n\ntype RedisClient = ReturnType<typeof createClient>;\n\n/* eslint-disable @shopify/typescript-prefer-pascal-case-enums */\nenum ShopifyStorageOption {\n  sessionKeyPrefix = 'sessionKeyPrefix',\n  migratorOptions = 'migratorOptions',\n  onError = 'onError',\n}\n/* eslint-enable @shopify/typescript-prefer-pascal-case-enums */\n\nexport interface RedisSessionStorageOptions extends RedisClientOptions {\n  [ShopifyStorageOption.sessionKeyPrefix]: string;\n  [ShopifyStorageOption.migratorOptions]?: SessionStorageMigratorOptions;\n  [ShopifyStorageOption.onError]?: (...args: any[]) => void;\n}\n\nconst defaultRedisSessionStorageOptions: RedisSessionStorageOptions = {\n  sessionKeyPrefix: 'shopify_sessions',\n  migratorOptions: {\n    migrationDBIdentifier: 'migrations',\n  },\n};\n\nexport class RedisSessionStorage implements SessionStorage {\n  static withCredentials(\n    host: string,\n    db: number,\n    username: string,\n    password: string,\n    opts: Partial<RedisSessionStorageOptions>,\n  ) {\n    return new RedisSessionStorage(\n      new URL(\n        `redis://${encodeURIComponent(username)}:${encodeURIComponent(\n          password,\n        )}@${host}/${db}`,\n      ),\n      opts,\n    );\n  }\n\n  public readonly ready: Promise<void>;\n  private internalInit: Promise<void>;\n  private options: RedisSessionStorageOptions;\n  private client: RedisConnection;\n  private migrator: SessionStorageMigrator;\n\n  constructor(\n    urlOrClient: URL | string | RedisClient,\n    opts: Partial<RedisSessionStorageOptions> = {},\n  ) {\n    const allowedClientKeys = Object.keys(ShopifyStorageOption);\n    const disallowedClientKeys = Object.keys(opts).filter(\n      (key) => !allowedClientKeys.includes(key),\n    );\n\n    if (\n      typeof urlOrClient !== 'string' &&\n      !(urlOrClient instanceof URL) &&\n      disallowedClientKeys.length > 0\n    ) {\n      throw new Error(\n        'Passing a RedisClient instance is not supported with options. Set the options when creating the client ' +\n          'instead.',\n      );\n    }\n\n    this.options = {...defaultRedisSessionStorageOptions, ...opts};\n    this.internalInit = this.init(urlOrClient);\n    this.migrator = new RedisSessionStorageMigrator(\n      this.client,\n      this.options.migratorOptions,\n      migrationList,\n    );\n    this.ready = this.migrator.applyMigrations(this.internalInit);\n  }\n\n  public async storeSession(session: Session): Promise<boolean> {\n    await this.ready;\n\n    await this.client.set(\n      session.id,\n      JSON.stringify(session.toPropertyArray(true)),\n    );\n    await this.addKeyToShopList(session);\n    return true;\n  }\n\n  public async loadSession(id: string): Promise<Session | undefined> {\n    await this.ready;\n\n    let rawResult: any = await this.client.get(id);\n\n    if (!rawResult) return undefined;\n    rawResult = JSON.parse(rawResult);\n\n    return Session.fromPropertyArray(rawResult, true);\n  }\n\n  public async deleteSession(id: string): Promise<boolean> {\n    await this.ready;\n    const session = await this.loadSession(id);\n    if (session) {\n      await this.removeKeyFromShopList(session.shop, id);\n      await this.client.del(id);\n    }\n    return true;\n  }\n\n  public async deleteSessions(ids: string[]): Promise<boolean> {\n    await this.ready;\n    await Promise.all(ids.map((id) => this.deleteSession(id)));\n    return true;\n  }\n\n  public async findSessionsByShop(shop: string): Promise<Session[]> {\n    await this.ready;\n\n    const idKeysArrayString = await this.client.get(shop);\n    if (!idKeysArrayString) return [];\n\n    const idKeysArray = JSON.parse(idKeysArrayString);\n    const results: Session[] = [];\n    for (const idKey of idKeysArray) {\n      const rawResult = await this.client.get(idKey, false);\n      if (!rawResult) continue;\n\n      const session = Session.fromPropertyArray(JSON.parse(rawResult), true);\n      results.push(session);\n    }\n\n    return results;\n  }\n\n  public async disconnect(): Promise<void> {\n    await this.client.disconnect();\n  }\n\n  private async addKeyToShopList(session: Session) {\n    const shopKey = session.shop;\n    const idKey = this.client.generateFullKey(session.id);\n    const idKeysArrayString = await this.client.get(shopKey);\n\n    if (idKeysArrayString) {\n      const idKeysArray = JSON.parse(idKeysArrayString);\n\n      if (!idKeysArray.includes(idKey)) {\n        idKeysArray.push(idKey);\n        await this.client.set(shopKey, JSON.stringify(idKeysArray));\n      }\n    } else {\n      await this.client.set(shopKey, JSON.stringify([idKey]));\n    }\n  }\n\n  private async removeKeyFromShopList(shop: string, id: string) {\n    const shopKey = shop;\n    const idKey = this.client.generateFullKey(id);\n    const idKeysArrayString = await this.client.get(shopKey);\n\n    if (idKeysArrayString) {\n      const idKeysArray = JSON.parse(idKeysArrayString);\n      const index = idKeysArray.indexOf(idKey);\n\n      if (index > -1) {\n        idKeysArray.splice(index, 1);\n        await this.client.set(shopKey, JSON.stringify(idKeysArray));\n      }\n    }\n  }\n\n  private async init(urlOrClient: URL | string | RedisClient) {\n    this.client = new RedisConnection(\n      urlOrClient,\n      this.options,\n      this.options.sessionKeyPrefix,\n    );\n    await this.client.connect();\n  }\n}\n"]}