{"version":3,"sources":["jsdelivr-header.js","/npm/@shopify/shopify-app-session-storage-prisma@6.0.6/dist/cjs/prisma.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAEA,IAAI,WAAa,QAAQ,wBACrB,OAAS,QAAQ,kBAErB,MAAM,iCAAmC,QACzC,MAAM,qBACF,OACA,MACA,UAAY,UACZ,kBAAoB,EACpB,0BAA4B,IAC5B,WAAA,CAAY,GAAQ,UAAE,EAAS,kBAAE,EAAiB,0BAAE,GAA+B,CAAC,GAWhF,GAVA,KAAK,OAAS,EACV,IACA,KAAK,UAAY,QAEK,IAAtB,IACA,KAAK,kBAAoB,QAEK,IAA9B,IACA,KAAK,0BAA4B,QAEN,IAA3B,KAAK,kBACL,MAAM,IAAI,MAAM,gCAAgC,KAAK,mBAEzD,KAAK,MAAQ,KAAK,eACb,MAAK,KAAM,IACX,OAAO,IACR,MAAM,IAAI,yBAAyB,UAAU,KAAK,qOAAsO,EAAM,GAEtS,CACA,kBAAM,CAAa,SACT,KAAK,cACX,MAAM,EAAO,KAAK,aAAa,GAC/B,UACU,KAAK,kBAAkB,OAAO,CAChC,MAAO,CAAE,GAAI,EAAQ,IACrB,OAAQ,EACR,OAAQ,GAEhB,CACA,MAAO,GACH,GAAI,aAAiB,OAAO,OAAO,+BAtCN,UAuCzB,EAAM,KAON,OANA,QAAQ,IAAI,kGACN,KAAK,kBAAkB,OAAO,CAChC,MAAO,CAAE,GAAI,EAAQ,IACrB,OAAQ,EACR,OAAQ,KAEL,EAEX,MAAM,CACV,CACA,OAAO,CACX,CACA,iBAAM,CAAY,SACR,KAAK,cACX,MAAM,QAAY,KAAK,kBAAkB,WAAW,CAChD,MAAO,CAAE,QAEb,GAAK,EAGL,OAAO,KAAK,aAAa,EAC7B,CACA,mBAAM,CAAc,SACV,KAAK,cACX,UACU,KAAK,kBAAkB,OAAO,CAAE,MAAO,CAAE,OACnD,CACA,MACI,OAAO,CACX,CACA,OAAO,CACX,CAC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A,CAAa,GACT,MAAM,EAAgB,CAClB,GAAI,EAAI,GACR,KAAM,EAAI,KACV,MAAO,EAAI,MACX,SAAU,EAAI,SACd,OAAQ,OAAO,EAAI,QACnB,UAAW,OAAO,EAAI,WACtB,SAAU,OAAO,EAAI,UACrB,MAAO,OAAO,EAAI,OAClB,OAAQ,OAAO,EAAI,SAoBvB,OAlByB,OAArB,EAAI,eACJ,EAAc,aAAe,EAAI,cAEZ,OAArB,EAAI,eACJ,EAAc,aAAe,EAAI,cAEX,OAAtB,EAAI,gBACJ,EAAc,cAAgB,EAAI,eAElC,EAAI,UACJ,EAAc,QAAU,EAAI,QAAQ,WAEpC,EAAI,QACJ,EAAc,MAAQ,EAAI,OAE1B,EAAI,cACJ,EAAc,YAAc,EAAI,aAE7B,WAAW,QAAQ,kBAAkB,OAAO,QAAQ,IAAgB,EAC/E,CACA,eAAA,GACI,OAAO,KAAK,OAAO,KAAK,UAC5B,EAEJ,MAAM,iCAAiC,MACnC,MACA,WAAA,CAAY,EAAS,GACjB,MAAM,GACN,KAAK,MAAQ,CACjB,EAEJ,MAAM,mCAAmC,MACrC,WAAA,CAAY,GACR,MAAM,EACV,EAEJ,eAAe,MAAM,GACjB,OAAO,IAAI,SAAS,GAAY,WAAW,EAAS,IACxD,CAEA,QAAQ,2BAA6B,2BACrC,QAAQ,yBAA2B,yBACnC,QAAQ,qBAAuB","file":"/npm/@shopify/shopify-app-session-storage-prisma@6.0.6/dist/cjs/prisma.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@shopify/shopify-app-session-storage-prisma@6.0.6/dist/cjs/prisma.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nvar shopifyApi = require('@shopify/shopify-api');\nvar client = require('@prisma/client');\n\nconst UNIQUE_KEY_CONSTRAINT_ERROR_CODE = 'P2002';\nclass PrismaSessionStorage {\n    prisma;\n    ready;\n    tableName = 'session';\n    connectionRetries = 2;\n    connectionRetryIntervalMs = 5000;\n    constructor(prisma, { tableName, connectionRetries, connectionRetryIntervalMs, } = {}) {\n        this.prisma = prisma;\n        if (tableName) {\n            this.tableName = tableName;\n        }\n        if (connectionRetries !== undefined) {\n            this.connectionRetries = connectionRetries;\n        }\n        if (connectionRetryIntervalMs !== undefined) {\n            this.connectionRetryIntervalMs = connectionRetryIntervalMs;\n        }\n        if (this.getSessionTable() === undefined) {\n            throw new Error(`PrismaClient does not have a ${this.tableName} table`);\n        }\n        this.ready = this.pollForTable()\n            .then(() => true)\n            .catch((cause) => {\n            throw new MissingSessionTableError(`Prisma ${this.tableName} table does not exist. This could happen for a few reasons, see https://github.com/Shopify/shopify-app-js/tree/main/packages/apps/session-storage/shopify-app-session-storage-prisma#troubleshooting for more information`, cause);\n        });\n    }\n    async storeSession(session) {\n        await this.ensureReady();\n        const data = this.sessionToRow(session);\n        try {\n            await this.getSessionTable().upsert({\n                where: { id: session.id },\n                update: data,\n                create: data,\n            });\n        }\n        catch (error) {\n            if (error instanceof client.Prisma.PrismaClientKnownRequestError &&\n                error.code === UNIQUE_KEY_CONSTRAINT_ERROR_CODE) {\n                console.log('Caught PrismaClientKnownRequestError P2002 - Unique Key Key Constraint, retrying upsert.');\n                await this.getSessionTable().upsert({\n                    where: { id: session.id },\n                    update: data,\n                    create: data,\n                });\n                return true;\n            }\n            throw error;\n        }\n        return true;\n    }\n    async loadSession(id) {\n        await this.ensureReady();\n        const row = await this.getSessionTable().findUnique({\n            where: { id },\n        });\n        if (!row) {\n            return undefined;\n        }\n        return this.rowToSession(row);\n    }\n    async deleteSession(id) {\n        await this.ensureReady();\n        try {\n            await this.getSessionTable().delete({ where: { id } });\n        }\n        catch {\n            return true;\n        }\n        return true;\n    }\n    async deleteSessions(ids) {\n        await this.ensureReady();\n        await this.getSessionTable().deleteMany({ where: { id: { in: ids } } });\n        return true;\n    }\n    async findSessionsByShop(shop) {\n        await this.ensureReady();\n        const sessions = await this.getSessionTable().findMany({\n            where: { shop },\n            take: 25,\n            orderBy: [{ expires: 'desc' }],\n        });\n        return sessions.map((session) => this.rowToSession(session));\n    }\n    async isReady() {\n        try {\n            await this.pollForTable();\n            this.ready = Promise.resolve(true);\n        }\n        catch (_error) {\n            this.ready = Promise.resolve(false);\n        }\n        return this.ready;\n    }\n    async ensureReady() {\n        if (!(await this.ready))\n            throw new MissingSessionStorageError('Prisma session storage is not ready. Use the `isReady` method to poll for the table.');\n    }\n    async pollForTable() {\n        for (let i = 0; i < this.connectionRetries; i++) {\n            try {\n                await this.getSessionTable().count();\n                return;\n            }\n            catch (error) {\n                console.log(`Error obtaining session table: ${error}`);\n            }\n            await sleep(this.connectionRetryIntervalMs);\n        }\n        throw Error(`The table \\`${this.tableName}\\` does not exist in the current database.`);\n    }\n    sessionToRow(session) {\n        const sessionParams = session.toObject();\n        return {\n            id: session.id,\n            shop: session.shop,\n            state: session.state,\n            isOnline: session.isOnline,\n            scope: session.scope || null,\n            expires: session.expires || null,\n            accessToken: session.accessToken || '',\n            userId: sessionParams.onlineAccessInfo?.associated_user\n                .id || null,\n            firstName: sessionParams.onlineAccessInfo?.associated_user.first_name || null,\n            lastName: sessionParams.onlineAccessInfo?.associated_user.last_name || null,\n            email: sessionParams.onlineAccessInfo?.associated_user.email || null,\n            accountOwner: sessionParams.onlineAccessInfo?.associated_user.account_owner || false,\n            locale: sessionParams.onlineAccessInfo?.associated_user.locale || null,\n            collaborator: sessionParams.onlineAccessInfo?.associated_user.collaborator || false,\n            emailVerified: sessionParams.onlineAccessInfo?.associated_user.email_verified || false,\n        };\n    }\n    rowToSession(row) {\n        const sessionParams = {\n            id: row.id,\n            shop: row.shop,\n            state: row.state,\n            isOnline: row.isOnline,\n            userId: String(row.userId),\n            firstName: String(row.firstName),\n            lastName: String(row.lastName),\n            email: String(row.email),\n            locale: String(row.locale),\n        };\n        if (row.accountOwner !== null) {\n            sessionParams.accountOwner = row.accountOwner;\n        }\n        if (row.collaborator !== null) {\n            sessionParams.collaborator = row.collaborator;\n        }\n        if (row.emailVerified !== null) {\n            sessionParams.emailVerified = row.emailVerified;\n        }\n        if (row.expires) {\n            sessionParams.expires = row.expires.getTime();\n        }\n        if (row.scope) {\n            sessionParams.scope = row.scope;\n        }\n        if (row.accessToken) {\n            sessionParams.accessToken = row.accessToken;\n        }\n        return shopifyApi.Session.fromPropertyArray(Object.entries(sessionParams), true);\n    }\n    getSessionTable() {\n        return this.prisma[this.tableName];\n    }\n}\nclass MissingSessionTableError extends Error {\n    cause;\n    constructor(message, cause) {\n        super(message);\n        this.cause = cause;\n    }\n}\nclass MissingSessionStorageError extends Error {\n    constructor(message) {\n        super(message);\n    }\n}\nasync function sleep(ms) {\n    return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexports.MissingSessionStorageError = MissingSessionStorageError;\nexports.MissingSessionTableError = MissingSessionTableError;\nexports.PrismaSessionStorage = PrismaSessionStorage;\n\n"]}