@boxyhq/saml-jackson 0.1.3-beta.82 → 0.1.3-beta.87

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boxyhq/saml-jackson",
3
- "version": "0.1.3-beta.82",
3
+ "version": "0.1.3-beta.87",
4
4
  "license": "Apache 2.0",
5
5
  "description": "SAML 2.0 service",
6
6
  "main": "src/index.js",
@@ -28,10 +28,16 @@ const extractBearerToken = (req) => {
28
28
  function getEncodedClientId(client_id) {
29
29
  try {
30
30
  const sp = new URLSearchParams(client_id);
31
- return {
32
- tenant: sp.get('tenant'),
33
- product: sp.get('product'),
34
- };
31
+ const tenant = sp.get('tenant');
32
+ const product = sp.get('product');
33
+ if (tenant && product) {
34
+ return {
35
+ tenant: sp.get('tenant'),
36
+ product: sp.get('product'),
37
+ };
38
+ }
39
+
40
+ return null;
35
41
  } catch (err) {
36
42
  return null;
37
43
  }
package/src/db/db.test.js CHANGED
@@ -20,7 +20,7 @@ const record2 = {
20
20
  const dbs = [
21
21
  {
22
22
  engine: 'mem',
23
- ttlCleanup: 1,
23
+ ttl: 1,
24
24
  },
25
25
  {
26
26
  engine: 'redis',
@@ -30,6 +30,8 @@ const dbs = [
30
30
  engine: 'sql',
31
31
  url: 'postgresql://postgres:postgres@localhost:5432/postgres',
32
32
  type: 'postgres',
33
+ ttl: 1,
34
+ limit: 1,
33
35
  },
34
36
  {
35
37
  engine: 'mongo',
@@ -39,11 +41,15 @@ const dbs = [
39
41
  engine: 'sql',
40
42
  url: 'mysql://root:mysql@localhost:3307/mysql',
41
43
  type: 'mysql',
44
+ ttl: 1,
45
+ limit: 1,
42
46
  },
43
47
  {
44
48
  engine: 'sql',
45
49
  url: 'mariadb://root@localhost:3306/mysql',
46
50
  type: 'mariadb',
51
+ ttl: 1,
52
+ limit: 1,
47
53
  },
48
54
  ];
49
55
 
@@ -212,7 +218,7 @@ t.test('dbs', ({ end }) => {
212
218
 
213
219
  t.test('ttl expiry: ' + dbEngine, async (t) => {
214
220
  // mongo runs ttl task every 60 seconds
215
- if (dbEngine.startsWith('sql') || dbEngine.startsWith('mongo')) {
221
+ if (dbEngine.startsWith('mongo')) {
216
222
  t.end();
217
223
  return;
218
224
  }
package/src/db/mem.js CHANGED
@@ -9,20 +9,25 @@ class Mem {
9
9
  this.cleanup = {}; // map of indexes for cleanup when store key is deleted
10
10
  this.ttlStore = {}; // map of key to ttl
11
11
 
12
- this.ttlCleanup = async () => {
13
- const now = Date.now();
14
- for (const k in this.ttlStore) {
15
- if (this.ttlStore[k].expiresAt < now) {
16
- await this.delete(this.ttlStore[k].namespace, this.ttlStore[k].key);
12
+ if (options.ttl) {
13
+ this.ttlCleanup = async () => {
14
+ const now = Date.now();
15
+ for (const k in this.ttlStore) {
16
+ if (this.ttlStore[k].expiresAt < now) {
17
+ await this.delete(
18
+ this.ttlStore[k].namespace,
19
+ this.ttlStore[k].key
20
+ );
21
+ }
17
22
  }
18
- }
19
23
 
20
- this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
21
- };
24
+ this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
25
+ };
22
26
 
23
- this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
27
+ this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
28
+ }
24
29
 
25
- return this; // Return the newly-created instance
30
+ return this;
26
31
  })();
27
32
  }
28
33
 
package/src/db/sql/sql.js CHANGED
@@ -23,7 +23,32 @@ class Sql {
23
23
  this.storeRepository = this.connection.getRepository(JacksonStore);
24
24
  this.indexRepository = this.connection.getRepository(JacksonIndex);
25
25
 
26
- return this; // Return the newly-created instance
26
+ if (options.ttl && options.limit) {
27
+ this.ttlCleanup = async () => {
28
+ const now = Date.now();
29
+
30
+ while (true) {
31
+ const ids = await this.storeRepository.find({
32
+ expiresAt: typeorm.MoreThan(now),
33
+ take: options.limit,
34
+ });
35
+
36
+ if (ids.length <= 0) {
37
+ break;
38
+ }
39
+
40
+ await this.storeRepository.remove(ids);
41
+ }
42
+
43
+ this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
44
+ };
45
+
46
+ this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
47
+ } else {
48
+ console.log('Warning: ttl cleanup not enabled, set both "ttl" and "limit" options to enable it!')
49
+ }
50
+
51
+ return this;
27
52
  })();
28
53
  }
29
54
 
package/src/index.js CHANGED
@@ -22,6 +22,7 @@ const defaultOpts = (opts) => {
22
22
  newOpts.db.url || 'postgres://postgres:postgres@localhost:5432/jackson';
23
23
  newOpts.db.type = newOpts.db.type || 'postgres'; // Only needed if DB_ENGINE is sql. Supported values: postgres, cockroachdb, mysql, mariadb
24
24
  newOpts.db.ttl = (newOpts.db.ttl || 300) * 1; // TTL for the code, session and token stores (in seconds)
25
+ newOpts.db.limit = (newOpts.db.limit || 1000) * 1; // Limit ttl cleanup to this many items at a time
25
26
 
26
27
  return newOpts;
27
28
  };