@iobroker/js-controller-common-db 7.2.3 → 8.0.0-alpha.1-20260921-e5941ca8a
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/build/cjs/index.js +3 -3
- package/build/cjs/lib/common/aliasProcessing.js +6 -0
- package/build/cjs/lib/common/aliasProcessing.js.map +2 -2
- package/build/cjs/lib/common/interview.js +2 -0
- package/build/cjs/lib/common/interview.js.map +1 -1
- package/build/cjs/lib/common/logger.d.ts +34 -1
- package/build/cjs/lib/common/logger.js +37 -37
- package/build/cjs/lib/common/logger.js.map +2 -2
- package/build/cjs/lib/common/maybeCallback.js +4 -0
- package/build/cjs/lib/common/maybeCallback.js.map +1 -1
- package/build/cjs/lib/common/password.d.ts +9 -0
- package/build/cjs/lib/common/password.js +8 -6
- package/build/cjs/lib/common/password.js.map +2 -2
- package/build/cjs/lib/common/session.js +10 -5
- package/build/cjs/lib/common/session.js.map +2 -2
- package/build/cjs/lib/common/tools.d.ts +164 -59
- package/build/cjs/lib/common/tools.js +497 -476
- package/build/cjs/lib/common/tools.js.map +3 -3
- package/build/esm/lib/common/aliasProcessing.d.ts.map +1 -1
- package/build/esm/lib/common/aliasProcessing.js +5 -0
- package/build/esm/lib/common/aliasProcessing.js.map +1 -1
- package/build/esm/lib/common/logger.d.ts +34 -1
- package/build/esm/lib/common/logger.d.ts.map +1 -1
- package/build/esm/lib/common/logger.js +45 -49
- package/build/esm/lib/common/logger.js.map +1 -1
- package/build/esm/lib/common/password.d.ts +9 -0
- package/build/esm/lib/common/password.d.ts.map +1 -1
- package/build/esm/lib/common/password.js +5 -0
- package/build/esm/lib/common/password.js.map +1 -1
- package/build/esm/lib/common/session.d.ts.map +1 -1
- package/build/esm/lib/common/session.js +6 -6
- package/build/esm/lib/common/session.js.map +1 -1
- package/build/esm/lib/common/tools.d.ts +164 -59
- package/build/esm/lib/common/tools.d.ts.map +1 -1
- package/build/esm/lib/common/tools.js +535 -586
- package/build/esm/lib/common/tools.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +18 -18
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/common/maybeCallback.ts"],
|
|
4
4
|
"sourcesContent": ["// Beware, below be TypeScript dragons!\n\nimport { ERRORS } from '@/lib/common/tools.js';\n\ntype MaybeCbCallback<T extends any[]> = (...args: T) => void;\ntype MaybeCbErrCallback<T extends any[]> = (error: Error | null | undefined, ...args: T) => void;\n\n// Helper type to infer the return type of the maybeCallbackWithError function\n// If the callback is given, the return type is void\n// otherwise, the return type is a Promise whose resolved value type depends on the given arguments, or the error variable\ntype MaybeCbErrReturnType<\n TCb extends MaybeCbErrCallback<any> | null | undefined,\n TErr extends Error | string | null | undefined,\n TArgs extends any[],\n> =\n TCb extends MaybeCbErrCallback<any>\n ? void\n : // If there is an error given, the promise will never resolve\n TErr extends Error | string\n ? Promise<never>\n : // Infer the return type from the arguments\n Promise<\n [] extends TArgs\n ? void // if ([] === T) void\n : [any] extends TArgs\n ? TArgs[0] // else if (T has one element) => take first element\n : TArgs // else return T entirely\n >;\n\n// Helper type to infer the callback arguments for the maybeCallbackWithError function\n// If a callback is given, they must match its arguments. Otherwise, they are inferred and default to any[]\ntype MaybeCbErrCallbackParameters<\n CB extends MaybeCbErrCallback<any> | null | undefined,\n TErr extends Error | string | null | undefined,\n> =\n Exclude<CB, undefined | null> extends MaybeCbErrCallback<infer U>\n ? // If the error argument is given,\n TErr extends Error | string\n ? // don't require arguments but allow passing them\n U | []\n : // Otherwise, require the correct args\n U\n : any[];\n\n// Helper type to infer the callback arguments for the maybeCallback function\n// If a callback is given, they must match its arguments. Otherwise, they are inferred and default to any[]\ntype MaybeCbCallbackParameters<CB extends MaybeCbCallback<any> | null | undefined> =\n Exclude<CB, undefined | null> extends MaybeCbCallback<infer U> ? U : any[];\n\n// Helper type to infer the return type of the maybeCallback function\n// If the callback is given, the return type is void\n// otherwise, the return type is a Promise whose resolved value type depends on the given arguments\ntype MaybeCbReturnType<TCb extends MaybeCbErrCallback<any> | null | undefined, TArgs extends any[]> =\n TCb extends MaybeCbCallback<any>\n ? void\n : // Infer the return type from the arguments\n Promise<\n [] extends TArgs\n ? void // if ([] === T) void\n : [any] extends TArgs\n ? TArgs[0] // else if (T has one element) => take first element\n : TArgs // else return T entirely\n >;\n\n// Helper type to lower the inference priority of an argument\ntype NoInfer<T> = T & { [K in keyof T]: T[K] };\n\n// This is the publicly visible signature of maybeCallback. The one below is just internal\n// and makes implementing the function much, much easier (although a bit unsound).\nexport function maybeCallback<\n // Limit the callback type to a valid callback type\n TCb extends MaybeCbCallback<any> | null | undefined,\n // The callback arguments must match the callback args\n TArgs extends MaybeCbCallbackParameters<TCb> = MaybeCbCallbackParameters<TCb>,\n>(\n callback: TCb,\n // Infer the arguments with lower priority than the callback - they need to match it.\n ...args: NoInfer<TArgs>\n): MaybeCbReturnType<TCb, TArgs>;\n\n/**\n * Checks if the given callback is a function and if so calls it with the given parameter immediately, else a resolved Promise is returned\n *\n * @param callback - callback function to be executed\n * @param args - as many arguments as needed, which will be returned by the callback function or by the Promise\n * @returns if Promise is resolved with multiple arguments, an array is returned\n */\nexport function maybeCallback<T extends any[]>(callback?: MaybeCbCallback<T> | null, ...args: T): Promise<any> | void {\n if (typeof callback === 'function') {\n // if function we call it with given param\n setImmediate(callback, ...args);\n } else {\n return Promise.resolve(args.length > 1 ? args : args[0]);\n }\n}\n\n// This is the publicly visible signature of maybeCallbackWithError. The one below is just internal\n// and makes implementing the function much, much easier (although a bit unsound).\nexport function maybeCallbackWithError<\n // Limit the callback type to a valid callback type\n TCb extends MaybeCbErrCallback<any> | null | undefined,\n // And the error to either an error or sting, or null/undefined\n TErr extends Error | string | null | undefined,\n // The callback arguments must match the callback args\n TArgs extends MaybeCbErrCallbackParameters<TCb, TErr> = MaybeCbErrCallbackParameters<TCb, TErr>,\n>(\n callback: TCb,\n error: TErr,\n // Infer the arguments with lower priority than the callback - they need to match it.\n ...args: NoInfer<TArgs>\n): MaybeCbErrReturnType<TCb, TErr, TArgs>;\n\n/**\n * Checks if the given callback is a function and if so calls it with the given error and parameter immediately, else a resolved or rejected Promise is returned. Error ERROR_DB_CLOSED are not rejecting the promise\n *\n * @param callback - callback function to be executed\n * @param error - error which will be used by the callback function. If callback is not a function and\n * error is given, a rejected Promise is returned. If error is given, but it is not an instance of Error, it is converted into one.\n * @param args - as many arguments as needed, which will be returned by the callback function or by the Promise\n * @returns if Promise is resolved with multiple arguments, an array is returned\n */\nexport function maybeCallbackWithError<T extends any[]>(\n callback: MaybeCbErrCallback<T> | null | undefined,\n error: Error | string | null | undefined,\n ...args: T\n): Promise<any> | void {\n if (error !== undefined && error !== null && !(error instanceof Error)) {\n // if it's not a real Error, we convert it into one\n error = new Error(error);\n }\n const isDbError = error ? error.message === ERRORS.ERROR_DB_CLOSED : false;\n\n if (typeof callback === 'function') {\n setImmediate(callback, error, ...args);\n } else if (error && !isDbError) {\n return Promise.reject(error);\n } else {\n return Promise.resolve(args.length > 1 ? args : args[0]);\n }\n}\n\n// This is the publicly visible signature of maybeCallbackWithRedisError, which is an exact copy of maybeCallbackWithError's signature.\n// The one below is just internal and makes implementing the function much, much easier (although a bit unsound).\nexport function maybeCallbackWithRedisError<\n // Limit the callback type to a valid callback type\n TCb extends MaybeCbErrCallback<any> | null | undefined,\n // And the error to either an error or sting, or null/undefined\n TErr extends Error | string | null | undefined,\n // The callback arguments must match the callback args\n TArgs extends MaybeCbErrCallbackParameters<TCb, TErr> = MaybeCbErrCallbackParameters<TCb, TErr>,\n>(\n callback: TCb,\n error: TErr,\n // Infer the arguments with lower priority than the callback - they need to match it.\n ...args: NoInfer<TArgs>\n): MaybeCbErrReturnType<TCb, TErr, TArgs>;\n\n/**\n * Checks if the given callback is a function and if so calls it with the given error and parameter immediately, else a resolved or rejected Promise is returned. Redis-Error \"Connection is closed.\" is converted into ERROR_DB_CLOSED\n *\n * @param callback - callback function to be executed\n * @param error - error which will be used by the callback function. If callback is not a function and\n * error is given, a rejected Promise is returned. If error is given, but it is not an instance of Error, it is converted into one.\n * @param args - as many arguments as needed, which will be returned by the callback function or by the Promise\n * @returns Promise if Promise is resolved with multiple arguments, an array is returned\n */\nexport function maybeCallbackWithRedisError<T extends any[]>(\n callback: MaybeCbErrCallback<T> | null | undefined,\n error: Error | string | null | undefined,\n ...args: T\n): Promise<any> | void {\n if (error instanceof Error && error.message.includes('Connection is closed')) {\n error.message = ERRORS.ERROR_DB_CLOSED;\n }\n return maybeCallbackWithError(callback, error, ...args);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAEA,mBAAuB;AAqFjB,SAAU,cAA+B,aAAyC,MAAO;AAC3F,MAAI,OAAO,aAAa,YAAY;AAEhC,iBAAa,UAAU,GAAG,IAAI;EAClC,OAAO;AACH,WAAO,QAAQ,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,CAAC;EAC3D;AACJ;AAPgB;AAkCV,SAAU,uBACZ,UACA,UACG,MAAO;AAEV,MAAI,UAAU,UAAa,UAAU,QAAQ,EAAE,iBAAiB,QAAQ;AAEpE,YAAQ,IAAI,MAAM,KAAK;EAC3B;AACA,QAAM,YAAY,QAAQ,MAAM,YAAY,oBAAO,kBAAkB;AAErE,MAAI,OAAO,aAAa,YAAY;AAChC,iBAAa,UAAU,OAAO,GAAG,IAAI;EACzC,WAAW,SAAS,CAAC,WAAW;AAC5B,WAAO,QAAQ,OAAO,KAAK;EAC/B,OAAO;AACH,WAAO,QAAQ,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,CAAC;EAC3D;AACJ;AAlBgB;AA6CV,SAAU,4BACZ,UACA,UACG,MAAO;AAEV,MAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,sBAAsB,GAAG;AAC1E,UAAM,UAAU,oBAAO;EAC3B;AACA,SAAO,uBAAuB,UAAU,OAAO,GAAG,IAAI;AAC1D;AATgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -28,10 +28,19 @@
|
|
|
28
28
|
|
|
29
29
|
*
|
|
30
30
|
*/
|
|
31
|
+
/** Set of password helper functions bound to a specific password */
|
|
31
32
|
export interface PasswordReturnValue {
|
|
33
|
+
/** Check whether the password fulfills the complexity requirements */
|
|
32
34
|
complexity: (password: string, callback: (isComplex: boolean) => void) => boolean;
|
|
35
|
+
/** Verify the password against the given stored hash */
|
|
33
36
|
check: (hashedPassword: string, callback: (err?: Error | null, isOk?: boolean) => void) => void;
|
|
37
|
+
/** Create a salted PBKDF2 hash of the password */
|
|
34
38
|
hash: (salt: string | null, iterations: number | null, callback: (err?: Error | null, hash?: string) => void) => void;
|
|
35
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a set of helper functions (hash, check, complexity) bound to the given password
|
|
42
|
+
*
|
|
43
|
+
* @param pw The plain text password to operate on
|
|
44
|
+
*/
|
|
36
45
|
export declare function password(pw: string): PasswordReturnValue;
|
|
37
46
|
//# sourceMappingURL=password.d.ts.map
|
|
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
9
|
var __export = (target, all) => {
|
|
9
10
|
for (var name in all)
|
|
10
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -34,7 +35,7 @@ module.exports = __toCommonJS(password_exports);
|
|
|
34
35
|
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
35
36
|
function password(pw) {
|
|
36
37
|
return {
|
|
37
|
-
hash: (salt, iterations, callback) => {
|
|
38
|
+
hash: /* @__PURE__ */ __name((salt, iterations, callback) => {
|
|
38
39
|
salt = salt || import_node_crypto.default.randomBytes(16).toString("hex");
|
|
39
40
|
iterations = iterations || 1e4;
|
|
40
41
|
import_node_crypto.default.pbkdf2(pw, salt, iterations, 256, "sha256", (err, key) => {
|
|
@@ -43,8 +44,8 @@ function password(pw) {
|
|
|
43
44
|
}
|
|
44
45
|
callback(null, `pbkdf2$${iterations}$${key.toString("hex")}$${salt}`);
|
|
45
46
|
});
|
|
46
|
-
},
|
|
47
|
-
check: function(hashedPassword, callback) {
|
|
47
|
+
}, "hash"),
|
|
48
|
+
check: /* @__PURE__ */ __name(function(hashedPassword, callback) {
|
|
48
49
|
if (!hashedPassword) {
|
|
49
50
|
return callback(null, false);
|
|
50
51
|
}
|
|
@@ -62,8 +63,8 @@ function password(pw) {
|
|
|
62
63
|
callback(null, newHash === hashedPassword);
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
|
-
},
|
|
66
|
-
complexity: (password2, callback) => {
|
|
66
|
+
}, "check"),
|
|
67
|
+
complexity: /* @__PURE__ */ __name((password2, callback) => {
|
|
67
68
|
let result = false;
|
|
68
69
|
if (typeof password2 === "string") {
|
|
69
70
|
result = password2.length >= 8 && // minimum length is 8
|
|
@@ -73,9 +74,10 @@ function password(pw) {
|
|
|
73
74
|
}
|
|
74
75
|
typeof callback === "function" && callback(result);
|
|
75
76
|
return result;
|
|
76
|
-
}
|
|
77
|
+
}, "complexity")
|
|
77
78
|
};
|
|
78
79
|
}
|
|
80
|
+
__name(password, "password");
|
|
79
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
80
82
|
0 && (module.exports = {
|
|
81
83
|
password
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/common/password.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n *\n * password hash and check\n *\n * 7'2014-2024 Bluefox <dogafox@gmail.com>\n * 2014 hobbyquaker <hq@ccu.io>\n *\n * derived from https://github.com/florianheinemann/password-hash-and-salt/ (MIT License)\n *\n * The created hash is of the following format: <algorithm>$<iterations>$<hash>$<salt>\n *\n * Usage Example:\n \n var password = require('./lib/password.js');\n \n password('test').hash(null, null, function (err, res) {\n console.log(res);\n \n password('test').check(res, function (err, res) {\n console.log('test: ' + res);\n });\n \n password('muh').check(res, function (err, res) {\n console.log('muh: ' + res);\n });\n \n });\n \n *\n */\n\nimport crypto from 'node:crypto';\n\nexport interface PasswordReturnValue {\n complexity: (password: string, callback: (isComplex: boolean) => void) => boolean;\n check: (hashedPassword: string, callback: (err?: Error | null, isOk?: boolean) => void) => void;\n hash: (\n salt: string | null,\n iterations: number | null,\n callback: (err?: Error | null, hash?: string) => void,\n ) => void;\n}\n\nexport function password(pw: string): PasswordReturnValue {\n return {\n hash: (salt, iterations, callback) => {\n salt = salt || crypto.randomBytes(16).toString('hex');\n iterations = iterations || 10_000;\n\n crypto.pbkdf2(pw, salt, iterations, 256, 'sha256', (err, key) => {\n if (err) {\n return callback(err);\n }\n\n callback(null, `pbkdf2$${iterations}$${key.toString('hex')}$${salt}`);\n });\n },\n check: function (hashedPassword, callback) {\n if (!hashedPassword) {\n return callback(null, false);\n }\n const key = hashedPassword.split('$');\n if (key.length !== 4 || !key[2] || !key[3]) {\n return callback(new Error('Hash not formatted correctly'));\n }\n if (key[0] !== 'pbkdf2') {\n return callback(new Error('Unknown'));\n }\n\n this.hash(key[3], parseInt(key[1], 10), (error, newHash) => {\n if (error) {\n callback(error);\n } else {\n callback(null, newHash === hashedPassword);\n }\n });\n },\n complexity: (password, callback) => {\n let result = false;\n if (typeof password === 'string') {\n result =\n password.length >= 8 && // minimum length is 8\n /\\d/.test(password) && // contains at least one digit\n /[a-z]/.test(password) && // contains at least one lower case letter\n /[A-Z]/.test(password); // contains at least one upper case letter\n }\n typeof callback === 'function' && callback(result);\n return result; // true if the complexity OK\n },\n };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n *\n * password hash and check\n *\n * 7'2014-2024 Bluefox <dogafox@gmail.com>\n * 2014 hobbyquaker <hq@ccu.io>\n *\n * derived from https://github.com/florianheinemann/password-hash-and-salt/ (MIT License)\n *\n * The created hash is of the following format: <algorithm>$<iterations>$<hash>$<salt>\n *\n * Usage Example:\n \n var password = require('./lib/password.js');\n \n password('test').hash(null, null, function (err, res) {\n console.log(res);\n \n password('test').check(res, function (err, res) {\n console.log('test: ' + res);\n });\n \n password('muh').check(res, function (err, res) {\n console.log('muh: ' + res);\n });\n \n });\n \n *\n */\n\nimport crypto from 'node:crypto';\n\n/** Set of password helper functions bound to a specific password */\nexport interface PasswordReturnValue {\n /** Check whether the password fulfills the complexity requirements */\n complexity: (password: string, callback: (isComplex: boolean) => void) => boolean;\n /** Verify the password against the given stored hash */\n check: (hashedPassword: string, callback: (err?: Error | null, isOk?: boolean) => void) => void;\n /** Create a salted PBKDF2 hash of the password */\n hash: (\n salt: string | null,\n iterations: number | null,\n callback: (err?: Error | null, hash?: string) => void,\n ) => void;\n}\n\n/**\n * Create a set of helper functions (hash, check, complexity) bound to the given password\n *\n * @param pw The plain text password to operate on\n */\nexport function password(pw: string): PasswordReturnValue {\n return {\n hash: (salt, iterations, callback) => {\n salt = salt || crypto.randomBytes(16).toString('hex');\n iterations = iterations || 10_000;\n\n crypto.pbkdf2(pw, salt, iterations, 256, 'sha256', (err, key) => {\n if (err) {\n return callback(err);\n }\n\n callback(null, `pbkdf2$${iterations}$${key.toString('hex')}$${salt}`);\n });\n },\n check: function (hashedPassword, callback) {\n if (!hashedPassword) {\n return callback(null, false);\n }\n const key = hashedPassword.split('$');\n if (key.length !== 4 || !key[2] || !key[3]) {\n return callback(new Error('Hash not formatted correctly'));\n }\n if (key[0] !== 'pbkdf2') {\n return callback(new Error('Unknown'));\n }\n\n this.hash(key[3], parseInt(key[1], 10), (error, newHash) => {\n if (error) {\n callback(error);\n } else {\n callback(null, newHash === hashedPassword);\n }\n });\n },\n complexity: (password, callback) => {\n let result = false;\n if (typeof password === 'string') {\n result =\n password.length >= 8 && // minimum length is 8\n /\\d/.test(password) && // contains at least one digit\n /[a-z]/.test(password) && // contains at least one lower case letter\n /[A-Z]/.test(password); // contains at least one upper case letter\n }\n typeof callback === 'function' && callback(result);\n return result; // true if the complexity OK\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AA+BA,yBAAmB;AAqBb,SAAU,SAAS,IAAU;AAC/B,SAAO;IACH,MAAM,wBAAC,MAAM,YAAY,aAAY;AACjC,aAAO,QAAQ,mBAAAA,QAAO,YAAY,EAAE,EAAE,SAAS,KAAK;AACpD,mBAAa,cAAc;AAE3B,yBAAAA,QAAO,OAAO,IAAI,MAAM,YAAY,KAAK,UAAU,CAAC,KAAK,QAAO;AAC5D,YAAI,KAAK;AACL,iBAAO,SAAS,GAAG;QACvB;AAEA,iBAAS,MAAM,UAAU,UAAU,IAAI,IAAI,SAAS,KAAK,CAAC,IAAI,IAAI,EAAE;MACxE,CAAC;IACL,GAXM;IAYN,OAAO,gCAAU,gBAAgB,UAAQ;AACrC,UAAI,CAAC,gBAAgB;AACjB,eAAO,SAAS,MAAM,KAAK;MAC/B;AACA,YAAM,MAAM,eAAe,MAAM,GAAG;AACpC,UAAI,IAAI,WAAW,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG;AACxC,eAAO,SAAS,IAAI,MAAM,8BAA8B,CAAC;MAC7D;AACA,UAAI,IAAI,CAAC,MAAM,UAAU;AACrB,eAAO,SAAS,IAAI,MAAM,SAAS,CAAC;MACxC;AAEA,WAAK,KAAK,IAAI,CAAC,GAAG,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,YAAW;AACvD,YAAI,OAAO;AACP,mBAAS,KAAK;QAClB,OAAO;AACH,mBAAS,MAAM,YAAY,cAAc;QAC7C;MACJ,CAAC;IACL,GAnBO;IAoBP,YAAY,wBAACC,WAAU,aAAY;AAC/B,UAAI,SAAS;AACb,UAAI,OAAOA,cAAa,UAAU;AAC9B,iBACIA,UAAS,UAAU;QACnB,KAAK,KAAKA,SAAQ;QAClB,QAAQ,KAAKA,SAAQ;QACrB,QAAQ,KAAKA,SAAQ;MAC7B;AACA,aAAO,aAAa,cAAc,SAAS,MAAM;AACjD,aAAO;IACX,GAXY;;AAapB;AA/CgB;",
|
|
6
6
|
"names": ["crypto", "password"]
|
|
7
7
|
}
|
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -24,14 +25,17 @@ module.exports = __toCommonJS(session_exports);
|
|
|
24
25
|
function createAdapterStore(session, defaultTtl = 3600) {
|
|
25
26
|
const Store = session.Store;
|
|
26
27
|
class AdapterStore extends Store {
|
|
28
|
+
static {
|
|
29
|
+
__name(this, "AdapterStore");
|
|
30
|
+
}
|
|
27
31
|
adapter;
|
|
32
|
+
/**
|
|
33
|
+
* @param options Store options including the adapter instance used to read and write sessions
|
|
34
|
+
*/
|
|
28
35
|
constructor(options) {
|
|
29
36
|
super(options);
|
|
30
37
|
this.adapter = options.adapter;
|
|
31
|
-
options
|
|
32
|
-
if (!options.cookie) {
|
|
33
|
-
options.cookie = { maxAge: defaultTtl };
|
|
34
|
-
}
|
|
38
|
+
options.cookie ||= { maxAge: defaultTtl };
|
|
35
39
|
Store.call(this, options);
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
@@ -65,7 +69,7 @@ function createAdapterStore(session, defaultTtl = 3600) {
|
|
|
65
69
|
sess = ttl;
|
|
66
70
|
ttl = sess?.cookie?.originalMaxAge ? Math.round(sess.cookie.originalMaxAge / 1e3) : defaultTtl;
|
|
67
71
|
}
|
|
68
|
-
ttl
|
|
72
|
+
ttl ||= defaultTtl;
|
|
69
73
|
this.adapter.setSession(sid, ttl, sess, function(err) {
|
|
70
74
|
fn?.call(this, err);
|
|
71
75
|
});
|
|
@@ -82,6 +86,7 @@ function createAdapterStore(session, defaultTtl = 3600) {
|
|
|
82
86
|
}
|
|
83
87
|
return AdapterStore;
|
|
84
88
|
}
|
|
89
|
+
__name(createAdapterStore, "createAdapterStore");
|
|
85
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
86
91
|
0 && (module.exports = {
|
|
87
92
|
createAdapterStore
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/common/session.ts"],
|
|
4
|
-
"sourcesContent": ["type
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["type Session = {\n Store: any;\n};\n\n// TODO: in the long term move this file somewhere where we have types access it is nowhere used in controller itself and just exported for adapters so it should go to js-controller-adapter package\ninterface AdapterStoreOptions {\n /** The ioBroker adapter */\n adapter: {\n getSession: (sid: string, callback: (obj: ioBroker.Session) => void) => void;\n setSession: (sid: string, ttl: number, sess: ioBroker.Session, callback: (err?: Error | null) => void) => void;\n destroySession: (sid: string, callback: () => void) => void;\n };\n /** The cookie */\n cookie?: {\n maxAge?: number;\n originalMaxAge?: number;\n };\n}\n\n/**\n * Function to create an AdapterStore constructor\n *\n * @param session The session object, like \"express-session\"\n * @param defaultTtl the default time to live in seconds\n * @returns the constructor to create a new AdapterStore\n */\nexport function createAdapterStore(session: Session, defaultTtl = 3600): any {\n const Store = session.Store;\n\n class AdapterStore extends Store {\n private readonly adapter: {\n getSession: (sid: string, callback: (obj: ioBroker.Session) => void) => void;\n setSession: (\n sid: string,\n ttl: number,\n sess: ioBroker.Session,\n callback: (err?: Error | null) => void,\n ) => void;\n destroySession: (sid: string, callback: () => void) => void;\n };\n\n /**\n * @param options Store options including the adapter instance used to read and write sessions\n */\n constructor(options: AdapterStoreOptions) {\n super(options);\n\n this.adapter = options.adapter;\n\n options.cookie ||= { maxAge: defaultTtl };\n Store.call(this, options);\n }\n\n /**\n * Attempt to fetch session by the given `sid`.\n *\n * @param sid Session ID\n * @param fn callback\n */\n get(sid: string, fn: (err?: Error | string | null, obj?: ioBroker.Session) => void): void {\n this.adapter.getSession(sid, (obj: ioBroker.Session): void => {\n if (obj) {\n if (fn) {\n return fn(null, obj);\n }\n } else if (fn) {\n return fn();\n }\n });\n }\n\n /**\n * Commit the given `sess` object associated with the given `sid`.\n *\n * @param sid Session ID\n * @param sess the session\n * @param fn callback\n */\n set(sid: string, sess: ioBroker.Session, fn: (err?: Error | null) => void): void;\n /**\n * Commit the given `sess` object associated with the given `sid`.\n *\n * @param sid Session ID\n * @param ttl Time to live\n * @param sess the session\n * @param fn callback\n */\n set(sid: string, ttl: number, sess: ioBroker.Session, fn: (err?: Error | null) => void): void;\n\n /**\n * Commit the given `sess` object associated with the given `sid`.\n *\n * @param sid Session ID\n * @param ttl Time to live\n * @param sess the session\n * @param fn callback\n */\n set(sid: unknown, ttl: unknown, sess: unknown, fn?: unknown): void {\n if (typeof sess === 'function') {\n fn = sess;\n sess = ttl;\n // analyse if the session is stored directly from express session\n ttl = (sess as ioBroker.Session)?.cookie?.originalMaxAge\n ? Math.round((sess as ioBroker.Session).cookie!.originalMaxAge! / 1000)\n : defaultTtl;\n }\n ttl ||= defaultTtl;\n this.adapter.setSession(\n sid as string,\n ttl as number,\n sess as ioBroker.Session,\n function (err?: Error | null): void {\n // @ts-expect-error \"this\" is OK\n (fn as (err?: Error | null) => void)?.call(this, err);\n },\n ); // do not use here => !!!\n }\n\n /**\n * Destroy the session associated with the given `sid`.\n *\n * @param sid Session ID\n * @param fn callback\n */\n destroy(sid: string, fn: () => void): void {\n this.adapter.destroySession(sid, fn);\n }\n }\n\n return AdapterStore;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAmBA;;;;;AAOM,SAAU,mBAAmB,SAAkB,aAAa,MAAI;AAClE,QAAM,QAAQ,QAAQ;EAEtB,MAAM,qBAAqB,MAAK;IAVpC,OAUoC;;;IACX;;;;IAcjB,YAAY,SAA4B;AACpC,YAAM,OAAO;AAEb,WAAK,UAAU,QAAQ;AAEvB,cAAQ,WAAW,EAAE,QAAQ,WAAU;AACvC,YAAM,KAAK,MAAM,OAAO;IAC5B;;;;;;;IAQA,IAAI,KAAa,IAAiE;AAC9E,WAAK,QAAQ,WAAW,KAAK,CAAC,QAA+B;AACzD,YAAI,KAAK;AACL,cAAI,IAAI;AACJ,mBAAO,GAAG,MAAM,GAAG;UACvB;QACJ,WAAW,IAAI;AACX,iBAAO,GAAE;QACb;MACJ,CAAC;IACL;;;;;;;;;IA4BA,IAAI,KAAc,KAAc,MAAe,IAAY;AACvD,UAAI,OAAO,SAAS,YAAY;AAC5B,aAAK;AACL,eAAO;AAEP,cAAO,MAA2B,QAAQ,iBACpC,KAAK,MAAO,KAA0B,OAAQ,iBAAkB,GAAI,IACpE;MACV;AACA,cAAQ;AACR,WAAK,QAAQ,WACT,KACA,KACA,MACA,SAAU,KAAkB;AAEvB,YAAqC,KAAK,MAAM,GAAG;MACxD,CAAC;IAET;;;;;;;IAQA,QAAQ,KAAa,IAAc;AAC/B,WAAK,QAAQ,eAAe,KAAK,EAAE;IACvC;;AAGJ,SAAO;AACX;AAxGgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|