@boxyhq/saml-jackson 0.1.5-beta.138 → 0.1.5-beta.142

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 CHANGED
@@ -166,12 +166,12 @@ curl --location --request POST 'http://localhost:6000/api/v1/saml/config' \
166
166
 
167
167
  The response returns a JSON with `client_id` and `client_secret` that can be stored against your tenant and product for a more secure OAuth 2.0 flow. If you do not want to store the `client_id` and `client_secret` you can alternatively use `client_id=tenant=<tenantID>&product=<productID>` and any arbitrary value for `client_secret` when setting up the OAuth 2.0 flow. Additionally a `provider` attribute is also returned which indicates the domain of your Identity Provider.
168
168
 
169
- #### 2.1 SAML GET config API
169
+ #### 2.1 SAML get config API
170
170
 
171
- This endpoint can be used to return metadata about an existing SAML config. This can be used to check and display the details to your customers. You can use either `clientID` and `clientSecret` combination or `tenant` and `product` combination.
171
+ This endpoint can be used to return metadata about an existing SAML config. This can be used to check and display the details to your customers. You can use either `clientID` or `tenant` and `product` combination.
172
172
 
173
173
  ```
174
- curl --location --request GET 'http://localhost:6000/api/v1/saml/config' \
174
+ curl --location --request POST 'http://localhost:6000/api/v1/saml/config/get' \
175
175
  --header 'Authorization: Api-Key <Jackson API Key>' \
176
176
  --header 'Content-Type: application/x-www-form-urlencoded' \
177
177
  --data-urlencode 'tenant=boxyhq.com' \
@@ -179,11 +179,10 @@ curl --location --request GET 'http://localhost:6000/api/v1/saml/config' \
179
179
  ```
180
180
 
181
181
  ```
182
- curl --location --request GET 'http://localhost:6000/api/v1/saml/config' \
182
+ curl --location --request POST 'http://localhost:6000/api/v1/saml/config/get' \
183
183
  --header 'Authorization: Api-Key <Jackson API Key>' \
184
184
  --header 'Content-Type: application/x-www-form-urlencoded' \
185
- --data-urlencode 'clientID=<Client ID>' \
186
- --data-urlencode 'clientSecret=<Client Secret>'
185
+ --data-urlencode 'clientID=<Client ID>'
187
186
  ```
188
187
 
189
188
  The response returns a JSON with `provider` indicating the domain of your Identity Provider. If an empty JSON payload is returned then we do not have any configuration stored for the attributes you requested.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boxyhq/saml-jackson",
3
- "version": "0.1.5-beta.138",
3
+ "version": "0.1.5-beta.142",
4
4
  "license": "Apache 2.0",
5
5
  "description": "SAML 2.0 service",
6
6
  "main": "src/index.js",
@@ -19,9 +19,11 @@
19
19
  "dev": "cross-env IDP_ENABLED=true nodemon src/jackson.js",
20
20
  "mongo": "cross-env DB_ENGINE=mongo DB_URL=mongodb://localhost:27017/jackson nodemon src/jackson.js",
21
21
  "pre-loaded": "cross-env DB_ENGINE=mem PRE_LOADED_CONFIG='./_config' nodemon src/jackson.js",
22
+ "pre-loaded-db": "cross-env PRE_LOADED_CONFIG='./_config' nodemon src/jackson.js",
22
23
  "test": "tap --timeout=100 src/**/*.test.js",
23
24
  "dev-dbs": "docker-compose -f ./_dev/docker-compose.yml up -d",
24
- "dev-dbs-destroy": "docker-compose -f ./_dev/docker-compose.yml down --volumes --remove-orphans"
25
+ "dev-dbs-destroy": "docker-compose -f ./_dev/docker-compose.yml down --volumes --remove-orphans",
26
+ "prepare": "husky install"
25
27
  },
26
28
  "tap": {
27
29
  "coverage-map": "map.js",
@@ -36,7 +38,7 @@
36
38
  "@peculiar/x509": "1.6.0",
37
39
  "cors": "2.8.5",
38
40
  "express": "4.17.1",
39
- "mongodb": "4.2.0",
41
+ "mongodb": "4.2.1",
40
42
  "mysql2": "2.3.3",
41
43
  "pg": "8.7.1",
42
44
  "rambda": "6.9.0",
@@ -51,8 +53,15 @@
51
53
  },
52
54
  "devDependencies": {
53
55
  "cross-env": "7.0.3",
54
- "eslint": "8.3.0",
56
+ "eslint": "8.4.0",
57
+ "husky": "7.0.4",
58
+ "lint-staged": "12.1.2",
55
59
  "nodemon": "2.0.15",
56
- "tap": "15.1.2"
60
+ "prettier": "2.5.1",
61
+ "tap": "15.1.5"
62
+ },
63
+ "lint-staged": {
64
+ "*.js": "eslint --cache --fix",
65
+ "*.{js,css,md}": "prettier --write"
57
66
  }
58
67
  }
@@ -83,9 +83,9 @@ const config = async (body) => {
83
83
  };
84
84
 
85
85
  const getConfig = async (body) => {
86
- const { clientID, clientSecret, tenant, product } = body;
86
+ const { clientID, tenant, product } = body;
87
87
 
88
- if (clientID && clientSecret) {
88
+ if (clientID) {
89
89
  const samlConfig = await configStore.get(clientID);
90
90
  if (!samlConfig) {
91
91
  return {};
package/src/db/db.test.js CHANGED
@@ -224,7 +224,7 @@ t.test('dbs', ({ end }) => {
224
224
  }
225
225
 
226
226
  await new Promise((resolve) =>
227
- setTimeout(resolve, ((dbEngine === 'mem' ? 5 : 0) + ttl + 0.5) * 1000)
227
+ setTimeout(resolve, (2*ttl + 0.5) * 1000)
228
228
  );
229
229
 
230
230
  const ret1 = await ttlStore.get(record1.id);
@@ -27,10 +27,6 @@ module.exports = (type) => {
27
27
  value: {
28
28
  type: valueType(type),
29
29
  },
30
- expiresAt: {
31
- type: 'bigint',
32
- nullable: true,
33
- },
34
30
  },
35
31
  });
36
32
  };
@@ -0,0 +1,23 @@
1
+ const EntitySchema = require('typeorm').EntitySchema;
2
+ const JacksonTTL = require('../model/JacksonTTL.js');
3
+
4
+ module.exports = new EntitySchema({
5
+ name: 'JacksonTTL',
6
+ target: JacksonTTL,
7
+ columns: {
8
+ key: {
9
+ primary: true,
10
+ type: 'varchar',
11
+ length: 1500,
12
+ },
13
+ expiresAt: {
14
+ type: 'bigint',
15
+ },
16
+ },
17
+ indices: [
18
+ {
19
+ name: '_jackson_ttl_expires_at',
20
+ columns: ['expiresAt'],
21
+ },
22
+ ],
23
+ });
@@ -1,8 +1,7 @@
1
1
  /*export */ class JacksonStore {
2
- constructor(key, value, expiresAt) {
2
+ constructor(key, value) {
3
3
  this.key = key;
4
4
  this.value = value;
5
- this.expiresAt = expiresAt;
6
5
  }
7
6
  }
8
7
 
@@ -0,0 +1,8 @@
1
+ /*export */ class JacksonTTL {
2
+ constructor(key, expiresAt) {
3
+ this.key = key;
4
+ this.expiresAt = expiresAt;
5
+ }
6
+ }
7
+
8
+ module.exports = JacksonTTL;
package/src/db/sql/sql.js CHANGED
@@ -2,6 +2,7 @@ require('reflect-metadata');
2
2
  const typeorm = require('typeorm');
3
3
  const JacksonStore = require('./model/JacksonStore.js');
4
4
  const JacksonIndex = require('./model/JacksonIndex.js');
5
+ const JacksonTTL = require('./model/JacksonTTL.js');
5
6
 
6
7
  const dbutils = require('../utils.js');
7
8
 
@@ -20,6 +21,7 @@ class Sql {
20
21
  entities: [
21
22
  require('./entity/JacksonStore.js')(options.type),
22
23
  require('./entity/JacksonIndex.js'),
24
+ require('./entity/JacksonTTL.js'),
23
25
  ],
24
26
  });
25
27
 
@@ -33,22 +35,29 @@ class Sql {
33
35
 
34
36
  this.storeRepository = this.connection.getRepository(JacksonStore);
35
37
  this.indexRepository = this.connection.getRepository(JacksonIndex);
38
+ this.ttlRepository = this.connection.getRepository(JacksonTTL);
36
39
 
37
40
  if (options.ttl && options.limit) {
38
41
  this.ttlCleanup = async () => {
39
42
  const now = Date.now();
40
43
 
41
44
  while (true) {
42
- const ids = await this.storeRepository.find({
43
- expiresAt: typeorm.MoreThan(now),
44
- take: options.limit,
45
- });
45
+ const ids = await this.ttlRepository
46
+ .createQueryBuilder('jackson_ttl')
47
+ .limit(options.limit)
48
+ .where('jackson_ttl.expiresAt <= :expiresAt', { expiresAt: now })
49
+ .getMany();
46
50
 
47
51
  if (ids.length <= 0) {
48
52
  break;
49
53
  }
50
54
 
55
+ const delIds = ids.map((id) => {
56
+ return id.key;
57
+ });
58
+
51
59
  await this.storeRepository.remove(ids);
60
+ await this.ttlRepository.delete(delIds);
52
61
  }
53
62
 
54
63
  this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
@@ -99,13 +108,15 @@ class Sql {
99
108
 
100
109
  async put(namespace, key, val, ttl = 0, ...indexes) {
101
110
  await this.connection.transaction(async (transactionalEntityManager) => {
102
- const store = new JacksonStore(
103
- dbutils.key(namespace, key),
104
- JSON.stringify(val),
105
- ttl > 0 ? Date.now() + ttl * 1000 : null
106
- );
111
+ const dbKey = dbutils.key(namespace, key);
112
+ const store = new JacksonStore(dbKey, JSON.stringify(val));
107
113
  await transactionalEntityManager.save(store);
108
114
 
115
+ if (ttl) {
116
+ const ttlRec = new JacksonTTL(dbKey, Date.now() + ttl * 1000);
117
+ await transactionalEntityManager.save(ttlRec);
118
+ }
119
+
109
120
  // no ttl support for secondary indexes
110
121
  for (const idx of indexes || []) {
111
122
  const key = dbutils.keyForIndex(namespace, idx);
package/src/jackson.js CHANGED
@@ -87,7 +87,7 @@ internalApp.post(apiPath + '/config', async (req, res) => {
87
87
  }
88
88
  });
89
89
 
90
- internalApp.get(apiPath + '/config', async (req, res) => {
90
+ internalApp.post(apiPath + '/config/get', async (req, res) => {
91
91
  try {
92
92
  const apiKey = extractAuthToken(req);
93
93
  if (!validateApiKey(apiKey)) {