corebasic 1.0.160 → 1.0.162

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/libs/features.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as Dip from './dip.js'
2
2
  import * as Kafka from './kafka.js'
3
3
  import * as Utils from './utils.js'
4
+ import * as Session from './session.js'
4
5
  import * as Messaging from './messaging.js'
5
6
  import axios from 'axios'
6
7
  import jwt from 'jsonwebtoken'
@@ -101,16 +102,30 @@ async function announce() {
101
102
  })
102
103
  await Messaging.produce(`${process.env.REDIS_CHANNEL_PREFIX}_SLYP_FEATURES_LIST`, JSON.stringify({...exp_features, uid: appId }))
103
104
  }
105
+
106
+
107
+ function getFeaturelessFeature(req) {
108
+ if (Session.ALLOWED_URLS.includes(req.path)) {
109
+ for(let key in features){
110
+ if (features[key].featureless && features[key].api === req.method.toUpperCase() + ' ' + req.path) {
111
+ return getFeature(key)
112
+ }
113
+ }
114
+ }
115
+ }
116
+
104
117
  const apiHandler = async (req, res) => {
105
118
  let method = req.method.toLowerCase()
106
119
  try {
107
- if (!req.body.feature) {
120
+ let feature = getFeature(req.body?.feature)
121
+ let featureless = feature ? undefined : (feature = getFeaturelessFeature(req))
122
+
123
+ if (!req.body?.feature && !featureless) {
108
124
  console.warn(`Feature: feature not sent by client`)
109
125
  throw { status: 404, message: "Resource not found. Feature not sent by client." }
110
126
  }
111
127
 
112
- let feature = getFeature(req.body.feature)
113
- if (!feature) {
128
+ if (!feature && !featureless) {
114
129
  console.warn(`Feature: ${req.body.feature} not available`)
115
130
  throw { status: 404, message: `Resource not found. Feature ${req.body.feature} not available.` }
116
131
  }
package/libs/session.js CHANGED
@@ -12,9 +12,11 @@ const REFRESH_TOKEN_SECRET = process.env.JWT_REFRESH_TOKEN_SECRET || "MY_SECRET_
12
12
  const DEPLOY_TOKEN_SECRET = process.env.DEPLOY_TOKEN_SECRET || "MY_SECRET_DEPLOY_TOKEN"
13
13
 
14
14
  let urlsAllowed = []
15
+ export var ALLOWED_URLS = []
15
16
 
16
17
  export const start = (expressApp, allowedUrls) => {
17
18
  urlsAllowed = ["/refreshToken", "/login"].concat(allowedUrls ?? [])
19
+ ALLOWED_URLS = urlsAllowed
18
20
  app = expressApp
19
21
 
20
22
 
@@ -79,7 +81,7 @@ export const generateAccessToken = (userId, clientId) => {
79
81
  let refreshTokenExpiry = new Date(now); refreshTokenExpiry.setDate(refreshTokenExpiry.getDate() + 30); refreshTokenExpiry = refreshTokenExpiry.getTime()
80
82
 
81
83
  const accessToken = jwt.sign(data, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
82
- const refreshToken = jwt.sign(data, REFRESH_TOKEN_SECRET, { expiresIn: '30d' });
84
+ const refreshToken = jwt.sign(data, REFRESH_TOKEN_SECRET, { expiresIn: '180d' });
83
85
  return { accessToken, refreshToken, accessTokenExpiry, refreshTokenExpiry };
84
86
  }
85
87
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.160",
4
+ "version": "1.0.162",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {