@shopify/shopify-app-session-storage 0.0.0-experimental-20240118200208

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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present, Shopify Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Session Storage
2
+
3
+ This folder contains the `SessionStorage` interface that the individual [packages](../) for most common databases implement.
4
+
5
+ See the [`session-storage.ts`](./src/types.ts) file for the methods that need to be implemented, the params they accept and values they return.
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var types = require('./types.js');
6
+
7
+ class AbstractMigrationEngine {
8
+ constructor(db, opts = {}, migrations) {
9
+ this.options = void 0;
10
+ this.connection = void 0;
11
+ this.ready = void 0;
12
+ this.migrations = void 0;
13
+ this.options = {
14
+ ...types.defaultSessionStorageMigratorOptions,
15
+ ...opts
16
+ };
17
+ this.connection = db;
18
+ this.migrations = migrations;
19
+ this.ready = this.initMigrationPersistence();
20
+ }
21
+ async applyMigrations(databaseReady) {
22
+ await databaseReady;
23
+ await this.ready;
24
+ for (const {
25
+ migrationName,
26
+ migrationFunction
27
+ } of this.getMigrationList()) {
28
+ const migrationApplied = await this.hasMigrationBeenApplied(migrationName);
29
+ if (!migrationApplied) {
30
+ await migrationFunction(this.connection);
31
+ await this.saveAppliedMigration(migrationName);
32
+ }
33
+ }
34
+ return Promise.resolve();
35
+ }
36
+ getMigrationList() {
37
+ return this.migrations;
38
+ }
39
+ }
40
+
41
+ exports.AbstractMigrationEngine = AbstractMigrationEngine;
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var types = require('./types.js');
6
+ var rdbmsSessionStorageMigrator = require('./rdbms-session-storage-migrator.js');
7
+ var abstractMigrationEngine = require('./abstract-migration-engine.js');
8
+
9
+
10
+
11
+ exports.MigrationOperation = types.MigrationOperation;
12
+ exports.defaultRdbmsSessionStorageMigratorOptions = types.defaultRdbmsSessionStorageMigratorOptions;
13
+ exports.defaultSessionStorageMigratorOptions = types.defaultSessionStorageMigratorOptions;
14
+ exports.RdbmsSessionStorageMigrator = rdbmsSessionStorageMigrator.RdbmsSessionStorageMigrator;
15
+ exports.AbstractMigrationEngine = abstractMigrationEngine.AbstractMigrationEngine;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var abstractMigrationEngine = require('./abstract-migration-engine.js');
6
+ var types = require('./types.js');
7
+
8
+ class RdbmsSessionStorageMigrator extends abstractMigrationEngine.AbstractMigrationEngine {
9
+ constructor(dbConnection, opts = {}, migrations) {
10
+ super(dbConnection, {
11
+ ...types.defaultRdbmsSessionStorageMigratorOptions,
12
+ ...opts
13
+ }, migrations);
14
+ }
15
+ async hasMigrationBeenApplied(migrationName) {
16
+ await this.ready;
17
+ const query = `
18
+ SELECT * FROM ${this.options.migrationDBIdentifier}
19
+ WHERE ${this.getOptions().migrationNameColumnName} =
20
+ ${this.connection.getArgumentPlaceholder(1)};
21
+ `;
22
+ const rows = await this.connection.query(query, [migrationName]);
23
+ return rows.length === 1;
24
+ }
25
+ async saveAppliedMigration(migrationName) {
26
+ await this.ready;
27
+ const insert = `
28
+ INSERT INTO ${this.options.migrationDBIdentifier} (${this.getOptions().migrationNameColumnName})
29
+ VALUES(${this.connection.getArgumentPlaceholder(1)});
30
+ `;
31
+ await this.connection.query(insert, [migrationName]);
32
+ }
33
+ getOptions() {
34
+ return this.options;
35
+ }
36
+ }
37
+
38
+ exports.RdbmsSessionStorageMigrator = RdbmsSessionStorageMigrator;
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Defines the strategy to be used to store sessions for the Shopify App.
7
+ */
8
+
9
+ /**
10
+ * define the option required to instantiate an RDBMS session storage implementation
11
+ */
12
+
13
+ /**
14
+ * Define a common way for migrator to execute query on the underlying persistence layer
15
+ */
16
+
17
+ /**
18
+ * This is for the use cases of the RDBMS database where
19
+ */
20
+
21
+ /**
22
+ * Each migration 'migration_name' will be define the following way.
23
+ * Via a function that receive the engine in parameter.
24
+ */
25
+
26
+ /**
27
+ * Defines what is needed for a migration to be execute
28
+ */
29
+ class MigrationOperation {
30
+ constructor(migrationName, migrationFunction) {
31
+ /** Name of the migration that will be used to uniquely identity it among all other migration */
32
+ this.migrationName = void 0;
33
+ /** The actual migration function that will modify the perisitence storage */
34
+ this.migrationFunction = void 0;
35
+ this.migrationName = migrationName;
36
+ this.migrationFunction = migrationFunction;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Defines how database migration will be handled.
42
+ */
43
+
44
+ /**
45
+ * Use to initialise session storage migrators
46
+ */
47
+
48
+ const defaultSessionStorageMigratorOptions = {
49
+ migrationDBIdentifier: 'shopify_sessions_migrations'
50
+ };
51
+ const defaultRdbmsSessionStorageMigratorOptions = {
52
+ migrationDBIdentifier: 'shopify_sessions_migrations',
53
+ migrationNameColumnName: 'migration_name'
54
+ };
55
+
56
+ exports.MigrationOperation = MigrationOperation;
57
+ exports.defaultRdbmsSessionStorageMigratorOptions = defaultRdbmsSessionStorageMigratorOptions;
58
+ exports.defaultSessionStorageMigratorOptions = defaultSessionStorageMigratorOptions;
@@ -0,0 +1,14 @@
1
+ import { MigrationOperation, SessionStorageMigrator, SessionStorageMigratorOptions, DBConnection } from './types';
2
+ export declare abstract class AbstractMigrationEngine<ConnectionType extends DBConnection, MigratorOptionType extends SessionStorageMigratorOptions> implements SessionStorageMigrator {
3
+ protected options: SessionStorageMigratorOptions;
4
+ protected connection: ConnectionType;
5
+ protected ready: Promise<void>;
6
+ protected migrations: MigrationOperation[];
7
+ constructor(db: ConnectionType, opts: Partial<MigratorOptionType> | undefined, migrations: MigrationOperation[]);
8
+ applyMigrations(databaseReady: Promise<void>): Promise<void>;
9
+ getMigrationList(): MigrationOperation[];
10
+ abstract initMigrationPersistence(): Promise<void>;
11
+ abstract hasMigrationBeenApplied(migrationName: string): Promise<boolean>;
12
+ abstract saveAppliedMigration(migrationName: string): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=abstract-migration-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-migration-engine.d.ts","sourceRoot":"","sources":["../../src/abstract-migration-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,6BAA6B,EAE7B,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,8BAAsB,uBAAuB,CAC3C,cAAc,SAAS,YAAY,EACnC,kBAAkB,SAAS,6BAA6B,CACxD,YAAW,sBAAsB;IAEjC,SAAS,CAAC,OAAO,EAAE,6BAA6B,CAAC;IACjD,SAAS,CAAC,UAAU,EAAE,cAAc,CAAC;IACrC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,SAAS,CAAC,UAAU,EAAE,kBAAkB,EAAE,CAAC;gBAGzC,EAAE,EAAE,cAAc,EAClB,IAAI,yCAAkC,EACtC,UAAU,EAAE,kBAAkB,EAAE;IAS5B,eAAe,CAAC,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBlE,gBAAgB,IAAI,kBAAkB,EAAE;IAIxC,QAAQ,CAAC,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAClD,QAAQ,CAAC,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IACzE,QAAQ,CAAC,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CACpE"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractMigrationEngine = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var types_1 = require("./types");
6
+ var AbstractMigrationEngine = /** @class */ (function () {
7
+ function AbstractMigrationEngine(db, opts, migrations) {
8
+ if (opts === void 0) { opts = {}; }
9
+ this.options = tslib_1.__assign(tslib_1.__assign({}, types_1.defaultSessionStorageMigratorOptions), opts);
10
+ this.connection = db;
11
+ this.migrations = migrations;
12
+ this.ready = this.initMigrationPersistence();
13
+ }
14
+ AbstractMigrationEngine.prototype.applyMigrations = function (databaseReady) {
15
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
16
+ var _a, _b, _c, migrationName, migrationFunction, migrationApplied, e_1_1;
17
+ var e_1, _d;
18
+ return tslib_1.__generator(this, function (_e) {
19
+ switch (_e.label) {
20
+ case 0: return [4 /*yield*/, databaseReady];
21
+ case 1:
22
+ _e.sent();
23
+ return [4 /*yield*/, this.ready];
24
+ case 2:
25
+ _e.sent();
26
+ _e.label = 3;
27
+ case 3:
28
+ _e.trys.push([3, 10, 11, 12]);
29
+ _a = tslib_1.__values(this.getMigrationList()), _b = _a.next();
30
+ _e.label = 4;
31
+ case 4:
32
+ if (!!_b.done) return [3 /*break*/, 9];
33
+ _c = _b.value, migrationName = _c.migrationName, migrationFunction = _c.migrationFunction;
34
+ return [4 /*yield*/, this.hasMigrationBeenApplied(migrationName)];
35
+ case 5:
36
+ migrationApplied = _e.sent();
37
+ if (!!migrationApplied) return [3 /*break*/, 8];
38
+ return [4 /*yield*/, migrationFunction(this.connection)];
39
+ case 6:
40
+ _e.sent();
41
+ return [4 /*yield*/, this.saveAppliedMigration(migrationName)];
42
+ case 7:
43
+ _e.sent();
44
+ _e.label = 8;
45
+ case 8:
46
+ _b = _a.next();
47
+ return [3 /*break*/, 4];
48
+ case 9: return [3 /*break*/, 12];
49
+ case 10:
50
+ e_1_1 = _e.sent();
51
+ e_1 = { error: e_1_1 };
52
+ return [3 /*break*/, 12];
53
+ case 11:
54
+ try {
55
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
56
+ }
57
+ finally { if (e_1) throw e_1.error; }
58
+ return [7 /*endfinally*/];
59
+ case 12: return [2 /*return*/, Promise.resolve()];
60
+ }
61
+ });
62
+ });
63
+ };
64
+ AbstractMigrationEngine.prototype.getMigrationList = function () {
65
+ return this.migrations;
66
+ };
67
+ return AbstractMigrationEngine;
68
+ }());
69
+ exports.AbstractMigrationEngine = AbstractMigrationEngine;
70
+ //# sourceMappingURL=abstract-migration-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-migration-engine.js","sourceRoot":"","sources":["../../src/abstract-migration-engine.ts"],"names":[],"mappings":";;;;AAAA,iCAMiB;AAEjB;IAUE,iCACE,EAAkB,EAClB,IAAsC,EACtC,UAAgC;QADhC,qBAAA,EAAA,SAAsC;QAGtC,IAAI,CAAC,OAAO,yCAAO,4CAAoC,GAAK,IAAI,CAAC,CAAC;QAClE,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAC/C,CAAC;IAEK,iDAAe,GAArB,UAAsB,aAA4B;;;;;;4BAChD,qBAAM,aAAa,EAAA;;wBAAnB,SAAmB,CAAC;wBACpB,qBAAM,IAAI,CAAC,KAAK,EAAA;;wBAAhB,SAAgB,CAAC;;;;wBAEgC,KAAA,iBAAA,IAAI,CAAC,gBAAgB,EAAE,CAAA;;;;wBAA7D,aAAkC,EAAjC,aAAa,mBAAA,EAAE,iBAAiB,uBAAA;wBACjB,qBAAM,IAAI,CAAC,uBAAuB,CACzD,aAAa,CACd,EAAA;;wBAFK,gBAAgB,GAAG,SAExB;6BACG,CAAC,gBAAgB,EAAjB,wBAAiB;wBACnB,qBAAM,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAA;;wBAAxC,SAAwC,CAAC;wBACzC,qBAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,EAAA;;wBAA9C,SAA8C,CAAC;;;;;;;;;;;;;;;;6BAGnD,sBAAO,OAAO,CAAC,OAAO,EAAE,EAAC;;;;KAC1B;IAED,kDAAgB,GAAhB;QACE,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAKH,8BAAC;AAAD,CAAC,AA7CD,IA6CC;AA7CqB,0DAAuB"}
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export * from './rdbms-session-storage-migrator';
3
+ export * from './abstract-migration-engine';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./types"), exports);
5
+ tslib_1.__exportStar(require("./rdbms-session-storage-migrator"), exports);
6
+ tslib_1.__exportStar(require("./abstract-migration-engine"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,2EAAiD;AACjD,sEAA4C"}
@@ -0,0 +1,10 @@
1
+ import { AbstractMigrationEngine } from './abstract-migration-engine';
2
+ import { RdbmsSessionStorageMigratorOptions, RdbmsConnection, MigrationOperation } from './types';
3
+ export declare abstract class RdbmsSessionStorageMigrator extends AbstractMigrationEngine<RdbmsConnection, RdbmsSessionStorageMigratorOptions> {
4
+ constructor(dbConnection: RdbmsConnection, opts: Partial<RdbmsSessionStorageMigratorOptions> | undefined, migrations: MigrationOperation[]);
5
+ hasMigrationBeenApplied(migrationName: string): Promise<boolean>;
6
+ saveAppliedMigration(migrationName: string): Promise<void>;
7
+ getOptions(): RdbmsSessionStorageMigratorOptions;
8
+ abstract initMigrationPersistence(): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=rdbms-session-storage-migrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rdbms-session-storage-migrator.d.ts","sourceRoot":"","sources":["../../src/rdbms-session-storage-migrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,6BAA6B,CAAC;AACpE,OAAO,EACL,kCAAkC,EAElC,eAAe,EACf,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,8BAAsB,2BAA4B,SAAQ,uBAAuB,CAC/E,eAAe,EACf,kCAAkC,CACnC;gBAEG,YAAY,EAAE,eAAe,EAC7B,IAAI,yDAAkD,EACtD,UAAU,EAAE,kBAAkB,EAAE;IAY5B,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAahE,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAazD,UAAU,IAAI,kCAAkC;IAIvD,QAAQ,CAAC,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;CACnD"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RdbmsSessionStorageMigrator = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var abstract_migration_engine_1 = require("./abstract-migration-engine");
6
+ var types_1 = require("./types");
7
+ var RdbmsSessionStorageMigrator = /** @class */ (function (_super) {
8
+ tslib_1.__extends(RdbmsSessionStorageMigrator, _super);
9
+ function RdbmsSessionStorageMigrator(dbConnection, opts, migrations) {
10
+ if (opts === void 0) { opts = {}; }
11
+ return _super.call(this, dbConnection, tslib_1.__assign(tslib_1.__assign({}, types_1.defaultRdbmsSessionStorageMigratorOptions), opts), migrations) || this;
12
+ }
13
+ RdbmsSessionStorageMigrator.prototype.hasMigrationBeenApplied = function (migrationName) {
14
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
15
+ var query, rows;
16
+ return tslib_1.__generator(this, function (_a) {
17
+ switch (_a.label) {
18
+ case 0: return [4 /*yield*/, this.ready];
19
+ case 1:
20
+ _a.sent();
21
+ query = "\n SELECT * FROM ".concat(this.options.migrationDBIdentifier, "\n WHERE ").concat(this.getOptions().migrationNameColumnName, " = \n ").concat(this.connection.getArgumentPlaceholder(1), ";\n ");
22
+ return [4 /*yield*/, this.connection.query(query, [migrationName])];
23
+ case 2:
24
+ rows = _a.sent();
25
+ return [2 /*return*/, rows.length === 1];
26
+ }
27
+ });
28
+ });
29
+ };
30
+ RdbmsSessionStorageMigrator.prototype.saveAppliedMigration = function (migrationName) {
31
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
32
+ var insert;
33
+ return tslib_1.__generator(this, function (_a) {
34
+ switch (_a.label) {
35
+ case 0: return [4 /*yield*/, this.ready];
36
+ case 1:
37
+ _a.sent();
38
+ insert = "\n INSERT INTO ".concat(this.options.migrationDBIdentifier, " (").concat(this.getOptions().migrationNameColumnName, ")\n VALUES(").concat(this.connection.getArgumentPlaceholder(1), ");\n ");
39
+ return [4 /*yield*/, this.connection.query(insert, [migrationName])];
40
+ case 2:
41
+ _a.sent();
42
+ return [2 /*return*/];
43
+ }
44
+ });
45
+ });
46
+ };
47
+ RdbmsSessionStorageMigrator.prototype.getOptions = function () {
48
+ return this.options;
49
+ };
50
+ return RdbmsSessionStorageMigrator;
51
+ }(abstract_migration_engine_1.AbstractMigrationEngine));
52
+ exports.RdbmsSessionStorageMigrator = RdbmsSessionStorageMigrator;
53
+ //# sourceMappingURL=rdbms-session-storage-migrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rdbms-session-storage-migrator.js","sourceRoot":"","sources":["../../src/rdbms-session-storage-migrator.ts"],"names":[],"mappings":";;;;AAAA,yEAAoE;AACpE,iCAKiB;AAEjB;IAA0D,uDAGzD;IACC,qCACE,YAA6B,EAC7B,IAAsD,EACtD,UAAgC;QADhC,qBAAA,EAAA,SAAsD;eAGtD,kBACE,YAAY,wCAEP,iDAAyC,GACzC,IAAI,GAET,UAAU,CACX;IACH,CAAC;IAEK,6DAAuB,GAA7B,UAA8B,aAAqB;;;;;4BACjD,qBAAM,IAAI,CAAC,KAAK,EAAA;;wBAAhB,SAAgB,CAAC;wBAEX,KAAK,GAAG,gCACI,IAAI,CAAC,OAAO,CAAC,qBAAqB,2BAC1C,IAAI,CAAC,UAAU,EAAE,CAAC,uBAAuB,0BAC7C,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,YAC9C,CAAC;wBAEW,qBAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,aAAa,CAAC,CAAC,EAAA;;wBAA1D,IAAI,GAAG,SAAmD;wBAChE,sBAAO,IAAI,CAAC,MAAM,KAAK,CAAC,EAAC;;;;KAC1B;IAEK,0DAAoB,GAA1B,UAA2B,aAAqB;;;;;4BAC9C,qBAAM,IAAI,CAAC,KAAK,EAAA;;wBAAhB,SAAgB,CAAC;wBAEX,MAAM,GAAG,kCACK,IAAI,CAAC,OAAO,CAAC,qBAAqB,eACpD,IAAI,CAAC,UAAU,EAAE,CAAC,uBAAuB,iCAE5B,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,iBACnD,CAAC;wBAEN,qBAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,EAAA;;wBAApD,SAAoD,CAAC;;;;;KACtD;IAEM,gDAAU,GAAjB;QACE,OAAO,IAAI,CAAC,OAA6C,CAAC;IAC5D,CAAC;IAGH,kCAAC;AAAD,CAAC,AAlDD,CAA0D,mDAAuB,GAkDhF;AAlDqB,kEAA2B"}
@@ -0,0 +1,139 @@
1
+ import { Session } from '@shopify/shopify-api';
2
+ /**
3
+ * Defines the strategy to be used to store sessions for the Shopify App.
4
+ */
5
+ export interface SessionStorage {
6
+ /**
7
+ * Creates or updates the given session in storage.
8
+ *
9
+ * @param session Session to store
10
+ */
11
+ storeSession(session: Session): Promise<boolean>;
12
+ /**
13
+ * Loads a session from storage.
14
+ *
15
+ * @param id Id of the session to load
16
+ */
17
+ loadSession(id: string): Promise<Session | undefined>;
18
+ /**
19
+ * Deletes a session from storage.
20
+ *
21
+ * @param id Id of the session to delete
22
+ */
23
+ deleteSession(id: string): Promise<boolean>;
24
+ /**
25
+ * Deletes an array of sessions from storage.
26
+ *
27
+ * @param ids Array of session id's to delete
28
+ */
29
+ deleteSessions(ids: string[]): Promise<boolean>;
30
+ /**
31
+ * Return an array of sessions for a given shop (or [] if none found).
32
+ *
33
+ * @param shop shop of the session(s) to return
34
+ */
35
+ findSessionsByShop(shop: string): Promise<Session[]>;
36
+ }
37
+ /**
38
+ * define the option required to instantiate an RDBMS session storage implementation
39
+ */
40
+ export interface RdbmsSessionStorageOptions {
41
+ sessionTableName: string;
42
+ migratorOptions?: RdbmsSessionStorageMigratorOptions;
43
+ }
44
+ /**
45
+ * Define a common way for migrator to execute query on the underlying persistence layer
46
+ */
47
+ export interface DBConnection {
48
+ /** the table used to store sessions */
49
+ sessionStorageIdentifier: string;
50
+ /**
51
+ * Initiate the actual connection to the underlying database
52
+ */
53
+ connect(): Promise<void>;
54
+ /**
55
+ * Disconnect from the underlying database
56
+ */
57
+ disconnect(): Promise<void>;
58
+ }
59
+ /**
60
+ * This is for the use cases of the RDBMS database where
61
+ */
62
+ export interface RdbmsConnection extends DBConnection {
63
+ /**
64
+ * Make a query to the underlying DB
65
+ * @param query - the query to execute
66
+ * @param params - the parameters required by the query
67
+ */
68
+ query(query: string, params: any[]): Promise<any[]>;
69
+ /**
70
+ * Determine if a table exist
71
+ * @param tablename - the table to search
72
+ */
73
+ hasTable(tablename: string): Promise<boolean>;
74
+ /**
75
+ * Based on the the #sqlArgumentPlaceholder value and the underlying engine, return the place holder for a given position in a list of sql argument
76
+ * @param position the position of the given sql argument
77
+ */
78
+ getArgumentPlaceholder(position?: number): string;
79
+ }
80
+ /**
81
+ * Each migration 'migration_name' will be define the following way.
82
+ * Via a function that receive the engine in parameter.
83
+ */
84
+ export type MigrationFunction = (engine: DBConnection) => Promise<void>;
85
+ /**
86
+ * Defines what is needed for a migration to be execute
87
+ */
88
+ export declare class MigrationOperation {
89
+ /** Name of the migration that will be used to uniquely identity it among all other migration */
90
+ migrationName: string;
91
+ /** The actual migration function that will modify the perisitence storage */
92
+ migrationFunction: MigrationFunction;
93
+ constructor(migrationName: string, migrationFunction: MigrationFunction);
94
+ }
95
+ /**
96
+ * Defines how database migration will be handled.
97
+ */
98
+ export interface SessionStorageMigrator {
99
+ /**
100
+ * Should ensure that the persistence 'table' is created if it does not exist yet.
101
+ */
102
+ initMigrationPersistence(): Promise<void>;
103
+ /**
104
+ * Returns true if the migrationName as already been applied and
105
+ * therefore the migrator should not apply it. if false,
106
+ * the migrator will run the associated migration
107
+ * @param migrationName the unique version name to look for in the migration table
108
+ */
109
+ hasMigrationBeenApplied(migrationName: string): Promise<boolean>;
110
+ /**
111
+ * Will persist that this migrationName has been applied in the migration table
112
+ * @param migrationName the version to persisited as applied
113
+ */
114
+ saveAppliedMigration(migrationName: string): Promise<void>;
115
+ /**
116
+ * Return a list MigrationOperation that needs to be executed
117
+ */
118
+ getMigrationList(): MigrationOperation[];
119
+ /**
120
+ * Will iterate over the map returned by #getmigrationList,
121
+ * for each entry call #hasMigrationBeenApplied, if it returns false
122
+ * it will execute execute the function and then call #saveAppliedMigration
123
+ * @param databaseReady - so that the migrator can wait for the database to fully up and running
124
+ * before starting its execution.
125
+ */
126
+ applyMigrations(databaseReady: Promise<void>): Promise<void>;
127
+ }
128
+ /**
129
+ * Use to initialise session storage migrators
130
+ */
131
+ export interface SessionStorageMigratorOptions {
132
+ migrationDBIdentifier: string;
133
+ }
134
+ export declare const defaultSessionStorageMigratorOptions: SessionStorageMigratorOptions;
135
+ export interface RdbmsSessionStorageMigratorOptions extends SessionStorageMigratorOptions {
136
+ migrationNameColumnName: string;
137
+ }
138
+ export declare const defaultRdbmsSessionStorageMigratorOptions: RdbmsSessionStorageMigratorOptions;
139
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjD;;;;OAIG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IAEtD;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE5C;;;;OAIG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhD;;;;OAIG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,kCAAkC,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,wBAAwB,EAAE,MAAM,CAAC;IAEjC;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,YAAY;IACnD;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEpD;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9C;;;OAGG;IACH,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACnD;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAExE;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,gGAAgG;IAChG,aAAa,EAAE,MAAM,CAAC;IAEtB,6EAA6E;IAC7E,iBAAiB,EAAE,iBAAiB,CAAC;gBAEzB,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB;CAIxE;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1C;;;;;OAKG;IACH,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEjE;;;OAGG;IACH,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3D;;OAEG;IACH,gBAAgB,IAAI,kBAAkB,EAAE,CAAC;IAEzC;;;;;;OAMG;IACH,eAAe,CAAC,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9D;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,eAAO,MAAM,oCAAoC,EAAE,6BAGhD,CAAC;AAEJ,MAAM,WAAW,kCACf,SAAQ,6BAA6B;IACrC,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED,eAAO,MAAM,yCAAyC,EAAE,kCAIrD,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultRdbmsSessionStorageMigratorOptions = exports.defaultSessionStorageMigratorOptions = exports.MigrationOperation = void 0;
4
+ /**
5
+ * Defines what is needed for a migration to be execute
6
+ */
7
+ var MigrationOperation = /** @class */ (function () {
8
+ function MigrationOperation(migrationName, migrationFunction) {
9
+ this.migrationName = migrationName;
10
+ this.migrationFunction = migrationFunction;
11
+ }
12
+ return MigrationOperation;
13
+ }());
14
+ exports.MigrationOperation = MigrationOperation;
15
+ exports.defaultSessionStorageMigratorOptions = {
16
+ migrationDBIdentifier: 'shopify_sessions_migrations',
17
+ };
18
+ exports.defaultRdbmsSessionStorageMigratorOptions = {
19
+ migrationDBIdentifier: 'shopify_sessions_migrations',
20
+ migrationNameColumnName: 'migration_name',
21
+ };
22
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAkGA;;GAEG;AACH;IAOE,4BAAY,aAAqB,EAAE,iBAAoC;QACrE,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IACH,yBAAC;AAAD,CAAC,AAXD,IAWC;AAXY,gDAAkB;AA0DlB,QAAA,oCAAoC,GAC/C;IACE,qBAAqB,EAAE,6BAA6B;CACrD,CAAC;AAOS,QAAA,yCAAyC,GACpD;IACE,qBAAqB,EAAE,6BAA6B;IACpD,uBAAuB,EAAE,gBAAgB;CAC1C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@shopify/shopify-app-session-storage",
3
+ "version": "0.0.0-experimental-20240118200208",
4
+ "description": "Shopify App Session Storage - abstract class",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Shopify/shopify-app-js.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/Shopify/shopify-app-js/issues"
11
+ },
12
+ "homepage": "https://github.com/Shopify/shopify-app-js/tree/main/packages/shopify-app-session-storage",
13
+ "author": "Shopify Inc.",
14
+ "license": "MIT",
15
+ "main": "./build/cjs/index.js",
16
+ "types": "./build/ts/index.d.ts",
17
+ "scripts": {},
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "@shopify:registry": "https://registry.npmjs.org"
21
+ },
22
+ "keywords": [
23
+ "shopify",
24
+ "node",
25
+ "app",
26
+ "graphql",
27
+ "rest",
28
+ "webhook",
29
+ "Admin API",
30
+ "Storefront API",
31
+ "session storage"
32
+ ],
33
+ "dependencies": {
34
+ "tslib": "^2.6.2"
35
+ },
36
+ "peerDependencies": {
37
+ "@shopify/shopify-api": "^9.0.2"
38
+ },
39
+ "devDependencies": {
40
+ "@shopify/eslint-plugin": "^42.1.0",
41
+ "@shopify/prettier-config": "^1.1.2",
42
+ "@types/jest": "^29.5.1",
43
+ "eslint": "^8.55.0",
44
+ "eslint-plugin-prettier": "^4.2.1",
45
+ "prettier": "^2.8.8",
46
+ "typescript": "^4.9.5"
47
+ },
48
+ "files": [
49
+ "build/*",
50
+ "!bundle/*",
51
+ "!tsconfig.tsbuildinfo",
52
+ "!node_modules"
53
+ ]
54
+ }