{"version":3,"file":"sticky-bucket-service.mjs","names":["toString","getStickyBucketAttributeKey","StickyBucketService","constructor","opts","prefix","getAllAssignments","attributes","docs","Promise","all","Object","entries","map","attributeName","attributeValue","getAssignments","forEach","doc","key","getKey","StickyBucketServiceSync","getAssignmentsSync","saveAssignments","saveAssignmentsSync","getAllAssignmentsSync","LocalStorageStickyBucketService","localStorage","globalThis","e","raw","getItem","data","JSON","parse","assignments","setItem","stringify","ExpressCookieStickyBucketService","req","res","cookieAttributes","maxAge","cookies","str","cookie","encodeURIComponent","BrowserCookieStickyBucketService","jsCookie","expires","get","domain","hostOnlyAttributes","set","remove","RedisStickyBucketService","redis","keys","mget","then","values","_attributeName","_attributeValue"],"sources":["../../src/sticky-bucket-service.ts"],"sourcesContent":["import {\n  LocalStorageCompat,\n  StickyAssignmentsDocument,\n  StickyAttributeKey,\n} from \"./types/growthbook\";\nimport { toString } from \"./util\";\nimport { getStickyBucketAttributeKey } from \"./core\";\n\nexport interface CookieAttributes {\n  expires?: number | Date | undefined;\n  path?: string | undefined;\n  domain?: string | undefined;\n  secure?: boolean | undefined;\n  sameSite?: \"strict\" | \"Strict\" | \"lax\" | \"Lax\" | \"none\" | \"None\" | undefined;\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  [property: string]: any;\n}\nexport interface JsCookiesCompat<T = string> {\n  set(\n    name: string,\n    value: string | T,\n    options?: CookieAttributes,\n  ): string | undefined;\n  get(name: string): string | T | undefined;\n  get(): { [key: string]: string };\n  remove(name: string, options?: CookieAttributes): void;\n}\n\nexport interface IORedisCompat {\n  mget(...keys: string[]): Promise<string[]>;\n  set(key: string, value: string): Promise<string>;\n}\n\nexport interface RequestCompat {\n  cookies: Record<string, string>;\n  [key: string]: unknown;\n}\nexport interface ResponseCompat {\n  cookie(\n    name: string,\n    value: string,\n    options?: CookieAttributes,\n  ): ResponseCompat;\n  [key: string]: unknown;\n}\n\n/**\n * Responsible for reading and writing documents which describe sticky bucket assignments.\n */\nexport abstract class StickyBucketService {\n  protected prefix: string;\n\n  constructor(opts?: { prefix?: string }) {\n    opts = opts || {};\n    this.prefix = opts.prefix || \"\";\n  }\n\n  abstract getAssignments(\n    attributeName: string,\n    attributeValue: string,\n  ): Promise<StickyAssignmentsDocument | null>;\n\n  abstract saveAssignments(doc: StickyAssignmentsDocument): Promise<unknown>;\n\n  /**\n   * The SDK calls getAllAssignments to populate sticky buckets. This in turn will\n   * typically loop through individual getAssignments calls. However, some StickyBucketService\n   * instances (i.e. Redis) will instead perform a multi-query inside getAllAssignments instead.\n   */\n  async getAllAssignments(\n    attributes: Record<string, string>,\n  ): Promise<Record<StickyAttributeKey, StickyAssignmentsDocument>> {\n    const docs: Record<string, StickyAssignmentsDocument> = {};\n    (\n      await Promise.all(\n        Object.entries(attributes).map(([attributeName, attributeValue]) =>\n          this.getAssignments(attributeName, attributeValue),\n        ),\n      )\n    ).forEach((doc) => {\n      if (doc) {\n        const key = getStickyBucketAttributeKey(\n          doc.attributeName,\n          doc.attributeValue,\n        );\n        docs[key] = doc;\n      }\n    });\n    return docs;\n  }\n\n  getKey(attributeName: string, attributeValue: string): string {\n    return `${this.prefix}${attributeName}||${attributeValue}`;\n  }\n}\n\nexport abstract class StickyBucketServiceSync extends StickyBucketService {\n  abstract getAssignmentsSync(\n    attributeName: string,\n    attributeValue: string,\n  ): StickyAssignmentsDocument | null;\n\n  abstract saveAssignmentsSync(doc: StickyAssignmentsDocument): void;\n\n  async getAssignments(attributeName: string, attributeValue: string) {\n    return this.getAssignmentsSync(attributeName, attributeValue);\n  }\n\n  async saveAssignments(doc: StickyAssignmentsDocument) {\n    this.saveAssignmentsSync(doc);\n  }\n\n  getAllAssignmentsSync(\n    attributes: Record<string, string>,\n  ): Record<StickyAttributeKey, StickyAssignmentsDocument> {\n    const docs: Record<string, StickyAssignmentsDocument> = {};\n    Object.entries(attributes)\n      .map(([attributeName, attributeValue]) =>\n        this.getAssignmentsSync(attributeName, attributeValue),\n      )\n      .forEach((doc) => {\n        if (doc) {\n          const key = getStickyBucketAttributeKey(\n            doc.attributeName,\n            doc.attributeValue,\n          );\n          docs[key] = doc;\n        }\n      });\n    return docs;\n  }\n}\n\nexport class LocalStorageStickyBucketService extends StickyBucketService {\n  private localStorage: LocalStorageCompat | undefined;\n  constructor(opts?: { prefix?: string; localStorage?: LocalStorageCompat }) {\n    opts = opts || {};\n    super();\n    this.prefix = opts.prefix || \"gbStickyBuckets__\";\n    try {\n      this.localStorage = opts.localStorage || globalThis.localStorage;\n    } catch (e) {\n      // Ignore localStorage errors\n    }\n  }\n  async getAssignments(attributeName: string, attributeValue: string) {\n    const key = this.getKey(attributeName, attributeValue);\n    let doc: StickyAssignmentsDocument | null = null;\n    if (!this.localStorage) return doc;\n    try {\n      const raw = (await this.localStorage.getItem(key)) || \"{}\";\n      const data = JSON.parse(raw);\n      if (data.attributeName && data.attributeValue && data.assignments) {\n        doc = data;\n      }\n    } catch (e) {\n      // Ignore localStorage errors\n    }\n    return doc;\n  }\n  async saveAssignments(doc: StickyAssignmentsDocument) {\n    const key = this.getKey(doc.attributeName, doc.attributeValue);\n    if (!this.localStorage) return;\n    try {\n      await this.localStorage.setItem(key, JSON.stringify(doc));\n    } catch (e) {\n      // Ignore localStorage errors\n    }\n  }\n}\n\nexport class ExpressCookieStickyBucketService extends StickyBucketServiceSync {\n  /**\n   * Intended to be used with cookieParser() middleware from npm: 'cookie-parser'.\n   * Assumes:\n   *  - reading a cookie is automatically decoded via decodeURIComponent() or similar\n   *  - writing a cookie name & value must be manually encoded via encodeURIComponent() or similar\n   *  - all cookie bodies are JSON encoded strings and are manually encoded/decoded\n   */\n  private req: RequestCompat;\n  private res: ResponseCompat;\n  private cookieAttributes: CookieAttributes;\n  constructor({\n    prefix = \"gbStickyBuckets__\",\n    req,\n    res,\n    cookieAttributes = { maxAge: 180 * 24 * 3600 * 1000 }, // 180 days\n  }: {\n    prefix?: string;\n    req: RequestCompat;\n    res: ResponseCompat;\n    cookieAttributes?: CookieAttributes;\n  }) {\n    super();\n    this.prefix = prefix;\n    this.req = req;\n    this.res = res;\n    this.cookieAttributes = cookieAttributes;\n  }\n  getAssignmentsSync(attributeName: string, attributeValue: string) {\n    const key = this.getKey(attributeName, attributeValue);\n    let doc: StickyAssignmentsDocument | null = null;\n    if (!this.req) return doc;\n    try {\n      const raw = this.req.cookies[key] || \"{}\";\n      const data = JSON.parse(raw);\n      if (data.attributeName && data.attributeValue && data.assignments) {\n        doc = data;\n      }\n    } catch (e) {\n      // Ignore cookie errors\n    }\n    return doc;\n  }\n  saveAssignmentsSync(doc: StickyAssignmentsDocument) {\n    const key = this.getKey(doc.attributeName, doc.attributeValue);\n    if (!this.res) return;\n    const str = JSON.stringify(doc);\n    this.res.cookie(\n      encodeURIComponent(key),\n      encodeURIComponent(str),\n      this.cookieAttributes,\n    );\n  }\n}\n\nexport class BrowserCookieStickyBucketService extends StickyBucketServiceSync {\n  /**\n   * Intended to be used with npm: 'js-cookie'.\n   * Assumes:\n   *  - reading a cookie is automatically decoded via decodeURIComponent() or similar\n   *  - writing a cookie name & value is automatically encoded via encodeURIComponent() or similar\n   *  - all cookie bodies are JSON encoded strings and are manually encoded/decoded\n   */\n  private jsCookie: JsCookiesCompat;\n  private cookieAttributes: CookieAttributes;\n  constructor({\n    prefix = \"gbStickyBuckets__\",\n    jsCookie,\n    cookieAttributes = { expires: 180 }, // 180 days\n  }: {\n    prefix?: string;\n    jsCookie: JsCookiesCompat;\n    cookieAttributes?: CookieAttributes;\n  }) {\n    super();\n    this.prefix = prefix;\n    this.jsCookie = jsCookie;\n    this.cookieAttributes = cookieAttributes;\n  }\n  getAssignmentsSync(attributeName: string, attributeValue: string) {\n    const key = this.getKey(attributeName, attributeValue);\n    let doc: StickyAssignmentsDocument | null = null;\n    if (!this.jsCookie) return doc;\n    try {\n      const raw = this.jsCookie.get(key);\n      const data = JSON.parse(raw || \"{}\");\n      if (data.attributeName && data.attributeValue && data.assignments) {\n        doc = data;\n      }\n    } catch (e) {\n      // Ignore cookie errors\n    }\n    return doc;\n  }\n  async saveAssignmentsSync(doc: StickyAssignmentsDocument) {\n    const key = this.getKey(doc.attributeName, doc.attributeValue);\n    if (!this.jsCookie) return;\n    const str = JSON.stringify(doc);\n    const { domain, ...hostOnlyAttributes } = this.cookieAttributes;\n    if (!domain) {\n      this.jsCookie.set(key, str, this.cookieAttributes);\n      return;\n    }\n    // Remove any legacy host-only cookie first - it would shadow the\n    // domain-scoped one on reads\n    this.jsCookie.remove(key, hostOnlyAttributes);\n    this.jsCookie.set(key, str, this.cookieAttributes);\n    // Browsers silently reject a cookie whose domain doesn't cover this host\n    // (e.g. a typo) - fall back to host-only so assignments still persist\n    if (this.jsCookie.get(key) !== str) {\n      this.jsCookie.set(key, str, hostOnlyAttributes);\n    }\n  }\n}\n\nexport class RedisStickyBucketService extends StickyBucketService {\n  /** Intended to be used with npm: 'ioredis'. **/\n  private redis: IORedisCompat | undefined;\n  constructor({ redis }: { redis: IORedisCompat }) {\n    super();\n    this.redis = redis;\n  }\n  async getAllAssignments(\n    attributes: Record<string, string>,\n  ): Promise<Record<StickyAttributeKey, StickyAssignmentsDocument>> {\n    const docs: Record<StickyAttributeKey, StickyAssignmentsDocument> = {};\n    const keys = Object.entries(attributes).map(\n      ([attributeName, attributeValue]) =>\n        getStickyBucketAttributeKey(attributeName, attributeValue),\n    );\n    if (!this.redis) return docs;\n    await this.redis.mget(...keys).then((values) => {\n      values.forEach((raw) => {\n        try {\n          const data = JSON.parse(raw || \"{}\");\n          if (\n            data.attributeName &&\n            \"attributeValue\" in data &&\n            data.assignments\n          ) {\n            const key = getStickyBucketAttributeKey(\n              data.attributeName,\n              toString(data.attributeValue),\n            );\n            docs[key] = data;\n          }\n        } catch (e) {\n          // ignore redis doc parse errors\n        }\n      });\n    });\n    return docs;\n  }\n  async getAssignments(_attributeName: string, _attributeValue: string) {\n    // not implemented\n    return null;\n  }\n  async saveAssignments(doc: StickyAssignmentsDocument) {\n    const key = this.getKey(doc.attributeName, doc.attributeValue);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