@boxyhq/saml-jackson 0.2.3-beta.235 → 0.2.3-beta.240
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/dist/controller/api.d.ts +32 -0
- package/dist/controller/api.js +193 -0
- package/dist/controller/error.d.ts +5 -0
- package/dist/controller/error.js +12 -0
- package/dist/controller/oauth/allowed.d.ts +1 -0
- package/dist/controller/oauth/allowed.js +17 -0
- package/dist/controller/oauth/code-verifier.d.ts +2 -0
- package/dist/controller/oauth/code-verifier.js +15 -0
- package/dist/controller/oauth/redirect.d.ts +1 -0
- package/dist/controller/oauth/redirect.js +11 -0
- package/dist/controller/oauth.d.ts +23 -0
- package/dist/controller/oauth.js +263 -0
- package/dist/controller/utils.d.ts +6 -0
- package/dist/controller/utils.js +17 -0
- package/dist/db/db.d.ts +15 -0
- package/dist/db/db.js +107 -0
- package/dist/db/encrypter.d.ts +3 -0
- package/dist/db/encrypter.js +29 -0
- package/dist/db/mem.d.ts +20 -0
- package/dist/db/mem.js +128 -0
- package/dist/db/mongo.d.ts +17 -0
- package/dist/db/mongo.js +106 -0
- package/dist/db/redis.d.ts +15 -0
- package/dist/db/redis.js +107 -0
- package/dist/db/sql/entity/JacksonIndex.d.ts +7 -0
- package/dist/db/sql/entity/JacksonIndex.js +41 -0
- package/dist/db/sql/entity/JacksonStore.d.ts +6 -0
- package/dist/db/sql/entity/JacksonStore.js +42 -0
- package/dist/db/sql/entity/JacksonTTL.d.ts +4 -0
- package/dist/db/sql/entity/JacksonTTL.js +29 -0
- package/dist/db/sql/sql.d.ts +20 -0
- package/dist/db/sql/sql.js +174 -0
- package/dist/db/store.d.ts +5 -0
- package/dist/db/store.js +68 -0
- package/dist/db/utils.d.ts +7 -0
- package/dist/db/utils.js +29 -0
- package/dist/env.d.ts +22 -0
- package/dist/env.js +35 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +80 -0
- package/dist/jackson.d.ts +1 -0
- package/dist/jackson.js +153 -0
- package/dist/read-config.d.ts +3 -0
- package/dist/read-config.js +50 -0
- package/dist/saml/claims.d.ts +6 -0
- package/dist/saml/claims.js +35 -0
- package/dist/saml/saml.d.ts +11 -0
- package/dist/saml/saml.js +200 -0
- package/dist/saml/x509.d.ts +7 -0
- package/dist/saml/x509.js +69 -0
- package/dist/typings.d.ts +137 -0
- package/dist/typings.js +2 -0
- package/package.json +2 -1
package/dist/db/db.js
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
+
}) : function(o, v) {
|
12
|
+
o["default"] = v;
|
13
|
+
});
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
+
if (mod && mod.__esModule) return mod;
|
16
|
+
var result = {};
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
+
__setModuleDefault(result, mod);
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
28
|
+
});
|
29
|
+
};
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
32
|
+
};
|
33
|
+
const encrypter = __importStar(require("./encrypter"));
|
34
|
+
const mem_1 = __importDefault(require("./mem"));
|
35
|
+
const mongo_1 = __importDefault(require("./mongo"));
|
36
|
+
const redis_1 = __importDefault(require("./redis"));
|
37
|
+
const sql_1 = __importDefault(require("./sql/sql"));
|
38
|
+
const store_1 = __importDefault(require("./store"));
|
39
|
+
const decrypt = (res, encryptionKey) => {
|
40
|
+
if (res.iv && res.tag) {
|
41
|
+
return JSON.parse(encrypter.decrypt(res.value, res.iv, res.tag, encryptionKey));
|
42
|
+
}
|
43
|
+
return JSON.parse(res.value);
|
44
|
+
};
|
45
|
+
class DB {
|
46
|
+
constructor(db, encryptionKey) {
|
47
|
+
this.db = db;
|
48
|
+
this.encryptionKey = encryptionKey;
|
49
|
+
}
|
50
|
+
get(namespace, key) {
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
52
|
+
const res = yield this.db.get(namespace, key);
|
53
|
+
if (!res) {
|
54
|
+
return null;
|
55
|
+
}
|
56
|
+
return decrypt(res, this.encryptionKey);
|
57
|
+
});
|
58
|
+
}
|
59
|
+
getByIndex(namespace, idx) {
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
61
|
+
const res = yield this.db.getByIndex(namespace, idx);
|
62
|
+
const encryptionKey = this.encryptionKey;
|
63
|
+
return res.map((r) => {
|
64
|
+
return decrypt(r, encryptionKey);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
}
|
68
|
+
// ttl is in seconds
|
69
|
+
put(namespace, key, val, ttl = 0, ...indexes) {
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
71
|
+
if (ttl > 0 && indexes && indexes.length > 0) {
|
72
|
+
throw new Error('secondary indexes not allow on a store with ttl');
|
73
|
+
}
|
74
|
+
const dbVal = this.encryptionKey
|
75
|
+
? encrypter.encrypt(JSON.stringify(val), this.encryptionKey)
|
76
|
+
: { value: JSON.stringify(val) };
|
77
|
+
return yield this.db.put(namespace, key, dbVal, ttl, ...indexes);
|
78
|
+
});
|
79
|
+
}
|
80
|
+
delete(namespace, key) {
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
82
|
+
return yield this.db.delete(namespace, key);
|
83
|
+
});
|
84
|
+
}
|
85
|
+
store(namespace, ttl = 0) {
|
86
|
+
return store_1.default.new(namespace, this, ttl);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
module.exports = {
|
90
|
+
new: (options) => __awaiter(void 0, void 0, void 0, function* () {
|
91
|
+
const encryptionKey = options.encryptionKey
|
92
|
+
? Buffer.from(options.encryptionKey, 'latin1')
|
93
|
+
: null;
|
94
|
+
switch (options.engine) {
|
95
|
+
case 'redis':
|
96
|
+
return new DB(yield redis_1.default.new(options), encryptionKey);
|
97
|
+
case 'sql':
|
98
|
+
return new DB(yield sql_1.default.new(options), encryptionKey);
|
99
|
+
case 'mongo':
|
100
|
+
return new DB(yield mongo_1.default.new(options), encryptionKey);
|
101
|
+
case 'mem':
|
102
|
+
return new DB(yield mem_1.default.new(options), encryptionKey);
|
103
|
+
default:
|
104
|
+
throw new Error('unsupported db engine: ' + options.engine);
|
105
|
+
}
|
106
|
+
}),
|
107
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.decrypt = exports.encrypt = void 0;
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
8
|
+
const ALGO = 'aes-256-gcm';
|
9
|
+
const BLOCK_SIZE = 16; // 128 bit
|
10
|
+
const encrypt = (text, key) => {
|
11
|
+
const iv = crypto_1.default.randomBytes(BLOCK_SIZE);
|
12
|
+
const cipher = crypto_1.default.createCipheriv(ALGO, key, iv);
|
13
|
+
let ciphertext = cipher.update(text, 'utf8', 'base64');
|
14
|
+
ciphertext += cipher.final('base64');
|
15
|
+
return {
|
16
|
+
iv: iv.toString('base64'),
|
17
|
+
tag: cipher.getAuthTag().toString('base64'),
|
18
|
+
value: ciphertext,
|
19
|
+
};
|
20
|
+
};
|
21
|
+
exports.encrypt = encrypt;
|
22
|
+
const decrypt = (ciphertext, iv, tag, key) => {
|
23
|
+
const decipher = crypto_1.default.createDecipheriv(ALGO, key, Buffer.from(iv, 'base64'));
|
24
|
+
decipher.setAuthTag(Buffer.from(tag, 'base64'));
|
25
|
+
let cleartext = decipher.update(ciphertext, 'base64', 'utf8');
|
26
|
+
cleartext += decipher.final('utf8');
|
27
|
+
return cleartext;
|
28
|
+
};
|
29
|
+
exports.decrypt = decrypt;
|
package/dist/db/mem.d.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import { DatabaseDriver, DatabaseOption, Index, Encrypted } from '../typings';
|
2
|
+
declare class Mem implements DatabaseDriver {
|
3
|
+
private options;
|
4
|
+
private store;
|
5
|
+
private indexes;
|
6
|
+
private cleanup;
|
7
|
+
private ttlStore;
|
8
|
+
private ttlCleanup;
|
9
|
+
private timerId;
|
10
|
+
constructor(options: DatabaseOption);
|
11
|
+
init(): Promise<Mem>;
|
12
|
+
get(namespace: string, key: string): Promise<any>;
|
13
|
+
getByIndex(namespace: string, idx: Index): Promise<any>;
|
14
|
+
put(namespace: string, key: string, val: Encrypted, ttl?: number, ...indexes: any[]): Promise<any>;
|
15
|
+
delete(namespace: string, key: string): Promise<any>;
|
16
|
+
}
|
17
|
+
declare const _default: {
|
18
|
+
new: (options: DatabaseOption) => Promise<Mem>;
|
19
|
+
};
|
20
|
+
export default _default;
|
package/dist/db/mem.js
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
"use strict";
|
2
|
+
// This is an in-memory implementation to be used with testing and prototyping only
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
4
|
+
if (k2 === undefined) k2 = k;
|
5
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
6
|
+
}) : (function(o, m, k, k2) {
|
7
|
+
if (k2 === undefined) k2 = k;
|
8
|
+
o[k2] = m[k];
|
9
|
+
}));
|
10
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
11
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
12
|
+
}) : function(o, v) {
|
13
|
+
o["default"] = v;
|
14
|
+
});
|
15
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
16
|
+
if (mod && mod.__esModule) return mod;
|
17
|
+
var result = {};
|
18
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
19
|
+
__setModuleDefault(result, mod);
|
20
|
+
return result;
|
21
|
+
};
|
22
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
23
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
24
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
25
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
27
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
28
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
29
|
+
});
|
30
|
+
};
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
32
|
+
const dbutils = __importStar(require("./utils"));
|
33
|
+
class Mem {
|
34
|
+
constructor(options) {
|
35
|
+
this.options = options;
|
36
|
+
}
|
37
|
+
init() {
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
39
|
+
this.store = {}; // map of key, value
|
40
|
+
this.indexes = {}; // map of key, Set
|
41
|
+
this.cleanup = {}; // map of indexes for cleanup when store key is deleted
|
42
|
+
this.ttlStore = {}; // map of key to ttl
|
43
|
+
if (this.options.ttl) {
|
44
|
+
this.ttlCleanup = () => __awaiter(this, void 0, void 0, function* () {
|
45
|
+
const now = Date.now();
|
46
|
+
for (const k in this.ttlStore) {
|
47
|
+
if (this.ttlStore[k].expiresAt < now) {
|
48
|
+
yield this.delete(this.ttlStore[k].namespace, this.ttlStore[k].key);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
if (this.options.ttl) {
|
52
|
+
this.timerId = setTimeout(this.ttlCleanup, this.options.ttl * 1000);
|
53
|
+
}
|
54
|
+
});
|
55
|
+
this.timerId = setTimeout(this.ttlCleanup, this.options.ttl * 1000);
|
56
|
+
}
|
57
|
+
return this;
|
58
|
+
});
|
59
|
+
}
|
60
|
+
get(namespace, key) {
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
62
|
+
const res = this.store[dbutils.key(namespace, key)];
|
63
|
+
if (res) {
|
64
|
+
return res;
|
65
|
+
}
|
66
|
+
return null;
|
67
|
+
});
|
68
|
+
}
|
69
|
+
getByIndex(namespace, idx) {
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
71
|
+
const dbKeys = yield this.indexes[dbutils.keyForIndex(namespace, idx)];
|
72
|
+
const ret = [];
|
73
|
+
for (const dbKey of dbKeys || []) {
|
74
|
+
ret.push(yield this.get(namespace, dbKey));
|
75
|
+
}
|
76
|
+
return ret;
|
77
|
+
});
|
78
|
+
}
|
79
|
+
put(namespace, key, val, ttl = 0, ...indexes) {
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
81
|
+
const k = dbutils.key(namespace, key);
|
82
|
+
this.store[k] = val;
|
83
|
+
if (ttl) {
|
84
|
+
this.ttlStore[k] = {
|
85
|
+
namespace,
|
86
|
+
key,
|
87
|
+
expiresAt: Date.now() + ttl * 1000,
|
88
|
+
};
|
89
|
+
}
|
90
|
+
// no ttl support for secondary indexes
|
91
|
+
for (const idx of indexes || []) {
|
92
|
+
const idxKey = dbutils.keyForIndex(namespace, idx);
|
93
|
+
let set = this.indexes[idxKey];
|
94
|
+
if (!set) {
|
95
|
+
set = new Set();
|
96
|
+
this.indexes[idxKey] = set;
|
97
|
+
}
|
98
|
+
set.add(key);
|
99
|
+
const cleanupKey = dbutils.keyFromParts(dbutils.indexPrefix, k);
|
100
|
+
let cleanup = this.cleanup[cleanupKey];
|
101
|
+
if (!cleanup) {
|
102
|
+
cleanup = new Set();
|
103
|
+
this.cleanup[cleanupKey] = cleanup;
|
104
|
+
}
|
105
|
+
cleanup.add(idxKey);
|
106
|
+
}
|
107
|
+
});
|
108
|
+
}
|
109
|
+
delete(namespace, key) {
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
111
|
+
const k = dbutils.key(namespace, key);
|
112
|
+
delete this.store[k];
|
113
|
+
const idxKey = dbutils.keyFromParts(dbutils.indexPrefix, k);
|
114
|
+
// delete secondary indexes and then the mapping of the seconary indexes
|
115
|
+
const dbKeys = this.cleanup[idxKey];
|
116
|
+
for (const dbKey of dbKeys || []) {
|
117
|
+
this.indexes[dbKey] && this.indexes[dbKey].delete(key);
|
118
|
+
}
|
119
|
+
delete this.cleanup[idxKey];
|
120
|
+
delete this.ttlStore[k];
|
121
|
+
});
|
122
|
+
}
|
123
|
+
}
|
124
|
+
exports.default = {
|
125
|
+
new: (options) => __awaiter(void 0, void 0, void 0, function* () {
|
126
|
+
return yield new Mem(options).init();
|
127
|
+
}),
|
128
|
+
};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { DatabaseDriver, DatabaseOption, Encrypted, Index } from '../typings';
|
2
|
+
declare class Mongo implements DatabaseDriver {
|
3
|
+
private options;
|
4
|
+
private client;
|
5
|
+
private collection;
|
6
|
+
private db;
|
7
|
+
constructor(options: DatabaseOption);
|
8
|
+
init(): Promise<Mongo>;
|
9
|
+
get(namespace: string, key: string): Promise<any>;
|
10
|
+
getByIndex(namespace: string, idx: Index): Promise<any>;
|
11
|
+
put(namespace: string, key: string, val: Encrypted, ttl?: number, ...indexes: any[]): Promise<void>;
|
12
|
+
delete(namespace: string, key: string): Promise<any>;
|
13
|
+
}
|
14
|
+
declare const _default: {
|
15
|
+
new: (options: DatabaseOption) => Promise<Mongo>;
|
16
|
+
};
|
17
|
+
export default _default;
|
package/dist/db/mongo.js
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
+
}) : function(o, v) {
|
12
|
+
o["default"] = v;
|
13
|
+
});
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
+
if (mod && mod.__esModule) return mod;
|
16
|
+
var result = {};
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
+
__setModuleDefault(result, mod);
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
28
|
+
});
|
29
|
+
};
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
31
|
+
const mongodb_1 = require("mongodb");
|
32
|
+
const dbutils = __importStar(require("./utils"));
|
33
|
+
class Mongo {
|
34
|
+
constructor(options) {
|
35
|
+
this.options = options;
|
36
|
+
}
|
37
|
+
init() {
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
39
|
+
this.client = new mongodb_1.MongoClient(this.options.url);
|
40
|
+
yield this.client.connect();
|
41
|
+
this.db = this.client.db();
|
42
|
+
this.collection = this.db.collection('jacksonStore');
|
43
|
+
yield this.collection.createIndex({ indexes: 1 });
|
44
|
+
yield this.collection.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 1 });
|
45
|
+
return this;
|
46
|
+
});
|
47
|
+
}
|
48
|
+
get(namespace, key) {
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
50
|
+
const res = yield this.collection.findOne({
|
51
|
+
_id: dbutils.key(namespace, key),
|
52
|
+
});
|
53
|
+
if (res && res.value) {
|
54
|
+
return res.value;
|
55
|
+
}
|
56
|
+
return null;
|
57
|
+
});
|
58
|
+
}
|
59
|
+
getByIndex(namespace, idx) {
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
61
|
+
const docs = yield this.collection
|
62
|
+
.find({
|
63
|
+
indexes: dbutils.keyForIndex(namespace, idx),
|
64
|
+
})
|
65
|
+
.toArray();
|
66
|
+
const ret = [];
|
67
|
+
for (const doc of docs || []) {
|
68
|
+
ret.push(doc.value);
|
69
|
+
}
|
70
|
+
return ret;
|
71
|
+
});
|
72
|
+
}
|
73
|
+
put(namespace, key, val, ttl = 0, ...indexes) {
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
75
|
+
const doc = {
|
76
|
+
value: val,
|
77
|
+
};
|
78
|
+
if (ttl) {
|
79
|
+
doc.expiresAt = new Date(Date.now() + ttl * 1000);
|
80
|
+
}
|
81
|
+
// no ttl support for secondary indexes
|
82
|
+
for (const idx of indexes || []) {
|
83
|
+
const idxKey = dbutils.keyForIndex(namespace, idx);
|
84
|
+
if (!doc.indexes) {
|
85
|
+
doc.indexes = [];
|
86
|
+
}
|
87
|
+
doc.indexes.push(idxKey);
|
88
|
+
}
|
89
|
+
yield this.collection.updateOne({ _id: dbutils.key(namespace, key) }, {
|
90
|
+
$set: doc,
|
91
|
+
}, { upsert: true });
|
92
|
+
});
|
93
|
+
}
|
94
|
+
delete(namespace, key) {
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
96
|
+
return yield this.collection.deleteOne({
|
97
|
+
_id: dbutils.key(namespace, key),
|
98
|
+
});
|
99
|
+
});
|
100
|
+
}
|
101
|
+
}
|
102
|
+
exports.default = {
|
103
|
+
new: (options) => __awaiter(void 0, void 0, void 0, function* () {
|
104
|
+
return yield new Mongo(options).init();
|
105
|
+
}),
|
106
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { DatabaseDriver, DatabaseOption, Encrypted, Index } from '../typings';
|
2
|
+
declare class Redis implements DatabaseDriver {
|
3
|
+
private options;
|
4
|
+
private client;
|
5
|
+
constructor(options: DatabaseOption);
|
6
|
+
init(): Promise<Redis>;
|
7
|
+
get(namespace: string, key: string): Promise<any>;
|
8
|
+
getByIndex(namespace: string, idx: Index): Promise<any>;
|
9
|
+
put(namespace: string, key: string, val: Encrypted, ttl?: number, ...indexes: any[]): Promise<void>;
|
10
|
+
delete(namespace: string, key: string): Promise<any>;
|
11
|
+
}
|
12
|
+
declare const _default: {
|
13
|
+
new: (options: DatabaseOption) => Promise<Redis>;
|
14
|
+
};
|
15
|
+
export default _default;
|
package/dist/db/redis.js
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
+
}) : function(o, v) {
|
12
|
+
o["default"] = v;
|
13
|
+
});
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
+
if (mod && mod.__esModule) return mod;
|
16
|
+
var result = {};
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
+
__setModuleDefault(result, mod);
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
28
|
+
});
|
29
|
+
};
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
31
|
+
const redis = __importStar(require("redis"));
|
32
|
+
const dbutils = __importStar(require("./utils"));
|
33
|
+
class Redis {
|
34
|
+
constructor(options) {
|
35
|
+
this.options = options;
|
36
|
+
}
|
37
|
+
init() {
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
39
|
+
const opts = {};
|
40
|
+
if (this.options && this.options.url) {
|
41
|
+
opts['socket'] = {
|
42
|
+
url: this.options.url,
|
43
|
+
};
|
44
|
+
}
|
45
|
+
this.client = redis.createClient(opts);
|
46
|
+
this.client.on('error', (err) => console.log('Redis Client Error', err));
|
47
|
+
yield this.client.connect();
|
48
|
+
return this;
|
49
|
+
});
|
50
|
+
}
|
51
|
+
get(namespace, key) {
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
53
|
+
const res = yield this.client.get(dbutils.key(namespace, key));
|
54
|
+
if (res) {
|
55
|
+
return JSON.parse(res);
|
56
|
+
}
|
57
|
+
return null;
|
58
|
+
});
|
59
|
+
}
|
60
|
+
getByIndex(namespace, idx) {
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
62
|
+
const dbKeys = yield this.client.sMembers(dbutils.keyForIndex(namespace, idx));
|
63
|
+
const ret = [];
|
64
|
+
for (const dbKey of dbKeys || []) {
|
65
|
+
ret.push(yield this.get(namespace, dbKey));
|
66
|
+
}
|
67
|
+
return ret;
|
68
|
+
});
|
69
|
+
}
|
70
|
+
put(namespace, key, val, ttl = 0, ...indexes) {
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
72
|
+
let tx = this.client.multi();
|
73
|
+
const k = dbutils.key(namespace, key);
|
74
|
+
tx = tx.set(k, JSON.stringify(val));
|
75
|
+
if (ttl) {
|
76
|
+
tx = tx.expire(k, ttl);
|
77
|
+
}
|
78
|
+
// no ttl support for secondary indexes
|
79
|
+
for (const idx of indexes || []) {
|
80
|
+
const idxKey = dbutils.keyForIndex(namespace, idx);
|
81
|
+
tx = tx.sAdd(idxKey, key);
|
82
|
+
tx = tx.sAdd(dbutils.keyFromParts(dbutils.indexPrefix, k), idxKey);
|
83
|
+
}
|
84
|
+
yield tx.exec();
|
85
|
+
});
|
86
|
+
}
|
87
|
+
delete(namespace, key) {
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
89
|
+
let tx = this.client.multi();
|
90
|
+
const k = dbutils.key(namespace, key);
|
91
|
+
tx = tx.del(k);
|
92
|
+
const idxKey = dbutils.keyFromParts(dbutils.indexPrefix, k);
|
93
|
+
// delete secondary indexes and then the mapping of the seconary indexes
|
94
|
+
const dbKeys = yield this.client.sMembers(idxKey);
|
95
|
+
for (const dbKey of dbKeys || []) {
|
96
|
+
tx.sRem(dbKey, key);
|
97
|
+
}
|
98
|
+
tx.del(idxKey);
|
99
|
+
return yield tx.exec();
|
100
|
+
});
|
101
|
+
}
|
102
|
+
}
|
103
|
+
exports.default = {
|
104
|
+
new: (options) => __awaiter(void 0, void 0, void 0, function* () {
|
105
|
+
return yield new Redis(options).init();
|
106
|
+
}),
|
107
|
+
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.JacksonIndex = void 0;
|
10
|
+
const JacksonStore_1 = require("./JacksonStore");
|
11
|
+
const typeorm_1 = require("typeorm");
|
12
|
+
let JacksonIndex = class JacksonIndex {
|
13
|
+
};
|
14
|
+
__decorate([
|
15
|
+
(0, typeorm_1.PrimaryGeneratedColumn)()
|
16
|
+
], JacksonIndex.prototype, "id", void 0);
|
17
|
+
__decorate([
|
18
|
+
(0, typeorm_1.Index)('_jackson_index_key'),
|
19
|
+
(0, typeorm_1.Column)({
|
20
|
+
type: 'varchar',
|
21
|
+
length: 1500,
|
22
|
+
})
|
23
|
+
], JacksonIndex.prototype, "key", void 0);
|
24
|
+
__decorate([
|
25
|
+
(0, typeorm_1.Column)({
|
26
|
+
type: 'varchar',
|
27
|
+
length: 1500,
|
28
|
+
})
|
29
|
+
], JacksonIndex.prototype, "storeKey", void 0);
|
30
|
+
__decorate([
|
31
|
+
(0, typeorm_1.ManyToOne)(() => JacksonStore_1.JacksonStore, undefined, {
|
32
|
+
//inverseSide: 'in',
|
33
|
+
eager: true,
|
34
|
+
onDelete: 'CASCADE',
|
35
|
+
})
|
36
|
+
], JacksonIndex.prototype, "store", void 0);
|
37
|
+
JacksonIndex = __decorate([
|
38
|
+
(0, typeorm_1.Index)('_jackson_index_key_store', ['key', 'storeKey']),
|
39
|
+
(0, typeorm_1.Entity)()
|
40
|
+
], JacksonIndex);
|
41
|
+
exports.JacksonIndex = JacksonIndex;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.JacksonStore = void 0;
|
10
|
+
const typeorm_1 = require("typeorm");
|
11
|
+
let JacksonStore = class JacksonStore {
|
12
|
+
};
|
13
|
+
__decorate([
|
14
|
+
(0, typeorm_1.Column)({
|
15
|
+
primary: true,
|
16
|
+
type: 'varchar',
|
17
|
+
length: 1500,
|
18
|
+
})
|
19
|
+
], JacksonStore.prototype, "key", void 0);
|
20
|
+
__decorate([
|
21
|
+
(0, typeorm_1.Column)({
|
22
|
+
type: 'text',
|
23
|
+
})
|
24
|
+
], JacksonStore.prototype, "value", void 0);
|
25
|
+
__decorate([
|
26
|
+
(0, typeorm_1.Column)({
|
27
|
+
type: 'varchar',
|
28
|
+
length: 64,
|
29
|
+
nullable: true,
|
30
|
+
})
|
31
|
+
], JacksonStore.prototype, "iv", void 0);
|
32
|
+
__decorate([
|
33
|
+
(0, typeorm_1.Column)({
|
34
|
+
type: 'varchar',
|
35
|
+
length: 64,
|
36
|
+
nullable: true,
|
37
|
+
})
|
38
|
+
], JacksonStore.prototype, "tag", void 0);
|
39
|
+
JacksonStore = __decorate([
|
40
|
+
(0, typeorm_1.Entity)()
|
41
|
+
], JacksonStore);
|
42
|
+
exports.JacksonStore = JacksonStore;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.JacksonTTL = void 0;
|
10
|
+
const typeorm_1 = require("typeorm");
|
11
|
+
let JacksonTTL = class JacksonTTL {
|
12
|
+
};
|
13
|
+
__decorate([
|
14
|
+
(0, typeorm_1.Column)({
|
15
|
+
primary: true,
|
16
|
+
type: 'varchar',
|
17
|
+
length: 1500,
|
18
|
+
})
|
19
|
+
], JacksonTTL.prototype, "key", void 0);
|
20
|
+
__decorate([
|
21
|
+
(0, typeorm_1.Index)('_jackson_ttl_expires_at'),
|
22
|
+
(0, typeorm_1.Column)({
|
23
|
+
type: 'bigint',
|
24
|
+
})
|
25
|
+
], JacksonTTL.prototype, "expiresAt", void 0);
|
26
|
+
JacksonTTL = __decorate([
|
27
|
+
(0, typeorm_1.Entity)()
|
28
|
+
], JacksonTTL);
|
29
|
+
exports.JacksonTTL = JacksonTTL;
|