corebasic 1.0.217 → 1.0.219

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/libs/auth.js CHANGED
@@ -1,4 +1,6 @@
1
+ // @ts-ignore
1
2
  import axios from 'axios';
3
+ // @ts-ignore
2
4
  import otpGenerator from 'otp-generator';
3
5
  import * as Dip from './dip.js';
4
6
  import * as Utils from './utils.js';
@@ -35,7 +37,8 @@ async function attemptLogin(req, res) {
35
37
  let meta = { company: "GLOBAL", outlet: "GLOBAL" };
36
38
  let expiry = 300000;
37
39
  let userMob = req.body.mob ?? req.body.phone;
38
- let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob);
40
+ const code = req.body.code;
41
+ let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob, code);
39
42
  let time = new Date().getTime();
40
43
  let collection = (req.body.app ? req.body.app + '.' : '') + "auth.login";
41
44
  let errMessage = { success: false, message: "Login Server Error" };
@@ -52,7 +55,7 @@ async function attemptLogin(req, res) {
52
55
  catch (err) {
53
56
  throw { ...errMessage, mode: 'verify', info: 'Cleanup Failed' };
54
57
  }
55
- return { ...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id };
58
+ return { ...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id, code };
56
59
  }
57
60
  throw { ...errMessage, mode: 'verify', info: "Invalid/Expired OTP" };
58
61
  }
@@ -64,7 +67,7 @@ async function attemptLogin(req, res) {
64
67
  let data = req.body.data ?? {};
65
68
  let info = { clientId, created: now, updated: now, ...data };
66
69
  await Dip.update(meta, collection, { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true });
67
- return { mode: 'login', success: true, userId, expiry, phone: mob, mob };
70
+ return { mode: 'login', success: true, userId, expiry, phone: mob, mob, code };
68
71
  }
69
72
  throw { ...errMessage, mode: 'login', info: 'Generating Info Failed' };
70
73
  }
@@ -1,4 +1,5 @@
1
1
  import * as Utils from './utils.js';
2
+ // @ts-ignore
2
3
  import compression from 'compression';
3
4
  // Compression Notes
4
5
  // -----------------
@@ -1,5 +1,6 @@
1
1
  import { entries, reduceRanges, extractBounds, getNormalizedBounds } from './index.js';
2
2
  import { formatDate, fillDates } from './date.js';
3
+ import * as Dip from '../../elabase.js';
3
4
  const EXPLICIT_SUFFIX_POLICY_TYPES = new Set(["string", "date", "number"]);
4
5
  export async function suffix(doc, policies, insertMode, arg) {
5
6
  let suffixes = [""];
@@ -26,17 +27,17 @@ export async function suffix(doc, policies, insertMode, arg) {
26
27
  if (policy_type === "date") {
27
28
  keys = keys.map(key => formatDate(key, format));
28
29
  if (ranges.length) {
29
- ranges = extractBounds(reduceRanges(ranges));
30
- const from = ranges.from ?? policy.min; // policy.min is always inclusive i.e $gte
31
- const to = ranges.to ?? policy.max; // policy.max is always inclusive i.e $lte
32
- const fromOp = ranges.from ? ranges.fromOp : "$gte"; // policy.min is $gte
33
- const toOp = ranges.to ? ranges.toOp : "$lte"; // policy.max is $lte
30
+ const bounds = extractBounds(reduceRanges(ranges));
31
+ const from = bounds.from ?? policy.min; // policy.min is always inclusive i.e $gte
32
+ const to = bounds.to ?? policy.max; // policy.max is always inclusive i.e $lte
33
+ const fromOp = bounds.from ? bounds.fromOp : "$gte"; // policy.min is $gte
34
+ const toOp = bounds.to ? bounds.toOp : "$lte"; // policy.max is $lte
34
35
  if (from === undefined || to === undefined) {
35
36
  keys = []; // Fall back to Dip.operation("ls").
36
37
  console.warn(`Warn: Missing suffix policy min/max bound for ${policy_type} range specified for key ${policy.key} in Dip`);
37
38
  }
38
39
  else {
39
- ranges = fillDates({ from, to, fromOp, toOp }, format);
40
+ let ranges = fillDates({ from, to, fromOp, toOp }, format);
40
41
  if (!ranges.length && policy.inferRange)
41
42
  ranges = [...new Set([from === undefined ? undefined : formatDate(from, format), to === undefined ? undefined : formatDate(to, format)].filter(item => item))];
42
43
  // console.log(ranges)
@@ -51,9 +52,9 @@ export async function suffix(doc, policies, insertMode, arg) {
51
52
  keys = [...new Set(keys)];
52
53
  }
53
54
  else if (policy_type === "number" && ranges.length) {
54
- ranges = getNormalizedBounds(extractBounds(reduceRanges(ranges)), "number");
55
- const from = ranges.from ?? policy.min; // policy.min is always inclusive i.e $gte
56
- const to = ranges.to ?? policy.max; // policy.max is always inclusive i.e $lte
55
+ const bounds = getNormalizedBounds(extractBounds(reduceRanges(ranges)), "number");
56
+ const from = bounds.from ?? policy.min; // policy.min is always inclusive i.e $gte
57
+ const to = bounds.to ?? policy.max; // policy.max is always inclusive i.e $lte
57
58
  if (from === undefined || to === undefined) {
58
59
  keys = []; // Fall back to Dip.operation("ls").
59
60
  console.warn(`Warn: Missing suffix policy min/max bound for ${policy_type} range specified for key ${policy.key} in Dip`);
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import axios from 'axios';
2
3
  // import {curly} from 'node-libcurl'
3
4
  function hashStr(str) {
@@ -68,6 +69,6 @@ export default async function dipper(arg) {
68
69
  export const shard_stats = () => {
69
70
  let total = Object.values(shard_hits).reduce((partial, value) => partial + value, 0);
70
71
  let result = {};
71
- Object.entries(shard_hits).forEach(([key, value]) => result[key] = parseFloat(value * 100 / total).toFixed(2));
72
+ Object.entries(shard_hits).forEach(([key, value]) => result[key] = (value * 100 / total).toFixed(2));
72
73
  return result;
73
74
  };
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import axios from 'axios';
2
3
  import { default as dipper, shard_stats as ShardStats } from './dipper.js';
3
4
  import * as Utils from './utils.js';
@@ -5,7 +6,7 @@ import * as Cpp from './cpp.js';
5
6
  import { applySuffixPolicy } from './dip/suffix/policy.js';
6
7
  export const shard_stats = ShardStats;
7
8
  let Events = {
8
- send: function () { }
9
+ send: function (topic, data) { }
9
10
  };
10
11
  const url = process.env.DIP_URL || "http://127.0.0.1"; // Set DIP_URL to "http://dip" (Prod) or http://dip-dev (Dev) in CI/CD
11
12
  let port = process.env.DIP_PORT || 9401;
@@ -49,7 +50,7 @@ class DipMeta {
49
50
  }
50
51
  }
51
52
  export const isDipMeta = meta => meta instanceof DipMeta;
52
- export const globalMeta = args => {
53
+ export const globalMeta = (args) => {
53
54
  return new DipMeta({ ...args, company: "GLOBAL", outlet: "GLOBAL" });
54
55
  };
55
56
  export const companyMeta = (company, args) => {
@@ -11,7 +11,9 @@ import * as Kafka from './kafka.js';
11
11
  import * as Utils from './utils.js';
12
12
  import * as Session from './session.js';
13
13
  import * as Messaging from './messaging.js';
14
+ // @ts-ignore
14
15
  import axios from 'axios';
16
+ // @ts-ignore
15
17
  import jwt from 'jsonwebtoken';
16
18
  let features = {};
17
19
  let apis = {};
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import { Kafka, logLevel as KafkaLogLevel, CompressionTypes as KafkaCompressionTypes } from 'kafkajs';
2
3
  export const logLevel = KafkaLogLevel;
3
4
  export const CompressionTypes = KafkaCompressionTypes;
@@ -1,6 +1,8 @@
1
+ import * as Utils from './utils.js';
2
+ // @ts-ignore
1
3
  import axios from 'axios';
4
+ // @ts-ignore
2
5
  import { createClient } from 'redis';
3
- import * as Utils from './utils.js';
4
6
  const url = process.env.REDIS_URL || "redis://localhost:6380";
5
7
  // url: 'redis://alice:foobared@localhost:6380'
6
8
  let consumer, publisher;
@@ -1,6 +1,7 @@
1
- import jwt from 'jsonwebtoken';
2
1
  import * as Utils from './utils.js';
3
2
  import * as Features from './features.js';
3
+ // @ts-ignore
4
+ import jwt from 'jsonwebtoken';
4
5
  let app;
5
6
  const ACCESS_TOKEN_SECRET = process.env.JWT_ACCESS_TOKEN_SECRET || "MY_SECRET_ACCESS_TOKEN";
6
7
  const REFRESH_TOKEN_SECRET = process.env.JWT_REFRESH_TOKEN_SECRET || "MY_SECRET_REFRESH_TOKEN";
@@ -27,13 +28,13 @@ export const start = (expressApp, allowedUrls) => {
27
28
  try {
28
29
  const token = req.header('JWT'); // 'Authorization' for Spring Boot, 'x-access-token' for Node.js Express back-end
29
30
  const service = req.header('SERVICE'); // Case insensitive search
30
- const additionalValidation = async (_) => (process.env.GRANT_FULL_ACCESS || allowedDefaults || await checkPrivilege(req));
31
+ const additionalValidation = async () => (process.env.GRANT_FULL_ACCESS || allowedDefaults || await checkPrivilege(req));
31
32
  async function verifyDeveloperAccess() {
32
33
  const NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN = req.header('NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN');
33
34
  const isDeveloper = NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN && NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET;
34
35
  if (!isDeveloper)
35
36
  return false;
36
- const verify = _ => jwt.verify(NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET, { algorithms: ['RS512'] });
37
+ const verify = () => jwt.verify(NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET, { algorithms: ['RS512'] });
37
38
  try {
38
39
  if (service && verify())
39
40
  return true;
@@ -62,12 +63,12 @@ export const start = (expressApp, allowedUrls) => {
62
63
  const decoded = jwt.verify(refreshToken, REFRESH_TOKEN_SECRET);
63
64
  if (decoded.userId === userId && decoded.clientId === clientId) {
64
65
  let now = Utils.now();
65
- let accessTokenExpiry = new Date(now);
66
- accessTokenExpiry.setDate(accessTokenExpiry.getDate() + 1);
67
- accessTokenExpiry = accessTokenExpiry.getTime();
68
- let refreshTokenExpiry = new Date(now);
69
- refreshTokenExpiry.setDate(refreshTokenExpiry.getDate() + 30);
70
- refreshTokenExpiry = refreshTokenExpiry.getTime();
66
+ let _accessTokenExpiry = new Date(now);
67
+ _accessTokenExpiry.setDate(_accessTokenExpiry.getDate() + 1);
68
+ let _refreshTokenExpiry = new Date(now);
69
+ _refreshTokenExpiry.setDate(_refreshTokenExpiry.getDate() + 30);
70
+ const accessTokenExpiry = _accessTokenExpiry.getTime();
71
+ const refreshTokenExpiry = _refreshTokenExpiry.getTime();
71
72
  const accessToken = jwt.sign({ userId, clientId }, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
72
73
  const refreshToken = jwt.sign({ userId, clientId }, REFRESH_TOKEN_SECRET, { expiresIn: '30d' });
73
74
  return res.json({ tokens: { accessToken, refreshToken, accessTokenExpiry, refreshTokenExpiry } });
@@ -84,12 +85,12 @@ export const start = (expressApp, allowedUrls) => {
84
85
  export const generateAccessToken = (userId, clientId) => {
85
86
  let data = { userId, clientId };
86
87
  let now = Utils.now();
87
- let accessTokenExpiry = new Date(now);
88
- accessTokenExpiry.setDate(accessTokenExpiry.getDate() + 1);
89
- accessTokenExpiry = accessTokenExpiry.getTime();
90
- let refreshTokenExpiry = new Date(now);
91
- refreshTokenExpiry.setDate(refreshTokenExpiry.getDate() + 30);
92
- refreshTokenExpiry = refreshTokenExpiry.getTime();
88
+ let _accessTokenExpiry = new Date(now);
89
+ _accessTokenExpiry.setDate(_accessTokenExpiry.getDate() + 1);
90
+ let _refreshTokenExpiry = new Date(now);
91
+ _refreshTokenExpiry.setDate(_refreshTokenExpiry.getDate() + 30);
92
+ const accessTokenExpiry = _accessTokenExpiry.getTime();
93
+ const refreshTokenExpiry = _refreshTokenExpiry.getTime();
93
94
  const accessToken = jwt.sign(data, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
94
95
  const refreshToken = jwt.sign(data, REFRESH_TOKEN_SECRET, { expiresIn: '365d' });
95
96
  return { accessToken, refreshToken, accessTokenExpiry, refreshTokenExpiry };
package/libs/auth.ts CHANGED
@@ -1,4 +1,6 @@
1
+ // @ts-ignore
1
2
  import axios from 'axios'
3
+ // @ts-ignore
2
4
  import otpGenerator from 'otp-generator'
3
5
 
4
6
  import * as Dip from './dip.ts'
@@ -38,7 +40,8 @@ async function attemptLogin(req, res) {
38
40
 
39
41
  let expiry = 300000
40
42
  let userMob = req.body.mob ?? req.body.phone
41
- let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob)
43
+ const code = req.body.code
44
+ let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob, code)
42
45
  let time = new Date().getTime()
43
46
  let collection = (req.body.app ? req.body.app + '.' : '') + "auth.login"
44
47
  let errMessage = {success: false, message: "Login Server Error"}
@@ -51,7 +54,7 @@ async function attemptLogin(req, res) {
51
54
  let res = await Dip.query(meta, collection, { _id: mob, otp: req.body.otp, clientId, time: { $gt: time - expiry } })
52
55
  if (res.length) {
53
56
  try {await Dip.update(meta, collection, { _id: mob }, { $set: { otp: '', clientId: '', loggedIn: true } }) } catch (err) { throw {...errMessage, mode: 'verify', info: 'Cleanup Failed'} }
54
- return {...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id}
57
+ return {...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id, code}
55
58
  }
56
59
  throw {...errMessage, mode: 'verify', info: "Invalid/Expired OTP"}
57
60
  } else { // generate login
@@ -63,7 +66,7 @@ async function attemptLogin(req, res) {
63
66
  let info = { clientId, created: now, updated: now, ...data}
64
67
  await Dip.update(meta, collection, { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true })
65
68
 
66
- return {mode: 'login', success: true, userId, expiry, phone: mob, mob}
69
+ return {mode: 'login', success: true, userId, expiry, phone: mob, mob, code}
67
70
  }
68
71
  throw {...errMessage, mode: 'login', info: 'Generating Info Failed'}
69
72
  }
@@ -1,4 +1,5 @@
1
1
  import * as Utils from './utils.ts'
2
+ // @ts-ignore
2
3
  import compression from 'compression'
3
4
 
4
5
  // Compression Notes
@@ -1,4 +1,4 @@
1
- import {getNormalizedBounds} from './index.ts'
1
+ import {getNormalizedBounds, type Bounds} from './index.ts'
2
2
  import {addUTCYears, addUTCMonths, addUTCDays} from '../../utils.ts'
3
3
 
4
4
 
@@ -94,7 +94,7 @@ export function fillDates(bounds_t, format) {
94
94
  else
95
95
  step = "year";
96
96
 
97
- let bounds = { ...bounds_t, from: new Date(bounds_t.from), to: new Date(bounds_t.to) }
97
+ let bounds: Bounds = { ...bounds_t, from: new Date(bounds_t.from), to: new Date(bounds_t.to) }
98
98
 
99
99
  bounds = getNormalizedBounds(bounds, "date")
100
100
 
@@ -103,13 +103,13 @@ export function fillDates(bounds_t, format) {
103
103
 
104
104
  switch (step) {
105
105
  case "day":
106
- addUTCDays(bounds.from, 1)
106
+ addUTCDays(bounds.from as Date, 1)
107
107
  break;
108
108
  case "month":
109
- addUTCMonths(bounds.from, 1)
109
+ addUTCMonths(bounds.from as Date, 1)
110
110
  break;
111
111
  case "year":
112
- addUTCYears(bounds.from, 1)
112
+ addUTCYears(bounds.from as Date, 1)
113
113
  break;
114
114
  }
115
115
  }
@@ -72,7 +72,7 @@ function flatten_value(target_key, value, flattened, ancestor_has_id) {
72
72
  }
73
73
 
74
74
 
75
- export function entries(target_key, query, binary_slice) {
75
+ export function entries(target_key: string, query, binary_slice?: Buffer) {
76
76
  let result = flatten_id_values(target_key, query); // extract all valid _id
77
77
 
78
78
  // let cows = result.map(v => extract_direct_id(v, binary_slice))
@@ -160,11 +160,19 @@ export function reduceRanges(values) {
160
160
  return other;
161
161
  }
162
162
 
163
+ export type Bounds = {
164
+ values: any[],
165
+ from: number | string | Date;
166
+ to: number | string | Date;
167
+ fromOp: "$gt" | "$gte";
168
+ toOp: "$lt" | "$lte";
169
+ }
170
+
163
171
  // reduceRanges() resolves conflicting bounds before extractBounds() runs.
164
172
  // extractBounds() receives at most one lower bound and atmost one upper bound. reduceRanges() ensures this
165
173
  // The for loop in extractBounds() may look slightly misleading because it looks like it is designed to resolve conflicts: but reduceRanges() has already done the conflict resolution.
166
174
  // NOTE CRITICAL: extractBounds() MUST ONLY BE RUN ON THE OUTPUT OF reduceRanges()
167
- export function extractBounds(values) {
175
+ export function extractBounds(values): Bounds {
168
176
  let lower = null;
169
177
  let upper = null;
170
178
  let lowerOp = null
@@ -204,20 +212,20 @@ export function extractBounds(values) {
204
212
  }
205
213
 
206
214
  // Converts exclusive bounds ($gt/$lt) into inclusive bounds
207
- export function getNormalizedBounds(bounds_t, type) {
215
+ export function getNormalizedBounds(bounds_t: Bounds, type): Bounds {
208
216
  let bounds = {...bounds_t}
209
217
 
210
218
  if (type === "number") {
211
219
  if (bounds.fromOp === "$gt")
212
- bounds.from++;
220
+ (bounds.from as number)++;
213
221
  if (bounds.toOp === "$lt")
214
- bounds.to--;
222
+ (bounds.to as number)--;
215
223
  } else if (type === "date") {
216
224
  if (bounds.fromOp === "$gt")
217
- bounds.from = new Date(bounds.from.getTime() + 1);
225
+ bounds.from = new Date((bounds.from as Date).getTime() + 1);
218
226
 
219
227
  if (bounds.toOp === "$lt")
220
- bounds.to = new Date(bounds.to.getTime() - 1);
228
+ bounds.to = new Date((bounds.to as Date).getTime() - 1);
221
229
  }
222
230
 
223
231
  return bounds
@@ -88,7 +88,7 @@ export function intersects(w_values, w_bounds, q_values, q_bounds) {
88
88
 
89
89
 
90
90
  // NOTE: Matching is based on intersection, not equality. A policy matches if, for every key in `when`, there exists at least one value that satisfies both the `when` constraint and the query constraint.
91
- export function matchPolicy(query, when, g_obj) {
91
+ export function matchPolicy(query, when, g_obj?: Record<string, any>) {
92
92
  let obj = g_obj ?? {}
93
93
  for (let key in when) {
94
94
  if (key === "$and" || key === "$or") {
@@ -135,8 +135,9 @@ export function matchPolicy(query, when, g_obj) {
135
135
 
136
136
 
137
137
 
138
+ type Arg = { db?: string; collection?: string; [key: string]: any }
138
139
 
139
- export async function applySuffixPolicy(COLLECTIONS_JSON, collections, query, insertMode, arg) {
140
+ export async function applySuffixPolicy(COLLECTIONS_JSON, collections, query, insertMode?: boolean, arg?: Arg) {
140
141
  collections = Array.isArray(collections) ? collections : [collections]
141
142
  let suffixes = []
142
143
 
@@ -1,10 +1,11 @@
1
- import {entries, reduceRanges, extractBounds, getNormalizedBounds} from './index.ts'
1
+ import {entries, reduceRanges, extractBounds, getNormalizedBounds, type Bounds} from './index.ts'
2
2
  import {formatDate, fillDates} from './date.ts'
3
+ import * as Dip from '../../elabase.ts'
3
4
 
4
-
5
+ type Arg = { db?: string; collection?: string; [key: string]: any }
5
6
 
6
7
  const EXPLICIT_SUFFIX_POLICY_TYPES = new Set([ "string", "date", "number" ]);
7
- export async function suffix(doc, policies, insertMode, arg) {
8
+ export async function suffix(doc, policies, insertMode?: boolean, arg?: Arg) {
8
9
  let suffixes = [""]
9
10
  for (const policy of policies) {
10
11
 
@@ -37,16 +38,16 @@ export async function suffix(doc, policies, insertMode, arg) {
37
38
  if (policy_type === "date") {
38
39
  keys = keys.map(key => formatDate(key, format))
39
40
  if (ranges.length) {
40
- ranges = extractBounds(reduceRanges(ranges))
41
- const from = ranges.from ?? policy.min // policy.min is always inclusive i.e $gte
42
- const to = ranges.to ?? policy.max // policy.max is always inclusive i.e $lte
43
- const fromOp = ranges.from ? ranges.fromOp : "$gte" // policy.min is $gte
44
- const toOp = ranges.to ? ranges.toOp : "$lte" // policy.max is $lte
41
+ const bounds = extractBounds(reduceRanges(ranges))
42
+ const from = bounds.from ?? policy.min // policy.min is always inclusive i.e $gte
43
+ const to = bounds.to ?? policy.max // policy.max is always inclusive i.e $lte
44
+ const fromOp = bounds.from ? bounds.fromOp : "$gte" // policy.min is $gte
45
+ const toOp = bounds.to ? bounds.toOp : "$lte" // policy.max is $lte
45
46
  if (from === undefined || to === undefined) {
46
47
  keys = [] // Fall back to Dip.operation("ls").
47
48
  console.warn(`Warn: Missing suffix policy min/max bound for ${policy_type} range specified for key ${policy.key} in Dip`)
48
49
  } else {
49
- ranges = fillDates({from, to, fromOp, toOp}, format)
50
+ let ranges = fillDates({from, to, fromOp, toOp}, format)
50
51
  if (!ranges.length && policy.inferRange)
51
52
  ranges = [...new Set([from === undefined ? undefined : formatDate(from, format), to === undefined ? undefined : formatDate(to, format)].filter(item => item))]
52
53
  // console.log(ranges)
@@ -59,9 +60,9 @@ export async function suffix(doc, policies, insertMode, arg) {
59
60
  }
60
61
  keys = [...new Set(keys)];
61
62
  } else if (policy_type === "number" && ranges.length) {
62
- ranges = getNormalizedBounds(extractBounds(reduceRanges(ranges)), "number")
63
- const from = ranges.from ?? policy.min // policy.min is always inclusive i.e $gte
64
- const to = ranges.to ?? policy.max // policy.max is always inclusive i.e $lte
63
+ const bounds = getNormalizedBounds(extractBounds(reduceRanges(ranges)), "number")
64
+ const from = bounds.from ?? policy.min // policy.min is always inclusive i.e $gte
65
+ const to = bounds.to ?? policy.max // policy.max is always inclusive i.e $lte
65
66
  if (from === undefined || to === undefined) {
66
67
  keys = [] // Fall back to Dip.operation("ls").
67
68
  console.warn(`Warn: Missing suffix policy min/max bound for ${policy_type} range specified for key ${policy.key} in Dip`)
package/libs/dip.ts CHANGED
@@ -37,7 +37,7 @@ export const IdempotentDip = () => {
37
37
  return {
38
38
  txn: '',
39
39
  meta: undefined,
40
- new: (async function (meta, txn, blank) {
40
+ new: (async function (meta, txn, blank?: {blank: boolean}) {
41
41
  this.txn = txn
42
42
  this.meta = meta
43
43
  return blank ? this : ((await Elabase.query(this.meta, "txns",{_id: this.txn})).length ? false : this)
package/libs/dipper.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import axios from 'axios'
2
3
  // import {curly} from 'node-libcurl'
3
4
 
@@ -84,8 +85,8 @@ export default async function dipper(arg) {
84
85
 
85
86
 
86
87
  export const shard_stats = () => {
87
- let total = Object.values(shard_hits).reduce( (partial, value) => partial + value, 0)
88
+ let total: number = (Object.values(shard_hits) as number[]).reduce( (partial: number, value: number) => partial + value, 0)
88
89
  let result = {}
89
- Object.entries(shard_hits).forEach( ([key,value]) => result[key] = parseFloat(value * 100 / total).toFixed(2) )
90
+ Object.entries(shard_hits).forEach( ([key, value]) => result[key] = ((value as number) * 100 / total).toFixed(2) )
90
91
  return result
91
92
  }
package/libs/elabase.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import axios from 'axios'
2
3
  import {default as dipper, shard_stats as ShardStats} from './dipper.ts'
3
4
  import * as Utils from './utils.ts'
@@ -12,7 +13,7 @@ export const shard_stats = ShardStats
12
13
 
13
14
 
14
15
  let Events = {
15
- send: function() { }
16
+ send: function(topic?: string, data?: any) { }
16
17
  }
17
18
 
18
19
 
@@ -62,6 +63,9 @@ function deepFreeze(obj) {
62
63
  return obj;
63
64
  }
64
65
  class DipMeta {
66
+ declare company?: string;
67
+ declare outlet?: string;
68
+
65
69
  constructor(obj) {
66
70
  Object.assign(this, deepFreeze(obj));
67
71
  Object.freeze(this);
@@ -69,10 +73,10 @@ class DipMeta {
69
73
  }
70
74
  export const isDipMeta = meta => meta instanceof DipMeta
71
75
 
72
- export const globalMeta = args => {
76
+ export const globalMeta = (args?: any) => {
73
77
  return new DipMeta({ ...args, company: "GLOBAL", outlet: "GLOBAL" })
74
78
  }
75
- export const companyMeta = (company, args) => {
79
+ export const companyMeta = (company, args?: any) => {
76
80
  if (typeof company !== "string" && !Array.isArray(company))
77
81
  throw new Error("Error: Invalid company provided in Dip.companyMeta()")
78
82
  if (!company || (typeof company === "string" && company.trim() === "") || company === "GLOBAL" || (Array.isArray(company) && (!company.length || company.some(item => typeof item !== "string" || item.trim() === "" || item === "GLOBAL")) ))
@@ -80,7 +84,7 @@ export const companyMeta = (company, args) => {
80
84
 
81
85
  return new DipMeta({...args, outlet: "GLOBAL", company})
82
86
  }
83
- export const outletMeta = (outlet, args) => {
87
+ export const outletMeta = (outlet, args?: any) => {
84
88
  if (typeof outlet !== "string" && !Array.isArray(outlet))
85
89
  throw new Error("Error: Invalid outlet provided in Dip.outletMeta()")
86
90
  if (!outlet || (typeof outlet === "string" && outlet.trim() === "") || outlet === "GLOBAL" || (Array.isArray(outlet) && (!outlet.length || outlet.some(item => typeof item !== "string" || item.trim() === "" || item === "GLOBAL")) ))
@@ -89,7 +93,7 @@ export const outletMeta = (outlet, args) => {
89
93
  return new DipMeta({...args, company: "GLOBAL", outlet})
90
94
  }
91
95
 
92
- export const customMeta = (company, outlet, args) => {
96
+ export const customMeta = (company, outlet, args?: any) => {
93
97
 
94
98
  if (typeof company !== "string" && !Array.isArray(company))
95
99
  throw new Error("Error: Invalid company provided in Dip.customMeta()")
@@ -308,7 +312,7 @@ export const operation = async (name, extras) => {
308
312
 
309
313
 
310
314
  // Ported
311
- export const insert = async (meta, collection, value, options, extras) => {
315
+ export const insert = async (meta, collection, value, options?: any, extras?: any) => {
312
316
 
313
317
  if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.insert()') // TODO: throw error once review completes
314
318
 
@@ -352,7 +356,7 @@ export const insert = async (meta, collection, value, options, extras) => {
352
356
  }
353
357
 
354
358
  // Ported
355
- export const query = async (meta, collection, query, options, extras) => {
359
+ export const query = async (meta, collection, query, options?: any, extras?: any) => {
356
360
 
357
361
  if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.query()') // TODO: throw error once review completes
358
362
 
@@ -404,7 +408,7 @@ function collectionArray(col) {
404
408
  }
405
409
 
406
410
  // Ported
407
- export const update = async (meta, collection, query, update, options, extras) => {
411
+ export const update = async (meta, collection, query, update, options?: any, extras?: any) => {
408
412
 
409
413
  if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.update()') // TODO: throw error once review completes
410
414
 
@@ -444,7 +448,7 @@ export const update = async (meta, collection, query, update, options, extras) =
444
448
  }
445
449
 
446
450
  // Ported
447
- export const remove = async (meta, collection, query, options, extras) => {
451
+ export const remove = async (meta, collection, query, options?: any, extras?: any) => {
448
452
 
449
453
  if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.remove()') // TODO: throw error once review completes
450
454
 
package/libs/features.ts CHANGED
@@ -3,7 +3,9 @@ import * as Kafka from './kafka.ts'
3
3
  import * as Utils from './utils.ts'
4
4
  import * as Session from './session.ts'
5
5
  import * as Messaging from './messaging.ts'
6
+ // @ts-ignore
6
7
  import axios from 'axios'
8
+ // @ts-ignore
7
9
  import jwt from 'jsonwebtoken'
8
10
 
9
11
  let features = {}
package/libs/kafka.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import { Kafka, logLevel as KafkaLogLevel, CompressionTypes as KafkaCompressionTypes } from 'kafkajs'
2
3
 
3
4
  export const logLevel = KafkaLogLevel
@@ -38,7 +39,7 @@ export const createTopic = async (topic, partition, replicas) => {
38
39
 
39
40
  let consumers = []
40
41
 
41
- const start_consumer = async function (topic, groupId, callback) {
42
+ const start_consumer = async function (topic, groupId, callback?: Function) {
42
43
  callback = typeof groupId === "string" ? callback : groupId
43
44
  groupId = typeof groupId === "string" ? `${appName}.${groupId}` : `${appName}.${topic}`
44
45
 
@@ -96,7 +97,7 @@ const start_producer = async function (topic, message, key, options) {
96
97
  // start_consumer('quickstart-events')
97
98
  // start_producer('quickstart-events', 'Hello KafkaJS user! Little')
98
99
 
99
- export const receive = async function(topic, groupId, callback) {
100
+ export const receive = async function(topic, groupId, callback?: Function) {
100
101
  topic = topicPrefix + topic
101
102
  return (await start_consumer(topic, groupId, callback))
102
103
  }
package/libs/messaging.ts CHANGED
@@ -1,7 +1,10 @@
1
1
 
2
+ import * as Utils from './utils.ts'
3
+
4
+ // @ts-ignore
2
5
  import axios from 'axios'
6
+ // @ts-ignore
3
7
  import { createClient } from 'redis';
4
- import * as Utils from './utils.ts'
5
8
 
6
9
  const url = process.env.REDIS_URL || "redis://localhost:6380"
7
10
 
package/libs/session.ts CHANGED
@@ -1,6 +1,8 @@
1
- import jwt from 'jsonwebtoken'
2
1
  import * as Utils from './utils.ts'
3
2
  import * as Features from './features.ts'
3
+ // @ts-ignore
4
+ import jwt from 'jsonwebtoken'
5
+
4
6
  let app
5
7
 
6
8
 
@@ -42,14 +44,14 @@ export const start = (expressApp, allowedUrls) => {
42
44
  try {
43
45
  const token = req.header('JWT'); // 'Authorization' for Spring Boot, 'x-access-token' for Node.js Express back-end
44
46
  const service = req.header('SERVICE'); // Case insensitive search
45
- const additionalValidation = async _ => (process.env.GRANT_FULL_ACCESS || allowedDefaults || await checkPrivilege(req))
47
+ const additionalValidation = async () => (process.env.GRANT_FULL_ACCESS || allowedDefaults || await checkPrivilege(req))
46
48
 
47
49
  async function verifyDeveloperAccess() {
48
50
  const NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN = req.header('NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN')
49
51
  const isDeveloper = NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN && NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET
50
52
  if (!isDeveloper)
51
53
  return false
52
- const verify = _ => jwt.verify(NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET, { algorithms: ['RS512'] })
54
+ const verify = () => jwt.verify(NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN_SECRET, { algorithms: ['RS512'] })
53
55
  try {
54
56
  if (service && verify())
55
57
  return true
@@ -79,8 +81,10 @@ export const start = (expressApp, allowedUrls) => {
79
81
  const decoded = jwt.verify(refreshToken, REFRESH_TOKEN_SECRET)
80
82
  if (decoded.userId === userId && decoded.clientId === clientId) {
81
83
  let now = Utils.now()
82
- let accessTokenExpiry = new Date(now); accessTokenExpiry.setDate(accessTokenExpiry.getDate() + 1); accessTokenExpiry = accessTokenExpiry.getTime()
83
- let refreshTokenExpiry = new Date(now); refreshTokenExpiry.setDate(refreshTokenExpiry.getDate() + 30); refreshTokenExpiry = refreshTokenExpiry.getTime()
84
+ let _accessTokenExpiry = new Date(now); _accessTokenExpiry.setDate(_accessTokenExpiry.getDate() + 1);
85
+ let _refreshTokenExpiry = new Date(now); _refreshTokenExpiry.setDate(_refreshTokenExpiry.getDate() + 30);
86
+ const accessTokenExpiry = _accessTokenExpiry.getTime()
87
+ const refreshTokenExpiry = _refreshTokenExpiry.getTime()
84
88
  const accessToken = jwt.sign({ userId, clientId }, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
85
89
  const refreshToken = jwt.sign({ userId, clientId }, REFRESH_TOKEN_SECRET, { expiresIn: '30d' });
86
90
  return res.json({ tokens: { accessToken, refreshToken, accessTokenExpiry, refreshTokenExpiry} });
@@ -100,8 +104,10 @@ export const generateAccessToken = (userId, clientId) => {
100
104
  let data = { userId, clientId }
101
105
 
102
106
  let now = Utils.now()
103
- let accessTokenExpiry = new Date(now); accessTokenExpiry.setDate(accessTokenExpiry.getDate() + 1); accessTokenExpiry = accessTokenExpiry.getTime()
104
- let refreshTokenExpiry = new Date(now); refreshTokenExpiry.setDate(refreshTokenExpiry.getDate() + 30); refreshTokenExpiry = refreshTokenExpiry.getTime()
107
+ let _accessTokenExpiry = new Date(now); _accessTokenExpiry.setDate(_accessTokenExpiry.getDate() + 1);
108
+ let _refreshTokenExpiry = new Date(now); _refreshTokenExpiry.setDate(_refreshTokenExpiry.getDate() + 30);
109
+ const accessTokenExpiry = _accessTokenExpiry.getTime()
110
+ const refreshTokenExpiry = _refreshTokenExpiry.getTime()
105
111
 
106
112
  const accessToken = jwt.sign(data, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
107
113
  const refreshToken = jwt.sign(data, REFRESH_TOKEN_SECRET, { expiresIn: '365d' });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.217",
4
+ "version": "1.0.219",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "./index.ts",