@shopify/shopify-app-session-storage-redis 1.0.2 → 1.1.1
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/build/cjs/migrations.js +12 -6
- package/build/cjs/redis-connection.js +52 -0
- package/build/cjs/redis-migrator.js +39 -0
- package/build/cjs/redis.js +23 -41
- package/build/ts/migrations.d.ts +4 -4
- package/build/ts/migrations.d.ts.map +1 -1
- package/build/ts/migrations.js +13 -7
- package/build/ts/migrations.js.map +1 -1
- package/build/ts/redis-connection.d.ts +18 -0
- package/build/ts/redis-connection.d.ts.map +1 -0
- package/build/ts/redis-connection.js +84 -0
- package/build/ts/redis-connection.js.map +1 -0
- package/build/ts/redis-migrator.d.ts +10 -0
- package/build/ts/redis-migrator.d.ts.map +1 -0
- package/build/ts/redis-migrator.js +72 -0
- package/build/ts/redis-migrator.js.map +1 -0
- package/build/ts/redis.d.ts +4 -4
- package/build/ts/redis.d.ts.map +1 -1
- package/build/ts/redis.js +20 -53
- package/build/ts/redis.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -9
package/build/ts/redis.js
CHANGED
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RedisSessionStorage = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var redis_1 = require("redis");
|
|
6
5
|
var shopify_api_1 = require("@shopify/shopify-api");
|
|
7
6
|
var migrations_1 = require("./migrations");
|
|
7
|
+
var redis_connection_1 = require("./redis-connection");
|
|
8
|
+
var redis_migrator_1 = require("./redis-migrator");
|
|
8
9
|
var defaultRedisSessionStorageOptions = {
|
|
9
10
|
sessionKeyPrefix: 'shopify_sessions',
|
|
11
|
+
migratorOptions: {
|
|
12
|
+
migrationDBIdentifier: 'migrations',
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
15
|
var RedisSessionStorage = /** @class */ (function () {
|
|
12
16
|
function RedisSessionStorage(dbUrl, opts) {
|
|
13
17
|
if (opts === void 0) { opts = {}; }
|
|
14
|
-
this.dbUrl = dbUrl;
|
|
15
|
-
if (typeof this.dbUrl === 'string') {
|
|
16
|
-
this.dbUrl = new URL(this.dbUrl);
|
|
17
|
-
}
|
|
18
18
|
this.options = tslib_1.__assign(tslib_1.__assign({}, defaultRedisSessionStorageOptions), opts);
|
|
19
|
-
this.
|
|
19
|
+
this.internalInit = this.init(dbUrl.toString());
|
|
20
|
+
this.migrator = new redis_migrator_1.RedisSessionStorageMigrator(this.client, this.options.migratorOptions, migrations_1.migrationList);
|
|
21
|
+
this.ready = this.migrator.applyMigrations(this.internalInit);
|
|
20
22
|
}
|
|
21
23
|
RedisSessionStorage.withCredentials = function (host, db, username, password, opts) {
|
|
22
24
|
return new RedisSessionStorage(new URL("redis://".concat(encodeURIComponent(username), ":").concat(encodeURIComponent(password), "@").concat(host, "/").concat(db)), opts);
|
|
@@ -28,7 +30,7 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
28
30
|
case 0: return [4 /*yield*/, this.ready];
|
|
29
31
|
case 1:
|
|
30
32
|
_a.sent();
|
|
31
|
-
return [4 /*yield*/, this.client.set(
|
|
33
|
+
return [4 /*yield*/, this.client.set(session.id, JSON.stringify(session.toPropertyArray()))];
|
|
32
34
|
case 2:
|
|
33
35
|
_a.sent();
|
|
34
36
|
return [4 /*yield*/, this.addKeyToShopList(session)];
|
|
@@ -47,7 +49,7 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
47
49
|
case 0: return [4 /*yield*/, this.ready];
|
|
48
50
|
case 1:
|
|
49
51
|
_a.sent();
|
|
50
|
-
return [4 /*yield*/, this.client.get(
|
|
52
|
+
return [4 /*yield*/, this.client.get(id)];
|
|
51
53
|
case 2:
|
|
52
54
|
rawResult = _a.sent();
|
|
53
55
|
if (!rawResult)
|
|
@@ -73,7 +75,7 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
73
75
|
return [4 /*yield*/, this.removeKeyFromShopList(session.shop, id)];
|
|
74
76
|
case 3:
|
|
75
77
|
_a.sent();
|
|
76
|
-
return [4 /*yield*/, this.client.del(
|
|
78
|
+
return [4 /*yield*/, this.client.del(id)];
|
|
77
79
|
case 4:
|
|
78
80
|
_a.sent();
|
|
79
81
|
_a.label = 5;
|
|
@@ -107,7 +109,7 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
107
109
|
case 0: return [4 /*yield*/, this.ready];
|
|
108
110
|
case 1:
|
|
109
111
|
_b.sent();
|
|
110
|
-
return [4 /*yield*/, this.client.get(
|
|
112
|
+
return [4 /*yield*/, this.client.get(shop)];
|
|
111
113
|
case 2:
|
|
112
114
|
idKeysArrayString = _b.sent();
|
|
113
115
|
if (!idKeysArrayString)
|
|
@@ -122,7 +124,7 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
122
124
|
case 4:
|
|
123
125
|
if (!!idKeysArray_1_1.done) return [3 /*break*/, 7];
|
|
124
126
|
idKey = idKeysArray_1_1.value;
|
|
125
|
-
return [4 /*yield*/, this.client.get(idKey)];
|
|
127
|
+
return [4 /*yield*/, this.client.get(idKey, false)];
|
|
126
128
|
case 5:
|
|
127
129
|
rawResult = _b.sent();
|
|
128
130
|
if (!rawResult)
|
|
@@ -153,7 +155,7 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
153
155
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
154
156
|
return tslib_1.__generator(this, function (_a) {
|
|
155
157
|
switch (_a.label) {
|
|
156
|
-
case 0: return [4 /*yield*/, this.client.
|
|
158
|
+
case 0: return [4 /*yield*/, this.client.disconnect()];
|
|
157
159
|
case 1:
|
|
158
160
|
_a.sent();
|
|
159
161
|
return [2 /*return*/];
|
|
@@ -161,17 +163,14 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
161
163
|
});
|
|
162
164
|
});
|
|
163
165
|
};
|
|
164
|
-
RedisSessionStorage.prototype.fullKey = function (name) {
|
|
165
|
-
return "".concat(this.options.sessionKeyPrefix, "_").concat(name);
|
|
166
|
-
};
|
|
167
166
|
RedisSessionStorage.prototype.addKeyToShopList = function (session) {
|
|
168
167
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
169
168
|
var shopKey, idKey, idKeysArrayString, idKeysArray;
|
|
170
169
|
return tslib_1.__generator(this, function (_a) {
|
|
171
170
|
switch (_a.label) {
|
|
172
171
|
case 0:
|
|
173
|
-
shopKey =
|
|
174
|
-
idKey = this.
|
|
172
|
+
shopKey = session.shop;
|
|
173
|
+
idKey = this.client.generateFullKey(session.id);
|
|
175
174
|
return [4 /*yield*/, this.client.get(shopKey)];
|
|
176
175
|
case 1:
|
|
177
176
|
idKeysArrayString = _a.sent();
|
|
@@ -199,8 +198,8 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
199
198
|
return tslib_1.__generator(this, function (_a) {
|
|
200
199
|
switch (_a.label) {
|
|
201
200
|
case 0:
|
|
202
|
-
shopKey =
|
|
203
|
-
idKey = this.
|
|
201
|
+
shopKey = shop;
|
|
202
|
+
idKey = this.client.generateFullKey(id);
|
|
204
203
|
return [4 /*yield*/, this.client.get(shopKey)];
|
|
205
204
|
case 1:
|
|
206
205
|
idKeysArrayString = _a.sent();
|
|
@@ -218,46 +217,14 @@ var RedisSessionStorage = /** @class */ (function () {
|
|
|
218
217
|
});
|
|
219
218
|
});
|
|
220
219
|
};
|
|
221
|
-
RedisSessionStorage.prototype.init = function () {
|
|
220
|
+
RedisSessionStorage.prototype.init = function (dbUrl) {
|
|
222
221
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
223
222
|
return tslib_1.__generator(this, function (_a) {
|
|
224
223
|
switch (_a.label) {
|
|
225
224
|
case 0:
|
|
226
|
-
this.client =
|
|
227
|
-
if (this.options.onError) {
|
|
228
|
-
this.client.on('error', this.options.onError);
|
|
229
|
-
}
|
|
225
|
+
this.client = new redis_connection_1.RedisConnection(dbUrl, this.options, this.options.sessionKeyPrefix);
|
|
230
226
|
return [4 /*yield*/, this.client.connect()];
|
|
231
227
|
case 1:
|
|
232
|
-
_a.sent();
|
|
233
|
-
return [4 /*yield*/, this.migrate()];
|
|
234
|
-
case 2:
|
|
235
|
-
_a.sent();
|
|
236
|
-
return [2 /*return*/];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
};
|
|
241
|
-
RedisSessionStorage.prototype.migrate = function () {
|
|
242
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
243
|
-
var migrationsRecord, migrations;
|
|
244
|
-
return tslib_1.__generator(this, function (_a) {
|
|
245
|
-
switch (_a.label) {
|
|
246
|
-
case 0: return [4 /*yield*/, this.client.get(this.fullKey('migrations'))];
|
|
247
|
-
case 1:
|
|
248
|
-
migrationsRecord = _a.sent();
|
|
249
|
-
migrations = {};
|
|
250
|
-
if (migrationsRecord) {
|
|
251
|
-
migrations = JSON.parse(migrationsRecord);
|
|
252
|
-
}
|
|
253
|
-
if (!!migrations.migrateToVersion1_0_1) return [3 /*break*/, 3];
|
|
254
|
-
return [4 /*yield*/, (0, migrations_1.migrateToVersion1_0_1)(this.client, this.options.sessionKeyPrefix, this.fullKey.bind(this))];
|
|
255
|
-
case 2:
|
|
256
|
-
_a.sent();
|
|
257
|
-
migrations.migrateToVersion1_0_1 = true;
|
|
258
|
-
_a.label = 3;
|
|
259
|
-
case 3: return [4 /*yield*/, this.client.set(this.fullKey('migrations'), JSON.stringify(migrations))];
|
|
260
|
-
case 4:
|
|
261
228
|
_a.sent();
|
|
262
229
|
return [2 /*return*/];
|
|
263
230
|
}
|
package/build/ts/redis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/redis.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../src/redis.ts"],"names":[],"mappings":";;;;AACA,oDAA6C;AAO7C,2CAA2C;AAC3C,u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