UNPKG

@shopify/shopify-app-session-storage-redis

Version:
31 lines (28 loc) 1.25 kB
import { Session } from '@shopify/shopify-api'; import { MigrationOperation } from '@shopify/shopify-app-session-storage'; const migrationList = [ new MigrationOperation( // This migration name cannot be changed as it has already been released 'migrateToVersion1_0_1', migrateAddShopKeyToTrackSessionsByShop), ]; // need to add shop keys with list of associated session keys to support // the new findSessionsByShop in v2.x.x async function migrateAddShopKeyToTrackSessionsByShop(connection) { const shopsAndSessions = {}; const keys = await connection.keys('*'); for (const key of keys) { if (key.startsWith(connection.sessionStorageIdentifier)) { const session = Session.fromPropertyArray(JSON.parse((await connection.get(key, false)))); if (!shopsAndSessions[session.shop]) { shopsAndSessions[session.shop] = []; } shopsAndSessions[session.shop].push(key); } } // eslint-disable-next-line guard-for-in for (const shop in shopsAndSessions) { await connection.set(shop, JSON.stringify(shopsAndSessions[shop])); } } export { migrateAddShopKeyToTrackSessionsByShop, migrationList }; //# sourceMappingURL=migrations.mjs.map