@shopify/shopify-app-session-storage-redis 3.0.2 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/migrations.js +33 -0
- package/dist/cjs/migrations.js.map +1 -0
- package/dist/cjs/redis-connection.js +51 -0
- package/dist/cjs/redis-connection.js.map +1 -0
- package/dist/cjs/redis-migrator.js +37 -0
- package/dist/cjs/redis-migrator.js.map +1 -0
- package/dist/cjs/redis.js +106 -0
- package/dist/cjs/redis.js.map +1 -0
- package/dist/esm/migrations.mjs +30 -0
- package/dist/esm/migrations.mjs.map +1 -0
- package/dist/esm/redis-connection.mjs +49 -0
- package/dist/esm/redis-connection.mjs.map +1 -0
- package/dist/esm/redis-migrator.mjs +35 -0
- package/dist/esm/redis-migrator.mjs.map +1 -0
- package/dist/esm/redis.mjs +104 -0
- package/dist/esm/redis.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +20 -10
- package/build/cjs/migrations.js +0 -33
- package/build/cjs/redis-connection.js +0 -54
- package/build/cjs/redis-migrator.js +0 -39
- package/build/cjs/redis.js +0 -111
- package/build/ts/migrations.js +0 -83
- package/build/ts/migrations.js.map +0 -1
- package/build/ts/redis-connection.js +0 -96
- package/build/ts/redis-connection.js.map +0 -1
- package/build/ts/redis-migrator.js +0 -72
- package/build/ts/redis-migrator.js.map +0 -1
- package/build/ts/redis.js +0 -237
- package/build/ts/redis.js.map +0 -1
- /package/{build → dist}/ts/migrations.d.ts +0 -0
- /package/{build → dist}/ts/migrations.d.ts.map +0 -0
- /package/{build → dist}/ts/redis-connection.d.ts +0 -0
- /package/{build → dist}/ts/redis-connection.d.ts.map +0 -0
- /package/{build → dist}/ts/redis-migrator.d.ts +0 -0
- /package/{build → dist}/ts/redis-migrator.d.ts.map +0 -0
- /package/{build → dist}/ts/redis.d.ts +0 -0
- /package/{build → dist}/ts/redis.d.ts.map +0 -0
package/build/cjs/migrations.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var shopifyApi = require('@shopify/shopify-api');
|
|
6
|
-
var shopifyAppSessionStorage = require('@shopify/shopify-app-session-storage');
|
|
7
|
-
|
|
8
|
-
const migrationList = [new shopifyAppSessionStorage.MigrationOperation(
|
|
9
|
-
// This migration name cannot be changed as it has already been released
|
|
10
|
-
'migrateToVersion1_0_1', migrateAddShopKeyToTrackSessionsByShop)];
|
|
11
|
-
|
|
12
|
-
// need to add shop keys with list of associated session keys to support
|
|
13
|
-
// the new findSessionsByShop in v2.x.x
|
|
14
|
-
async function migrateAddShopKeyToTrackSessionsByShop(connection) {
|
|
15
|
-
const shopsAndSessions = {};
|
|
16
|
-
const keys = await connection.keys('*');
|
|
17
|
-
for (const key of keys) {
|
|
18
|
-
if (key.startsWith(connection.sessionStorageIdentifier)) {
|
|
19
|
-
const session = shopifyApi.Session.fromPropertyArray(JSON.parse(await connection.get(key, false)));
|
|
20
|
-
if (!shopsAndSessions[session.shop]) {
|
|
21
|
-
shopsAndSessions[session.shop] = [];
|
|
22
|
-
}
|
|
23
|
-
shopsAndSessions[session.shop].push(key);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
// eslint-disable-next-line guard-for-in
|
|
27
|
-
for (const shop in shopsAndSessions) {
|
|
28
|
-
await connection.set(shop, JSON.stringify(shopsAndSessions[shop]));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
exports.migrateAddShopKeyToTrackSessionsByShop = migrateAddShopKeyToTrackSessionsByShop;
|
|
33
|
-
exports.migrationList = migrationList;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var redis = require('redis');
|
|
6
|
-
|
|
7
|
-
class RedisConnection {
|
|
8
|
-
constructor(dbUrl, options, keyPrefix) {
|
|
9
|
-
this.sessionStorageIdentifier = void 0;
|
|
10
|
-
this.client = void 0;
|
|
11
|
-
this.eventHandler = (..._args) => {};
|
|
12
|
-
this.init(dbUrl, options);
|
|
13
|
-
this.sessionStorageIdentifier = keyPrefix;
|
|
14
|
-
}
|
|
15
|
-
query(_query, _params) {
|
|
16
|
-
throw new Error('Method not implemented. Use get(string, boolean) instead');
|
|
17
|
-
}
|
|
18
|
-
async connect() {
|
|
19
|
-
await this.client.connect();
|
|
20
|
-
}
|
|
21
|
-
async disconnect() {
|
|
22
|
-
await this.client.quit();
|
|
23
|
-
}
|
|
24
|
-
async keys(name) {
|
|
25
|
-
return this.client.keys(name);
|
|
26
|
-
}
|
|
27
|
-
async set(baseKey, value, addKeyPrefix = true) {
|
|
28
|
-
await this.client.set(this.buildKey(baseKey, addKeyPrefix), value);
|
|
29
|
-
}
|
|
30
|
-
async del(baseKey, addKeyPrefix = true) {
|
|
31
|
-
return this.client.del(this.buildKey(baseKey, addKeyPrefix));
|
|
32
|
-
}
|
|
33
|
-
async get(baseKey, addKeyPrefix = true) {
|
|
34
|
-
return this.client.get(this.buildKey(baseKey, addKeyPrefix));
|
|
35
|
-
}
|
|
36
|
-
generateFullKey(name) {
|
|
37
|
-
return `${this.sessionStorageIdentifier}_${name}`;
|
|
38
|
-
}
|
|
39
|
-
buildKey(baseKey, addKeyPrefix) {
|
|
40
|
-
return addKeyPrefix ? this.generateFullKey(baseKey) : baseKey;
|
|
41
|
-
}
|
|
42
|
-
init(dbUrl, options) {
|
|
43
|
-
this.client = redis.createClient({
|
|
44
|
-
...options,
|
|
45
|
-
url: dbUrl
|
|
46
|
-
});
|
|
47
|
-
this.client.on('error', this.eventHandler);
|
|
48
|
-
this.client.on('connect', this.eventHandler);
|
|
49
|
-
this.client.on('reconnecting', this.eventHandler);
|
|
50
|
-
this.client.on('ready', this.eventHandler);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
exports.RedisConnection = RedisConnection;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var shopifyAppSessionStorage = require('@shopify/shopify-app-session-storage');
|
|
6
|
-
|
|
7
|
-
class RedisSessionStorageMigrator extends shopifyAppSessionStorage.AbstractMigrationEngine {
|
|
8
|
-
constructor(dbConnection, opts = {}, migrations) {
|
|
9
|
-
// The name has already been decided whith the last migration
|
|
10
|
-
opts.migrationDBIdentifier = 'migrations';
|
|
11
|
-
super(dbConnection, opts, migrations);
|
|
12
|
-
}
|
|
13
|
-
async initMigrationPersistence() {
|
|
14
|
-
// nothing to do here
|
|
15
|
-
return Promise.resolve();
|
|
16
|
-
}
|
|
17
|
-
async hasMigrationBeenApplied(migrationName) {
|
|
18
|
-
var _migrations$get;
|
|
19
|
-
const migrations = await this.getMigrationRecords();
|
|
20
|
-
const found = (_migrations$get = migrations.get(migrationName)) !== null && _migrations$get !== void 0 ? _migrations$get : false;
|
|
21
|
-
return Promise.resolve(found);
|
|
22
|
-
}
|
|
23
|
-
async saveAppliedMigration(migrationName) {
|
|
24
|
-
const migrations = await this.getMigrationRecords();
|
|
25
|
-
migrations.set(migrationName, true);
|
|
26
|
-
this.connection.set(this.options.migrationDBIdentifier, JSON.stringify(Object.fromEntries(migrations)));
|
|
27
|
-
return Promise.resolve();
|
|
28
|
-
}
|
|
29
|
-
async getMigrationRecords() {
|
|
30
|
-
const migrationsRecord = await this.connection.get(this.options.migrationDBIdentifier);
|
|
31
|
-
let migrations = new Map();
|
|
32
|
-
if (migrationsRecord) {
|
|
33
|
-
migrations = new Map(Object.entries(JSON.parse(migrationsRecord)));
|
|
34
|
-
}
|
|
35
|
-
return Promise.resolve(migrations);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
exports.RedisSessionStorageMigrator = RedisSessionStorageMigrator;
|
package/build/cjs/redis.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var shopifyApi = require('@shopify/shopify-api');
|
|
6
|
-
var migrations = require('./migrations.js');
|
|
7
|
-
var redisConnection = require('./redis-connection.js');
|
|
8
|
-
var redisMigrator = require('./redis-migrator.js');
|
|
9
|
-
|
|
10
|
-
const defaultRedisSessionStorageOptions = {
|
|
11
|
-
sessionKeyPrefix: 'shopify_sessions',
|
|
12
|
-
migratorOptions: {
|
|
13
|
-
migrationDBIdentifier: 'migrations'
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
class RedisSessionStorage {
|
|
17
|
-
static withCredentials(host, db, username, password, opts) {
|
|
18
|
-
return new RedisSessionStorage(new URL(`redis://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}/${db}`), opts);
|
|
19
|
-
}
|
|
20
|
-
constructor(dbUrl, opts = {}) {
|
|
21
|
-
this.ready = void 0;
|
|
22
|
-
this.internalInit = void 0;
|
|
23
|
-
this.options = void 0;
|
|
24
|
-
this.client = void 0;
|
|
25
|
-
this.migrator = void 0;
|
|
26
|
-
this.options = {
|
|
27
|
-
...defaultRedisSessionStorageOptions,
|
|
28
|
-
...opts
|
|
29
|
-
};
|
|
30
|
-
this.internalInit = this.init(typeof dbUrl === 'string' ? dbUrl : dbUrl.toString());
|
|
31
|
-
this.migrator = new redisMigrator.RedisSessionStorageMigrator(this.client, this.options.migratorOptions, migrations.migrationList);
|
|
32
|
-
this.ready = this.migrator.applyMigrations(this.internalInit);
|
|
33
|
-
}
|
|
34
|
-
async storeSession(session) {
|
|
35
|
-
await this.ready;
|
|
36
|
-
await this.client.set(session.id, JSON.stringify(session.toPropertyArray()));
|
|
37
|
-
await this.addKeyToShopList(session);
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
async loadSession(id) {
|
|
41
|
-
await this.ready;
|
|
42
|
-
let rawResult = await this.client.get(id);
|
|
43
|
-
if (!rawResult) return undefined;
|
|
44
|
-
rawResult = JSON.parse(rawResult);
|
|
45
|
-
return shopifyApi.Session.fromPropertyArray(rawResult);
|
|
46
|
-
}
|
|
47
|
-
async deleteSession(id) {
|
|
48
|
-
await this.ready;
|
|
49
|
-
const session = await this.loadSession(id);
|
|
50
|
-
if (session) {
|
|
51
|
-
await this.removeKeyFromShopList(session.shop, id);
|
|
52
|
-
await this.client.del(id);
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
async deleteSessions(ids) {
|
|
57
|
-
await this.ready;
|
|
58
|
-
await Promise.all(ids.map(id => this.deleteSession(id)));
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
async findSessionsByShop(shop) {
|
|
62
|
-
await this.ready;
|
|
63
|
-
const idKeysArrayString = await this.client.get(shop);
|
|
64
|
-
if (!idKeysArrayString) return [];
|
|
65
|
-
const idKeysArray = JSON.parse(idKeysArrayString);
|
|
66
|
-
const results = [];
|
|
67
|
-
for (const idKey of idKeysArray) {
|
|
68
|
-
const rawResult = await this.client.get(idKey, false);
|
|
69
|
-
if (!rawResult) continue;
|
|
70
|
-
const session = shopifyApi.Session.fromPropertyArray(JSON.parse(rawResult));
|
|
71
|
-
results.push(session);
|
|
72
|
-
}
|
|
73
|
-
return results;
|
|
74
|
-
}
|
|
75
|
-
async disconnect() {
|
|
76
|
-
await this.client.disconnect();
|
|
77
|
-
}
|
|
78
|
-
async addKeyToShopList(session) {
|
|
79
|
-
const shopKey = session.shop;
|
|
80
|
-
const idKey = this.client.generateFullKey(session.id);
|
|
81
|
-
const idKeysArrayString = await this.client.get(shopKey);
|
|
82
|
-
if (idKeysArrayString) {
|
|
83
|
-
const idKeysArray = JSON.parse(idKeysArrayString);
|
|
84
|
-
if (!idKeysArray.includes(idKey)) {
|
|
85
|
-
idKeysArray.push(idKey);
|
|
86
|
-
await this.client.set(shopKey, JSON.stringify(idKeysArray));
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
await this.client.set(shopKey, JSON.stringify([idKey]));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async removeKeyFromShopList(shop, id) {
|
|
93
|
-
const shopKey = shop;
|
|
94
|
-
const idKey = this.client.generateFullKey(id);
|
|
95
|
-
const idKeysArrayString = await this.client.get(shopKey);
|
|
96
|
-
if (idKeysArrayString) {
|
|
97
|
-
const idKeysArray = JSON.parse(idKeysArrayString);
|
|
98
|
-
const index = idKeysArray.indexOf(idKey);
|
|
99
|
-
if (index > -1) {
|
|
100
|
-
idKeysArray.splice(index, 1);
|
|
101
|
-
await this.client.set(shopKey, JSON.stringify(idKeysArray));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async init(dbUrl) {
|
|
106
|
-
this.client = new redisConnection.RedisConnection(dbUrl, this.options, this.options.sessionKeyPrefix);
|
|
107
|
-
await this.client.connect();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
exports.RedisSessionStorage = RedisSessionStorage;
|
package/build/ts/migrations.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateAddShopKeyToTrackSessionsByShop = exports.migrationList = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var shopify_api_1 = require("@shopify/shopify-api");
|
|
6
|
-
var shopify_app_session_storage_1 = require("@shopify/shopify-app-session-storage");
|
|
7
|
-
exports.migrationList = [
|
|
8
|
-
new shopify_app_session_storage_1.MigrationOperation(
|
|
9
|
-
// This migration name cannot be changed as it has already been released
|
|
10
|
-
'migrateToVersion1_0_1', migrateAddShopKeyToTrackSessionsByShop),
|
|
11
|
-
];
|
|
12
|
-
// need to add shop keys with list of associated session keys to support
|
|
13
|
-
// the new findSessionsByShop in v2.x.x
|
|
14
|
-
function migrateAddShopKeyToTrackSessionsByShop(connection) {
|
|
15
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
16
|
-
var shopsAndSessions, keys, keys_1, keys_1_1, key, session, _a, _b, _c, _d, e_1_1, _e, _f, _g, _i, shop;
|
|
17
|
-
var e_1, _h;
|
|
18
|
-
return tslib_1.__generator(this, function (_j) {
|
|
19
|
-
switch (_j.label) {
|
|
20
|
-
case 0:
|
|
21
|
-
shopsAndSessions = {};
|
|
22
|
-
return [4 /*yield*/, connection.keys('*')];
|
|
23
|
-
case 1:
|
|
24
|
-
keys = _j.sent();
|
|
25
|
-
_j.label = 2;
|
|
26
|
-
case 2:
|
|
27
|
-
_j.trys.push([2, 7, 8, 9]);
|
|
28
|
-
keys_1 = tslib_1.__values(keys), keys_1_1 = keys_1.next();
|
|
29
|
-
_j.label = 3;
|
|
30
|
-
case 3:
|
|
31
|
-
if (!!keys_1_1.done) return [3 /*break*/, 6];
|
|
32
|
-
key = keys_1_1.value;
|
|
33
|
-
if (!key.startsWith(connection.sessionStorageIdentifier)) return [3 /*break*/, 5];
|
|
34
|
-
_b = (_a = shopify_api_1.Session).fromPropertyArray;
|
|
35
|
-
_d = (_c = JSON).parse;
|
|
36
|
-
return [4 /*yield*/, connection.get(key, false)];
|
|
37
|
-
case 4:
|
|
38
|
-
session = _b.apply(_a, [_d.apply(_c, [(_j.sent())])]);
|
|
39
|
-
if (!shopsAndSessions[session.shop]) {
|
|
40
|
-
shopsAndSessions[session.shop] = [];
|
|
41
|
-
}
|
|
42
|
-
shopsAndSessions[session.shop].push(key);
|
|
43
|
-
_j.label = 5;
|
|
44
|
-
case 5:
|
|
45
|
-
keys_1_1 = keys_1.next();
|
|
46
|
-
return [3 /*break*/, 3];
|
|
47
|
-
case 6: return [3 /*break*/, 9];
|
|
48
|
-
case 7:
|
|
49
|
-
e_1_1 = _j.sent();
|
|
50
|
-
e_1 = { error: e_1_1 };
|
|
51
|
-
return [3 /*break*/, 9];
|
|
52
|
-
case 8:
|
|
53
|
-
try {
|
|
54
|
-
if (keys_1_1 && !keys_1_1.done && (_h = keys_1.return)) _h.call(keys_1);
|
|
55
|
-
}
|
|
56
|
-
finally { if (e_1) throw e_1.error; }
|
|
57
|
-
return [7 /*endfinally*/];
|
|
58
|
-
case 9:
|
|
59
|
-
_e = shopsAndSessions;
|
|
60
|
-
_f = [];
|
|
61
|
-
for (_g in _e)
|
|
62
|
-
_f.push(_g);
|
|
63
|
-
_i = 0;
|
|
64
|
-
_j.label = 10;
|
|
65
|
-
case 10:
|
|
66
|
-
if (!(_i < _f.length)) return [3 /*break*/, 13];
|
|
67
|
-
_g = _f[_i];
|
|
68
|
-
if (!(_g in _e)) return [3 /*break*/, 12];
|
|
69
|
-
shop = _g;
|
|
70
|
-
return [4 /*yield*/, connection.set(shop, JSON.stringify(shopsAndSessions[shop]))];
|
|
71
|
-
case 11:
|
|
72
|
-
_j.sent();
|
|
73
|
-
_j.label = 12;
|
|
74
|
-
case 12:
|
|
75
|
-
_i++;
|
|
76
|
-
return [3 /*break*/, 10];
|
|
77
|
-
case 13: return [2 /*return*/];
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
exports.migrateAddShopKeyToTrackSessionsByShop = migrateAddShopKeyToTrackSessionsByShop;
|
|
83
|
-
//# sourceMappingURL=migrations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/migrations.ts"],"names":[],"mappings":";;;;AAAA,oDAA6C;AAC7C,oFAAwE;AAI3D,QAAA,aAAa,GAAG;IAC3B,IAAI,gDAAkB;IACpB,wEAAwE;IACxE,uBAAuB,EACvB,sCAAsC,CACvC;CACF,CAAC;AAEF,wEAAwE;AACxE,uCAAuC;AACvC,SAAsB,sCAAsC,CAC1D,UAA2B;;;;;;;oBAErB,gBAAgB,GAA6B,EAAE,CAAC;oBACzC,qBAAM,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAA;;oBAAjC,IAAI,GAAG,SAA0B;;;;oBACrB,SAAA,iBAAA,IAAI,CAAA;;;;oBAAX,GAAG;yBACR,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,wBAAwB,CAAC,EAAnD,wBAAmD;oBACrC,KAAA,CAAA,KAAA,qBAAO,CAAA,CAAC,iBAAiB,CAAA;oBACvC,KAAA,CAAA,KAAA,IAAI,CAAA,CAAC,KAAK,CAAA;oBAAE,qBAAM,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,EAAA;;oBADxC,OAAO,GAAG,cACd,cAAW,CAAC,SAAgC,CAAW,EAAC,EACzD;oBACD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;wBACpC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;oBACtC,CAAC;oBACD,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;;;;;;;;;;;;;;;;;yBAI1B,gBAAgB;;;;;;;;;;;oBACjC,qBAAM,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAA;;oBAAlE,SAAkE,CAAC;;;;;;;;;CAEtE;AApBD,wFAoBC"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RedisConnection = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var redis_1 = require("redis");
|
|
6
|
-
var RedisConnection = /** @class */ (function () {
|
|
7
|
-
function RedisConnection(dbUrl, options, keyPrefix) {
|
|
8
|
-
this.eventHandler = function () {
|
|
9
|
-
var _args = [];
|
|
10
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
11
|
-
_args[_i] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
this.init(dbUrl, options);
|
|
15
|
-
this.sessionStorageIdentifier = keyPrefix;
|
|
16
|
-
}
|
|
17
|
-
RedisConnection.prototype.query = function (_query, _params) {
|
|
18
|
-
throw new Error('Method not implemented. Use get(string, boolean) instead');
|
|
19
|
-
};
|
|
20
|
-
RedisConnection.prototype.connect = function () {
|
|
21
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
22
|
-
return tslib_1.__generator(this, function (_a) {
|
|
23
|
-
switch (_a.label) {
|
|
24
|
-
case 0: return [4 /*yield*/, this.client.connect()];
|
|
25
|
-
case 1:
|
|
26
|
-
_a.sent();
|
|
27
|
-
return [2 /*return*/];
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
RedisConnection.prototype.disconnect = function () {
|
|
33
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
34
|
-
return tslib_1.__generator(this, function (_a) {
|
|
35
|
-
switch (_a.label) {
|
|
36
|
-
case 0: return [4 /*yield*/, this.client.quit()];
|
|
37
|
-
case 1:
|
|
38
|
-
_a.sent();
|
|
39
|
-
return [2 /*return*/];
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
RedisConnection.prototype.keys = function (name) {
|
|
45
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
46
|
-
return tslib_1.__generator(this, function (_a) {
|
|
47
|
-
return [2 /*return*/, this.client.keys(name)];
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
RedisConnection.prototype.set = function (baseKey, value, addKeyPrefix) {
|
|
52
|
-
if (addKeyPrefix === void 0) { addKeyPrefix = true; }
|
|
53
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
54
|
-
return tslib_1.__generator(this, function (_a) {
|
|
55
|
-
switch (_a.label) {
|
|
56
|
-
case 0: return [4 /*yield*/, this.client.set(this.buildKey(baseKey, addKeyPrefix), value)];
|
|
57
|
-
case 1:
|
|
58
|
-
_a.sent();
|
|
59
|
-
return [2 /*return*/];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
RedisConnection.prototype.del = function (baseKey, addKeyPrefix) {
|
|
65
|
-
if (addKeyPrefix === void 0) { addKeyPrefix = true; }
|
|
66
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
67
|
-
return tslib_1.__generator(this, function (_a) {
|
|
68
|
-
return [2 /*return*/, this.client.del(this.buildKey(baseKey, addKeyPrefix))];
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
RedisConnection.prototype.get = function (baseKey, addKeyPrefix) {
|
|
73
|
-
if (addKeyPrefix === void 0) { addKeyPrefix = true; }
|
|
74
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
75
|
-
return tslib_1.__generator(this, function (_a) {
|
|
76
|
-
return [2 /*return*/, this.client.get(this.buildKey(baseKey, addKeyPrefix))];
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
RedisConnection.prototype.generateFullKey = function (name) {
|
|
81
|
-
return "".concat(this.sessionStorageIdentifier, "_").concat(name);
|
|
82
|
-
};
|
|
83
|
-
RedisConnection.prototype.buildKey = function (baseKey, addKeyPrefix) {
|
|
84
|
-
return addKeyPrefix ? this.generateFullKey(baseKey) : baseKey;
|
|
85
|
-
};
|
|
86
|
-
RedisConnection.prototype.init = function (dbUrl, options) {
|
|
87
|
-
this.client = (0, redis_1.createClient)(tslib_1.__assign(tslib_1.__assign({}, options), { url: dbUrl }));
|
|
88
|
-
this.client.on('error', this.eventHandler);
|
|
89
|
-
this.client.on('connect', this.eventHandler);
|
|
90
|
-
this.client.on('reconnecting', this.eventHandler);
|
|
91
|
-
this.client.on('ready', this.eventHandler);
|
|
92
|
-
};
|
|
93
|
-
return RedisConnection;
|
|
94
|
-
}());
|
|
95
|
-
exports.RedisConnection = RedisConnection;
|
|
96
|
-
//# sourceMappingURL=redis-connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redis-connection.js","sourceRoot":"","sources":["../../src/redis-connection.ts"],"names":[],"mappings":";;;;AAAA,+BAAuD;AAKvD;IAIE,yBAAY,KAAa,EAAE,OAA2B,EAAE,SAAiB;QAqDjE,iBAAY,GAAG;YAAC,eAAe;iBAAf,UAAe,EAAf,qBAAe,EAAf,IAAe;gBAAf,0BAAe;;QAAM,CAAC,CAAC;QApD7C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC1B,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;IAC5C,CAAC;IAED,+BAAK,GAAL,UAAM,MAAc,EAAE,OAAc;QAClC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAEK,iCAAO,GAAb;;;;4BACE,qBAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAA;;wBAA3B,SAA2B,CAAC;;;;;KAC7B;IAEK,oCAAU,GAAhB;;;;4BACE,qBAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAA;;wBAAxB,SAAwB,CAAC;;;;;KAC1B;IAEK,8BAAI,GAAV,UAAW,IAAY;;;gBACrB,sBAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAC;;;KAC/B;IAEK,6BAAG,GAAT,UAAU,OAAe,EAAE,KAAU,EAAE,YAAmB;QAAnB,6BAAA,EAAA,mBAAmB;;;;4BACxD,qBAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,EAAA;;wBAAlE,SAAkE,CAAC;;;;;KAC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,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RedisSessionStorageMigrator = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var shopify_app_session_storage_1 = require("@shopify/shopify-app-session-storage");
|
|
6
|
-
var RedisSessionStorageMigrator = /** @class */ (function (_super) {
|
|
7
|
-
tslib_1.__extends(RedisSessionStorageMigrator, _super);
|
|
8
|
-
function RedisSessionStorageMigrator(dbConnection, opts, migrations) {
|
|
9
|
-
if (opts === void 0) { opts = {}; }
|
|
10
|
-
// The name has already been decided whith the last migration
|
|
11
|
-
opts.migrationDBIdentifier = 'migrations';
|
|
12
|
-
return _super.call(this, dbConnection, opts, migrations) || this;
|
|
13
|
-
}
|
|
14
|
-
RedisSessionStorageMigrator.prototype.initMigrationPersistence = function () {
|
|
15
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
16
|
-
return tslib_1.__generator(this, function (_a) {
|
|
17
|
-
// nothing to do here
|
|
18
|
-
return [2 /*return*/, Promise.resolve()];
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
RedisSessionStorageMigrator.prototype.hasMigrationBeenApplied = function (migrationName) {
|
|
23
|
-
var _a;
|
|
24
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
25
|
-
var migrations, found;
|
|
26
|
-
return tslib_1.__generator(this, function (_b) {
|
|
27
|
-
switch (_b.label) {
|
|
28
|
-
case 0: return [4 /*yield*/, this.getMigrationRecords()];
|
|
29
|
-
case 1:
|
|
30
|
-
migrations = _b.sent();
|
|
31
|
-
found = (_a = migrations.get(migrationName)) !== null && _a !== void 0 ? _a : false;
|
|
32
|
-
return [2 /*return*/, Promise.resolve(found)];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
RedisSessionStorageMigrator.prototype.saveAppliedMigration = function (migrationName) {
|
|
38
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
39
|
-
var migrations;
|
|
40
|
-
return tslib_1.__generator(this, function (_a) {
|
|
41
|
-
switch (_a.label) {
|
|
42
|
-
case 0: return [4 /*yield*/, this.getMigrationRecords()];
|
|
43
|
-
case 1:
|
|
44
|
-
migrations = _a.sent();
|
|
45
|
-
migrations.set(migrationName, true);
|
|
46
|
-
this.connection.set(this.options.migrationDBIdentifier, JSON.stringify(Object.fromEntries(migrations)));
|
|
47
|
-
return [2 /*return*/, Promise.resolve()];
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
RedisSessionStorageMigrator.prototype.getMigrationRecords = function () {
|
|
53
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
54
|
-
var migrationsRecord, migrations;
|
|
55
|
-
return tslib_1.__generator(this, function (_a) {
|
|
56
|
-
switch (_a.label) {
|
|
57
|
-
case 0: return [4 /*yield*/, this.connection.get(this.options.migrationDBIdentifier)];
|
|
58
|
-
case 1:
|
|
59
|
-
migrationsRecord = _a.sent();
|
|
60
|
-
migrations = new Map();
|
|
61
|
-
if (migrationsRecord) {
|
|
62
|
-
migrations = new Map(Object.entries(JSON.parse(migrationsRecord)));
|
|
63
|
-
}
|
|
64
|
-
return [2 /*return*/, Promise.resolve(migrations)];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
return RedisSessionStorageMigrator;
|
|
70
|
-
}(shopify_app_session_storage_1.AbstractMigrationEngine));
|
|
71
|
-
exports.RedisSessionStorageMigrator = RedisSessionStorageMigrator;
|
|
72
|
-
//# sourceMappingURL=redis-migrator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redis-migrator.js","sourceRoot":"","sources":["../../src/redis-migrator.ts"],"names":[],"mappings":";;;;AAAA,oFAI8C;AAI9C;IAAiD,uDAGhD;IACC,qCACE,YAA6B,EAC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