corebasic 1.0.212 → 1.0.213

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.
Files changed (141) hide show
  1. package/dist/index.js +10 -0
  2. package/dist/libs/ObjectId.js +114 -0
  3. package/dist/libs/auth.js +103 -0
  4. package/dist/libs/compression.js +11 -0
  5. package/dist/libs/cpp.js +154 -0
  6. package/dist/libs/dip/suffix/date.js +89 -0
  7. package/dist/libs/dip/suffix/index.js +227 -0
  8. package/dist/libs/dip/suffix/policy.js +113 -0
  9. package/dist/libs/dip/suffix/query.js +279 -0
  10. package/dist/libs/dip/suffix/suffix.js +99 -0
  11. package/dist/libs/dip/suffix/tests/date.test.js +187 -0
  12. package/dist/libs/dip/suffix/tests/index.test.js +441 -0
  13. package/dist/libs/dip/suffix/tests/policy.applySuffixPolicy.test.js +489 -0
  14. package/dist/libs/dip/suffix/tests/policy.test.js +329 -0
  15. package/dist/libs/dip/suffix/tests/suffix.test.js +316 -0
  16. package/dist/libs/dip.js +102 -0
  17. package/dist/libs/dipper.js +73 -0
  18. package/dist/libs/elabase.js +656 -0
  19. package/dist/libs/features.js +366 -0
  20. package/dist/libs/kafka.js +121 -0
  21. package/dist/libs/messaging.js +130 -0
  22. package/dist/libs/mobilecodes.js +562 -0
  23. package/dist/libs/session.js +96 -0
  24. package/dist/libs/utils.js +297 -0
  25. package/package.json +3 -2
  26. package/tsc/@typescript/typescript-linux-x64/LICENSE +55 -0
  27. package/tsc/@typescript/typescript-linux-x64/NOTICE.txt +436 -0
  28. package/tsc/@typescript/typescript-linux-x64/README.md +3 -0
  29. package/tsc/@typescript/typescript-linux-x64/lib/lib.d.ts +20 -0
  30. package/tsc/@typescript/typescript-linux-x64/lib/lib.decorators.d.ts +382 -0
  31. package/tsc/@typescript/typescript-linux-x64/lib/lib.decorators.legacy.d.ts +20 -0
  32. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.asynciterable.d.ts +18 -0
  33. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.d.ts +45125 -0
  34. package/tsc/@typescript/typescript-linux-x64/lib/lib.dom.iterable.d.ts +18 -0
  35. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.collection.d.ts +159 -0
  36. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.core.d.ts +595 -0
  37. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.d.ts +26 -0
  38. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.generator.d.ts +75 -0
  39. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.iterable.d.ts +603 -0
  40. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.promise.d.ts +79 -0
  41. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.proxy.d.ts +126 -0
  42. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.reflect.d.ts +142 -0
  43. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.symbol.d.ts +44 -0
  44. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2015.symbol.wellknown.d.ts +324 -0
  45. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.array.include.d.ts +114 -0
  46. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.d.ts +19 -0
  47. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.full.d.ts +21 -0
  48. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2016.intl.d.ts +29 -0
  49. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.arraybuffer.d.ts +19 -0
  50. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.d.ts +24 -0
  51. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.date.d.ts +29 -0
  52. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.full.d.ts +21 -0
  53. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.intl.d.ts +42 -0
  54. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.object.d.ts +47 -0
  55. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.sharedmemory.d.ts +133 -0
  56. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.string.d.ts +47 -0
  57. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2017.typedarrays.d.ts +51 -0
  58. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.asyncgenerator.d.ts +75 -0
  59. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.asynciterable.d.ts +51 -0
  60. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.d.ts +22 -0
  61. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.full.d.ts +22 -0
  62. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.intl.d.ts +81 -0
  63. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.promise.d.ts +28 -0
  64. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2018.regexp.d.ts +35 -0
  65. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.array.d.ts +77 -0
  66. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.d.ts +22 -0
  67. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.full.d.ts +22 -0
  68. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.intl.d.ts +21 -0
  69. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.object.d.ts +31 -0
  70. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.string.d.ts +35 -0
  71. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2019.symbol.d.ts +22 -0
  72. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.bigint.d.ts +763 -0
  73. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.d.ts +25 -0
  74. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.date.d.ts +40 -0
  75. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.full.d.ts +22 -0
  76. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.intl.d.ts +472 -0
  77. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.number.d.ts +26 -0
  78. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.promise.d.ts +45 -0
  79. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.sharedmemory.d.ts +97 -0
  80. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.string.d.ts +42 -0
  81. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2020.symbol.wellknown.d.ts +39 -0
  82. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.d.ts +21 -0
  83. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.full.d.ts +22 -0
  84. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.intl.d.ts +164 -0
  85. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.promise.d.ts +46 -0
  86. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.string.d.ts +31 -0
  87. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2021.weakref.d.ts +76 -0
  88. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.array.d.ts +119 -0
  89. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.d.ts +23 -0
  90. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.error.d.ts +73 -0
  91. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.full.d.ts +22 -0
  92. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.intl.d.ts +143 -0
  93. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.object.d.ts +24 -0
  94. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.regexp.d.ts +37 -0
  95. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2022.string.d.ts +23 -0
  96. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.array.d.ts +922 -0
  97. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.collection.d.ts +19 -0
  98. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.d.ts +20 -0
  99. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.full.d.ts +22 -0
  100. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2023.intl.d.ts +62 -0
  101. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.arraybuffer.d.ts +63 -0
  102. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.collection.d.ts +27 -0
  103. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.d.ts +24 -0
  104. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.full.d.ts +22 -0
  105. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.object.d.ts +27 -0
  106. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.promise.d.ts +33 -0
  107. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.regexp.d.ts +23 -0
  108. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.sharedmemory.d.ts +66 -0
  109. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2024.string.d.ts +27 -0
  110. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.collection.d.ts +94 -0
  111. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.d.ts +23 -0
  112. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.float16.d.ts +443 -0
  113. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.full.d.ts +22 -0
  114. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.intl.d.ts +200 -0
  115. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.iterator.d.ts +146 -0
  116. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.promise.d.ts +32 -0
  117. package/tsc/@typescript/typescript-linux-x64/lib/lib.es2025.regexp.d.ts +30 -0
  118. package/tsc/@typescript/typescript-linux-x64/lib/lib.es5.d.ts +4599 -0
  119. package/tsc/@typescript/typescript-linux-x64/lib/lib.es6.d.ts +21 -0
  120. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.array.d.ts +33 -0
  121. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.collection.d.ts +47 -0
  122. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.d.ts +27 -0
  123. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.date.d.ts +21 -0
  124. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.decorators.d.ts +26 -0
  125. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.disposable.d.ts +191 -0
  126. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.error.d.ts +22 -0
  127. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.full.d.ts +22 -0
  128. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.intl.d.ts +107 -0
  129. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.sharedmemory.d.ts +23 -0
  130. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.temporal.d.ts +485 -0
  131. package/tsc/@typescript/typescript-linux-x64/lib/lib.esnext.typedarrays.d.ts +90 -0
  132. package/tsc/@typescript/typescript-linux-x64/lib/lib.scripthost.d.ts +320 -0
  133. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.asynciterable.d.ts +18 -0
  134. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.d.ts +15606 -0
  135. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.importscripts.d.ts +21 -0
  136. package/tsc/@typescript/typescript-linux-x64/lib/lib.webworker.iterable.d.ts +18 -0
  137. package/tsc/@typescript/typescript-linux-x64/lib/tsc +0 -0
  138. package/tsc/@typescript/typescript-linux-x64/lib/tsc.sig +11 -0
  139. package/tsc/@typescript/typescript-linux-x64/package.json +45 -0
  140. package/tsc/notes +14 -0
  141. package/tsconfig.json +48 -0
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import * as Elabase from './libs/elabase.js';
2
+ import * as Dip from './libs/dip.js';
3
+ import * as Kafka from './libs/kafka.js';
4
+ import * as Utils from './libs/utils.js';
5
+ import * as Session from './libs/session.js';
6
+ import * as Auth from './libs/auth.js';
7
+ import * as Features from './libs/features.js';
8
+ import * as Messaging from './libs/messaging.js';
9
+ import * as Compression from './libs/compression.js';
10
+ export { Elabase, Dip, Kafka, Utils, Session, Auth, Features, Messaging, Compression };
@@ -0,0 +1,114 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2011-2014- Justin Dearing (zippy1981@gmail.com)
4
+ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
5
+ * and GPL (http://www.opensource.org/licenses/gpl-license.php) version 2 licenses.
6
+ * This software is not distributed under version 3 or later of the GPL.
7
+ *
8
+ * Version 1.0.2
9
+ *
10
+ */
11
+ if (!document)
12
+ var document = { cookie: '' }; // fix crashes on node
13
+ /**
14
+ * Javascript class that mimics how WCF serializes a object of type MongoDB.Bson.ObjectId
15
+ * and converts between that format and the standard 24 character representation.
16
+ */
17
+ export var ObjectId = (function () {
18
+ var increment = Math.floor(Math.random() * (16777216));
19
+ var pid = Math.floor(Math.random() * (65536));
20
+ var machine = Math.floor(Math.random() * (16777216));
21
+ var setMachineCookie = function () {
22
+ var cookieList = document.cookie.split('; ');
23
+ for (var i in cookieList) {
24
+ var cookie = cookieList[i].split('=');
25
+ var cookieMachineId = parseInt(cookie[1], 10);
26
+ if (cookie[0] == 'mongoMachineId' && cookieMachineId && cookieMachineId >= 0 && cookieMachineId <= 16777215) {
27
+ machine = cookieMachineId;
28
+ break;
29
+ }
30
+ }
31
+ document.cookie = 'mongoMachineId=' + machine + ';expires=Tue, 19 Jan 2038 05:00:00 GMT;path=/';
32
+ };
33
+ if (typeof (localStorage) != 'undefined') {
34
+ try {
35
+ var mongoMachineId = parseInt(localStorage['mongoMachineId']);
36
+ if (mongoMachineId >= 0 && mongoMachineId <= 16777215) {
37
+ machine = Math.floor(localStorage['mongoMachineId']);
38
+ }
39
+ // Just always stick the value in.
40
+ localStorage['mongoMachineId'] = machine;
41
+ }
42
+ catch (e) {
43
+ setMachineCookie();
44
+ }
45
+ }
46
+ else {
47
+ setMachineCookie();
48
+ }
49
+ function ObjId() {
50
+ if (!(this instanceof ObjectId)) {
51
+ return new ObjectId(arguments[0], arguments[1], arguments[2], arguments[3]).toString();
52
+ }
53
+ if (typeof (arguments[0]) == 'object') {
54
+ this.timestamp = arguments[0].timestamp;
55
+ this.machine = arguments[0].machine;
56
+ this.pid = arguments[0].pid;
57
+ this.increment = arguments[0].increment;
58
+ }
59
+ else if (typeof (arguments[0]) == 'string' && arguments[0].length == 24) {
60
+ this.timestamp = Number('0x' + arguments[0].substr(0, 8)),
61
+ this.machine = Number('0x' + arguments[0].substr(8, 6)),
62
+ this.pid = Number('0x' + arguments[0].substr(14, 4)),
63
+ this.increment = Number('0x' + arguments[0].substr(18, 6));
64
+ }
65
+ else if (arguments.length == 4 && arguments[0] != null) {
66
+ this.timestamp = arguments[0];
67
+ this.machine = arguments[1];
68
+ this.pid = arguments[2];
69
+ this.increment = arguments[3];
70
+ }
71
+ else {
72
+ this.timestamp = Math.floor(new Date().valueOf() / 1000);
73
+ this.machine = machine;
74
+ this.pid = pid;
75
+ this.increment = increment++;
76
+ if (increment > 0xffffff) {
77
+ increment = 0;
78
+ }
79
+ }
80
+ }
81
+ ;
82
+ return ObjId;
83
+ })();
84
+ ObjectId.prototype.getDate = function () {
85
+ return new Date(this.timestamp * 1000);
86
+ };
87
+ ObjectId.prototype.toArray = function () {
88
+ var strOid = this.toString();
89
+ var array = [];
90
+ var i;
91
+ for (i = 0; i < 12; i++) {
92
+ array[i] = parseInt(strOid.slice(i * 2, i * 2 + 2), 16);
93
+ }
94
+ return array;
95
+ };
96
+ /**
97
+ * Turns a WCF representation of a BSON ObjectId into a 24 character string representation.
98
+ */
99
+ ObjectId.prototype.toString = function () {
100
+ if (this.timestamp === undefined
101
+ || this.machine === undefined
102
+ || this.pid === undefined
103
+ || this.increment === undefined) {
104
+ return 'Invalid ObjectId';
105
+ }
106
+ var timestamp = this.timestamp.toString(16);
107
+ var machine = this.machine.toString(16);
108
+ var pid = this.pid.toString(16);
109
+ var increment = this.increment.toString(16);
110
+ return '00000000'.substr(0, 8 - timestamp.length) + timestamp +
111
+ '000000'.substr(0, 6 - machine.length) + machine +
112
+ '0000'.substr(0, 4 - pid.length) + pid +
113
+ '000000'.substr(0, 6 - increment.length) + increment;
114
+ };
@@ -0,0 +1,103 @@
1
+ import axios from 'axios';
2
+ import otpGenerator from 'otp-generator';
3
+ import * as Dip from './dip.js';
4
+ import * as Utils from './utils.js';
5
+ import * as Session from './session.js';
6
+ let validateFn, validateErrMessage;
7
+ export const validate = (callback, errMessage) => {
8
+ validateFn = callback;
9
+ };
10
+ export const start = (app, successCallback) => {
11
+ app.post("/login", async (req, res) => {
12
+ if (validateFn && !validateFn(req)) {
13
+ res.status(401).json({ mode: 'login', success: false, info: validateErrMessage ?? 'Validation Failed', message: 'Login Server Error' });
14
+ return;
15
+ }
16
+ try {
17
+ let login = await attemptLogin(req, res);
18
+ if (login.mode === 'verify' && login.success) {
19
+ let tokens = Session.generateAccessToken(login.userId, req.body.clientId);
20
+ let response = { ...login, tokens };
21
+ if (successCallback)
22
+ await successCallback(req, res, response);
23
+ else
24
+ res.json(response);
25
+ }
26
+ else
27
+ res.json(login);
28
+ }
29
+ catch (err) {
30
+ return res.status(401).json(err);
31
+ }
32
+ });
33
+ };
34
+ async function attemptLogin(req, res) {
35
+ let meta = { company: "GLOBAL", outlet: "GLOBAL" };
36
+ let expiry = 300000;
37
+ let userMob = req.body.mob ?? req.body.phone;
38
+ let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob);
39
+ let time = new Date().getTime();
40
+ let collection = (req.body.app ? req.body.app + '.' : '') + "auth.login";
41
+ let errMessage = { success: false, message: "Login Server Error" };
42
+ let otpValid = Utils.isEmpty(req.body.otp) ? false : true;
43
+ let clientId = req.body.clientId;
44
+ if (Utils.isEmpty(clientId))
45
+ throw { ...errMessage, mode: otpValid ? 'verify' : 'login', info: "Invalid Client ID" };
46
+ if (otpValid) { // verify login
47
+ let res = await Dip.query(meta, collection, { _id: mob, otp: req.body.otp, clientId, time: { $gt: time - expiry } });
48
+ if (res.length) {
49
+ try {
50
+ await Dip.update(meta, collection, { _id: mob }, { $set: { otp: '', clientId: '', loggedIn: true } });
51
+ }
52
+ catch (err) {
53
+ throw { ...errMessage, mode: 'verify', info: 'Cleanup Failed' };
54
+ }
55
+ return { ...res[0], mode: 'verify', success: true, userId: res[0].userId, phone: res[0]._id, mob: res[0]._id };
56
+ }
57
+ throw { ...errMessage, mode: 'verify', info: "Invalid/Expired OTP" };
58
+ }
59
+ else { // generate login
60
+ let otp = mob === '0123456789' ? '1234' : otpGenerator.generate(4, { upperCaseAlphabets: false, specialChars: false, digital: true, lowerCaseAlphabets: false });
61
+ if (mob === '0123456789' || await sendOtp(mob, otp, req.body.app, req.body.hash)) {
62
+ let userId = req.body.userId ?? Utils.uid();
63
+ let now = Utils.now().getTime();
64
+ let data = req.body.data ?? {};
65
+ let info = { clientId, created: now, updated: now, ...data };
66
+ 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 };
68
+ }
69
+ throw { ...errMessage, mode: 'login', info: 'Generating Info Failed' };
70
+ }
71
+ }
72
+ async function sendOtp(mob, otp, app, hash) {
73
+ if (process.env.LOGIN_OTP_DISABLE) {
74
+ console.log(otp);
75
+ return true;
76
+ }
77
+ try {
78
+ if (app && hash)
79
+ app = encodeURIComponent(`${app} (#${hash})`); // Of the form '<app> (#<hash>)' for better readability. Note: Axios works with SlypBusiness%20(%23<HASH>) but Curl requires SlypBusiness%20%28%23<HASH>%29
80
+ let api = process.env.SMS_API.replace(':phone', mob).replace(':otp', otp).replace(':app', app ?? 'app');
81
+ await axios.get(api);
82
+ return true;
83
+ }
84
+ catch {
85
+ return false;
86
+ }
87
+ }
88
+ // API
89
+ // ----
90
+ // Login => HttpRequest.post('/login').send({app: '', mob: '', userId: 'Optional', data: {//optional} }) // Response => { mode: 'login', success, userId, expiry }
91
+ // Verify => HttpRequest.post('/login').send({app: '', clientId: '', mob: '', otp: ''}) // Response => { mode: 'verify', success, userId }
92
+ // Usage
93
+ // Auth.validate((req) => ["Phone1", "Phone2"].includes(req.body.mob.trim()))
94
+ // Auth.start(app, async (req, res, data) => {
95
+ // try {
96
+ // let meta = {company: "GLOBAL", outlet: "GLOBAL"}
97
+ // await Dip.insert(meta, "users", { }, "asdsds")
98
+ // await Kafka.send("users", {event: "userLogin", ...data, time: Utils.now()})
99
+ // res.json(data)
100
+ // } catch {
101
+ // res.json({...data, success: false})
102
+ // }
103
+ // })
@@ -0,0 +1,11 @@
1
+ import * as Utils from './utils.js';
2
+ import compression from 'compression';
3
+ // Compression Notes
4
+ // -----------------
5
+ // Default compression gzip. Compressed server responses will have header set with `Content-Encoding: gzip` before sending to client
6
+ // Curl cpr library by default announces compression capability by specifying header `Accept-Encoding`. Meaning client is able to decompress compressed response. Then server can compress responses if needed
7
+ // Regarding Client compressing data send to server, I think if server has `Content-Encoding: gzip` set, then client might compress before sending. But not sure. Need to check.
8
+ // Http Stream or ServerSideEvents require res.flush() after res.write(). res.flush function is added by the express compression middleware
9
+ export const start = app => {
10
+ app.use(Utils.excludeMiddleware(compression({ threshold: 1024 }))); // Response above 1024 bytes should be compressed. Default is also 1KB
11
+ };
@@ -0,0 +1,154 @@
1
+ import crypto from 'node:crypto';
2
+ function readContent(buffer, valueRef, bytesRef) {
3
+ const MASK = 0x7F;
4
+ const MSB = 0x80;
5
+ const MAX_VLQ_BYTES = 10;
6
+ // Ensure we have a valid Uint8Array view
7
+ if (!buffer)
8
+ return false;
9
+ const view = ArrayBuffer.isView(buffer) ? buffer : new Uint8Array(buffer);
10
+ const bufferSize = view.length;
11
+ let length = 0n;
12
+ let shift = 0n;
13
+ let lenBytes = 0;
14
+ while (true) {
15
+ if (lenBytes >= MAX_VLQ_BYTES || lenBytes >= bufferSize) {
16
+ return false;
17
+ }
18
+ const byte = view[lenBytes];
19
+ lenBytes++;
20
+ length |= BigInt(byte & MASK) << shift;
21
+ shift += 7n;
22
+ if ((byte & MSB) === 0) {
23
+ break;
24
+ }
25
+ }
26
+ // Emulate C++ pointer assignment by modifying the wrapper objects
27
+ valueRef.value = length;
28
+ bytesRef.value = lenBytes;
29
+ return true;
30
+ }
31
+ export function vlqToUint64(arrayBuffer) {
32
+ // Objects act as containers to simulate C++ pointers/references
33
+ const valueRef = { value: 0n };
34
+ const bytesRef = { value: 0 };
35
+ const success = readContent(arrayBuffer, valueRef, bytesRef);
36
+ // If read_content returned false, handle or return empty/default values
37
+ if (!success) {
38
+ return { value: Number(0n), bytes: 0 };
39
+ }
40
+ // Returns a plain object, the equivalent of QVariantMap
41
+ return {
42
+ value: Number(valueRef.value), // BigInt to Number
43
+ bytes: bytesRef.value // Number
44
+ };
45
+ }
46
+ function writeVlqcontent(buffer, value) {
47
+ const MASK = 0x7fn;
48
+ const MSB = 0x80;
49
+ let bufferPtr = 0;
50
+ let tempValue = BigInt(value);
51
+ do {
52
+ let byte = Number(tempValue & MASK);
53
+ tempValue >>= 7n;
54
+ if (tempValue > 0n) {
55
+ byte |= MSB;
56
+ }
57
+ buffer[bufferPtr++] = byte;
58
+ } while (tempValue > 0n);
59
+ return bufferPtr;
60
+ }
61
+ export function uint64ToVlq(value) {
62
+ // 10 bytes is the maximum VLQ size for a uint64
63
+ const out = Buffer.allocUnsafe(10);
64
+ const size = writeVlqcontent(out, value);
65
+ // Returns a fresh, correctly sized buffer copy
66
+ return Buffer.from(out.subarray(0, size));
67
+ }
68
+ export function sliceArrayBuffer(buffer, offset, length) {
69
+ // Ensure we are working with a Node.js Buffer
70
+ const buf = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
71
+ const totalSize = buf.length;
72
+ // Boundary check matching your C++ logic
73
+ if (offset < 0 || offset >= totalSize) {
74
+ return Buffer.alloc(0); // Returns an empty Buffer (like QByteArray())
75
+ }
76
+ // FIX: If length is -1, automatically calculate the remaining size to the end
77
+ if (length <= 0 || offset + length > totalSize) {
78
+ length = totalSize - offset;
79
+ }
80
+ // subarray() creates a zero-copy/shallow view over the original memory.
81
+ // Note: second argument is end index instead of cpp length
82
+ return buf.subarray(offset, offset + length); // COW/Shallow copy I hope or else what is the use of this function
83
+ }
84
+ export function stringToUtf8ArrayBuffer(arg) {
85
+ // Converts the string into a Node.js Buffer encoded in UTF-8
86
+ return Buffer.from(arg, 'utf8');
87
+ }
88
+ export function numberToSortableBytes(value) {
89
+ // 1. Create an 8-byte buffer and a data view to read/write raw bits
90
+ const buffer = Buffer.alloc(8);
91
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
92
+ // 2. Write the double value into the buffer to extract its raw 64-bit bits
93
+ view.setFloat64(0, value, true); // Use little-endian for direct memory mapping
94
+ let bits = view.getBigUint64(0, true);
95
+ const SIGN_MASK = 0x8000000000000000n; // Use BigInt literal for 64-bit mask
96
+ // 3. Apply the sorting transformation logic
97
+ if ((bits & SIGN_MASK) !== 0n) {
98
+ // Negative: invert all bits
99
+ bits = ~bits;
100
+ }
101
+ else {
102
+ // Positive: flip the sign bit
103
+ bits ^= SIGN_MASK;
104
+ }
105
+ // 4. Write the transformed bits back as Big Endian (equivalent to qToBigEndian)
106
+ view.setBigUint64(0, bits, false); // false = Big Endian
107
+ return buffer;
108
+ }
109
+ export function defaultHash(buffer) {
110
+ const buf = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
111
+ // Uses the high-speed, non-cryptographic xxhash64 algorithm
112
+ // supported natively in both Node.js and Bun's crypto module layers.
113
+ const hashBytes = crypto.createHash('md5').update(buf).digest(); // Earlier used xxhash64 but not available in my openssl. so md5
114
+ // Reads the 8-byte hash output into a 64-bit BigInt (quint64)
115
+ return hashBytes.readBigUInt64BE(0);
116
+ }
117
+ export function memcmpEqual(buffer1, buffer2) {
118
+ const b1 = Buffer.isBuffer(buffer1) ? buffer1 : Buffer.from(buffer1);
119
+ const b2 = Buffer.isBuffer(buffer2) ? buffer2 : Buffer.from(buffer2);
120
+ return b1.equals(b2);
121
+ }
122
+ export function arrayBufferToString(buffer) {
123
+ const buf = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
124
+ // Decodes the buffer bytes as a UTF-8 JavaScript string
125
+ return buf.toString('utf8');
126
+ }
127
+ // Matches QString Response::getSliceAsText
128
+ export function getSliceAsText(rawTextBuffer, offset, length) {
129
+ // Reuses the identical slice boundary logic from above
130
+ try {
131
+ const slice = getSliceAsArrayBuffer(rawTextBuffer, offset, length);
132
+ // Returns an empty string if slice was invalid, or the decoded UTF-8 string
133
+ return slice.length === 0 ? "" : slice.toString('utf8');
134
+ }
135
+ catch (e) {
136
+ console.log(e);
137
+ throw e;
138
+ }
139
+ }
140
+ // Matches QByteArray Response::getSliceAsArrayBuffer
141
+ export function getSliceAsArrayBuffer(rawTextBuffer, offset, length) {
142
+ const totalSize = rawTextBuffer.length;
143
+ if (offset < 0 || offset >= totalSize) {
144
+ return Buffer.alloc(0);
145
+ }
146
+ if (length === -1) {
147
+ length = totalSize - offset;
148
+ }
149
+ else if (length <= 0 || (offset + length) > totalSize) {
150
+ return Buffer.alloc(0); // Strict failure rule matching your new C++ code
151
+ }
152
+ // Creates a zero-copy view of the sliced buffer
153
+ return rawTextBuffer.subarray(offset, offset + length);
154
+ }
@@ -0,0 +1,89 @@
1
+ import { getNormalizedBounds } from './index.js';
2
+ import { addUTCYears, addUTCMonths, addUTCDays } from '../../utils.js';
3
+ const MONTH_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
4
+ const MONTH_LONG = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
5
+ export function formatDate(value, format) {
6
+ const dateObj = value instanceof Date ? value : new Date(value);
7
+ if (Number.isNaN(dateObj.getTime()))
8
+ throw new Error(`Error: Invalid date: ${value} in suffix policy specified for key in Dip`);
9
+ const utcMs = dateObj.getTime();
10
+ // Constant millisecond values for the extreme timezone edges
11
+ const TWELVE_HOURS_MS = 43200000; // 12 * 60 * 60 * 1000
12
+ const FOURTEEN_HOURS_MS = 50400000; // 14 * 60 * 60 * 1000
13
+ // Create dates for the absolute furthest west, UTC, and furthest east
14
+ const dWest = new Date(utcMs - TWELVE_HOURS_MS);
15
+ const dEast = new Date(utcMs + FOURTEEN_HOURS_MS);
16
+ // Extract individual components using UTC methods
17
+ const y1 = dWest.getUTCFullYear(), m1 = dWest.getUTCMonth(), d1 = dWest.getUTCDate();
18
+ const y2 = dateObj.getUTCFullYear(), m2 = dateObj.getUTCMonth(), d2 = dateObj.getUTCDate();
19
+ const y3 = dEast.getUTCFullYear(), m3 = dEast.getUTCMonth(), d3 = dEast.getUTCDate();
20
+ // Fast, loop-free deduplication using inline conditions
21
+ const years = [y1];
22
+ if (y2 !== y1)
23
+ years.push(y2);
24
+ if (y3 !== y2 && y3 !== y1)
25
+ years.push(y3);
26
+ const months = [m1];
27
+ if (m2 !== m1)
28
+ months.push(m2);
29
+ if (m3 !== m2 && m3 !== m1)
30
+ months.push(m3);
31
+ const dates = [d1];
32
+ if (d2 !== d1)
33
+ dates.push(d2);
34
+ if (d3 !== d2 && d3 !== d1)
35
+ dates.push(d3);
36
+ // years and months and dates are already deduplicated
37
+ const separator = '|';
38
+ const replacements = {
39
+ YYYY: _ => years.join(separator),
40
+ YY: _ => years.map(y => String(y).slice(-2)).join(separator),
41
+ MMMM: _ => months.map(m => MONTH_LONG[m]).join(separator),
42
+ MMM: _ => months.map(m => MONTH_SHORT[m]).join(separator),
43
+ MM: _ => months.map(m => String(m + 1).padStart(2, "0")).join(separator),
44
+ DD: _ => dates.map(d => String(d).padStart(2, "0")).join(separator),
45
+ D: _ => dates.join(separator),
46
+ };
47
+ return format.replace(/YYYY|MMMM|MMM|YY|MM|DD|D/g, token => replacements[token]());
48
+ }
49
+ // 📋 Supported Formats
50
+ // YYYY: 4-digit year (e.g., 2026)
51
+ // YY: 2-digit year (e.g., 26)
52
+ // MMMM: Full month name (e.g., July)
53
+ // MMM: Short month name (e.g., Jul)
54
+ // MM: 2-digit padded month (e.g., 07)
55
+ // DD: 2-digit padded day (e.g., 09)
56
+ // D: Unpadded day (e.g., 9)
57
+ // // let a = new Date()
58
+ // // let a = "2026-11-1"
59
+ // let a = new Date().getTime()
60
+ // let b = formatDate(a, "YYYY/DD-MMMM")
61
+ // console.log(b)
62
+ //
63
+ export function fillDates(bounds_t, format) {
64
+ const result = [];
65
+ let step;
66
+ if (format.includes("D"))
67
+ step = "day";
68
+ else if (format.includes("M"))
69
+ step = "month";
70
+ else
71
+ step = "year";
72
+ let bounds = { ...bounds_t, from: new Date(bounds_t.from), to: new Date(bounds_t.to) };
73
+ bounds = getNormalizedBounds(bounds, "date");
74
+ while (bounds.from <= bounds.to) {
75
+ result.push(formatDate(bounds.from, format));
76
+ switch (step) {
77
+ case "day":
78
+ addUTCDays(bounds.from, 1);
79
+ break;
80
+ case "month":
81
+ addUTCMonths(bounds.from, 1);
82
+ break;
83
+ case "year":
84
+ addUTCYears(bounds.from, 1);
85
+ break;
86
+ }
87
+ }
88
+ return [...new Set(result)];
89
+ }