UNPKG

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

Version:
34 lines (30 loc) 1.37 kB
'use strict'; var shopifyApi = require('@shopify/shopify-api'); var shopifyAppSessionStorage = require('@shopify/shopify-app-session-storage'); const migrationList = [ new shopifyAppSessionStorage.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 = shopifyApi.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])); } } exports.migrateAddShopKeyToTrackSessionsByShop = migrateAddShopKeyToTrackSessionsByShop; exports.migrationList = migrationList; //# sourceMappingURL=migrations.js.map