@flink-app/generic-auth-plugin 0.12.1-alpha.0 → 0.12.1-alpha.1
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/.flink/generatedHandlers.ts +1 -1
- package/.flink/generatedJobs.ts +1 -1
- package/.flink/generatedRepos.ts +1 -1
- package/.flink/schemas/schemas.json +2 -4
- package/.flink/schemas/schemas.ts +1 -1
- package/.flink/start.ts +1 -1
- package/dist/.flink/generatedHandlers.js +1 -1
- package/dist/.flink/generatedJobs.js +1 -1
- package/dist/.flink/generatedRepos.js +1 -1
- package/dist/.flink/schemas/schemas.json +2 -4
- package/dist/.flink/start.js +1 -1
- package/dist/src/coreFunctions.js +8 -8
- package/dist/src/handlers/Management/DeleteUserByUserid.js +21 -23
- package/dist/src/handlers/Management/GetSchema.js +12 -14
- package/dist/src/handlers/Management/GetUser.js +21 -23
- package/dist/src/handlers/Management/GetUserByUserid.js +22 -24
- package/dist/src/handlers/Management/GetUserViewByUserid.js +34 -36
- package/dist/src/handlers/Management/PutUserPasswordByUserid.js +46 -48
- package/dist/src/handlers/Management/PutUserProfileByUserid.js +24 -26
- package/dist/src/handlers/Management/PutUserProfileByUseridAppend.js +27 -29
- package/dist/src/handlers/Management/PutUserRolesByUserid.js +24 -26
- package/dist/src/handlers/Management/PutUserUsernameByUserid.js +33 -35
- package/dist/src/handlers/UserCreate.js +44 -46
- package/dist/src/handlers/UserLogin.js +23 -25
- package/dist/src/handlers/UserLoginByToken.js +23 -25
- package/dist/src/handlers/UserPasswordPut.js +21 -23
- package/dist/src/handlers/UserPasswordResetComplete.js +27 -29
- package/dist/src/handlers/UserPasswordResetForm.js +11 -11
- package/dist/src/handlers/UserPasswordResetStart.js +53 -55
- package/dist/src/handlers/UserProfileGet.js +21 -23
- package/dist/src/handlers/UserProfilePut.js +28 -30
- package/dist/src/handlers/UserPushRegisterToken.js +72 -74
- package/dist/src/handlers/UserPushRemoveToken.js +25 -27
- package/dist/src/handlers/UserToken.js +24 -26
- package/dist/src/index.js +7 -8
- package/dist/src/init.js +8 -4
- package/dist/src/management.js +5 -1
- package/package.json +32 -32
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -38,35 +38,33 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
|
|
40
40
|
var flink_1 = require("@flink-app/flink");
|
|
41
|
-
var postPasswordResetCompleteHandler = function (_a) {
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
});
|
|
41
|
+
var postPasswordResetCompleteHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
42
|
+
var pluginName, repo, jwtSecret /*, numberOfDigits, lifeTime*/, resp;
|
|
43
|
+
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
44
|
+
return __generator(this, function (_c) {
|
|
45
|
+
switch (_c.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
pluginName = origin || "genericAuthPlugin";
|
|
48
|
+
repo = ctx.repos[ctx.plugins[pluginName].repoName];
|
|
49
|
+
if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
|
|
50
|
+
return [2 /*return*/, (0, flink_1.internalServerError)("Password reset settings is needed to use password-reset")];
|
|
51
|
+
}
|
|
52
|
+
jwtSecret = ctx.plugins[pluginName].passwordResetSettings.code.jwtSecret;
|
|
53
|
+
return [4 /*yield*/, ctx.plugins.genericAuthPlugin.passwordResetComplete(repo, ctx.auth, jwtSecret, req.body.passwordResetToken, req.body.code, req.body.password, ctx.plugins.genericAuthPlugin.createPasswordHashAndSaltMethod, ctx.plugins.genericAuthPlugin.passwordResetSettings.passwordResetReusableTokens)];
|
|
54
|
+
case 1:
|
|
55
|
+
resp = _c.sent();
|
|
56
|
+
switch (resp.status) {
|
|
57
|
+
case "invalidCode":
|
|
58
|
+
return [2 /*return*/, (0, flink_1.badRequest)("Invalid validation code", resp.status)];
|
|
59
|
+
case "passwordError":
|
|
60
|
+
return [2 /*return*/, (0, flink_1.badRequest)("Invalid password", resp.status)];
|
|
61
|
+
case "userNotFound":
|
|
62
|
+
return [2 /*return*/, (0, flink_1.notFound)("User not found", resp.status)];
|
|
63
|
+
}
|
|
64
|
+
return [2 /*return*/, { data: resp, status: 200 }];
|
|
65
|
+
}
|
|
68
66
|
});
|
|
69
|
-
};
|
|
67
|
+
}); };
|
|
70
68
|
exports.default = postPasswordResetCompleteHandler;
|
|
71
69
|
exports.__assumedHttpMethod = "", exports.__file = "UserPasswordResetComplete.ts", exports.__query = [], exports.__params = [];
|
|
72
70
|
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "passwordResetToken": { "type": "string" }, "code": { "type": "string" }, "password": { "type": "string" } }, "required": ["code", "password", "passwordResetToken"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "userNotFound", "invalidCode", "passwordError"] } }, "required": ["status"], "definitions": {} } };
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -46,15 +46,15 @@ var handlebars_1 = __importDefault(require("handlebars"));
|
|
|
46
46
|
var defaultTemplate = "<html>\n<head>\n <title>Password reset</title>\n <link rel=\"stylesheet\" href=\"form/style.css\" />\n <script src=\"form/script.js\" type=\"text/javascript\"></script>\n</head>\n<body>\n <form id=\"form\">\n <p>Please enter new password</p>\n <input type=\"password\" name=\"password\" placeholder=\"Enter new password\" />\n <input\n type=\"password\"\n name=\"confirmPassword\"\n placeholder=\"Confirm new password\"\n />\n <button id=\"submit-btn\">Submit</button>\n </form>\n <div id=\"success\">Password has been updated, please proceed to login.</div>\n</body>\n</html>\n";
|
|
47
47
|
var script = "\n window.onload = () => {\n const urlSearchParams = new URLSearchParams(window.location.search);\n const params = Object.fromEntries(urlSearchParams.entries());\n const { token, code } = params;\n\n if (!token) {\n alert(\"Missing token\");\n } else if (!code) {\n alert(\"Missing code\");\n }\n\n const submitBtnEl = document.getElementById(\"submit-btn\");\n const [passwordInputEl, confirmPasswordEl] =\n document.getElementsByTagName(\"input\");\n\n submitBtnEl.onclick = async (e) => {\n e.preventDefault();\n e.stopPropagation();\n\n if (!passwordInputEl.value) {\n return alert(\"Enter a new password\");\n } else if (passwordInputEl.value !== confirmPasswordEl.value) {\n return alert(\n \"Passwords does not match, make sure that new and confirmed passwords are the same\"\n );\n }\n\n const res = await window.fetch(\"{{completeUrl}}\", {\n method: \"POST\",\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n passwordResetToken: token,\n code: code,\n password: passwordInputEl.value,\n }),\n });\n\n if (res.status > 399) {\n alert(\"Failed to set new password\");\n } else {\n document.getElementById(\"form\").style.display = \"none\";\n document.getElementById(\"success\").style.display = \"block\";\n }\n };\n };\n";
|
|
48
48
|
var style = " * {\n box-sizing: border-box;\n font-family: Arial, Helvetica, sans-serif;\n }\n\n p {\n margin: 0.5rem 0;\n }\n\n body {\n padding: 1rem;\n }\n\n form {\n display: block;\n max-width: 320px;\n }\n\n input {\n width: 100%;\n display: block;\n margin: 0.5rem 0;\n }\n\n #success {\n display: none;\n font-size: 1.2rem;\n color: rgb(0, 177, 115);\n max-width: 350px;\n }\n";
|
|
49
|
-
function handleUserPasswordResetForm(
|
|
50
|
-
|
|
51
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
+
function handleUserPasswordResetForm(_req_1, res_1, _a) {
|
|
50
|
+
return __awaiter(this, arguments, void 0, function (_req, res, _b) {
|
|
52
51
|
var tpl, html;
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
var templateFile = _b.templateFile, completeUrl = _b.completeUrl;
|
|
53
|
+
return __generator(this, function (_c) {
|
|
54
|
+
switch (_c.label) {
|
|
55
55
|
case 0: return [4 /*yield*/, readTemplate(templateFile)];
|
|
56
56
|
case 1:
|
|
57
|
-
tpl =
|
|
57
|
+
tpl = _c.sent();
|
|
58
58
|
html = handlebars_1.default.compile(tpl)({
|
|
59
59
|
completeUrl: completeUrl,
|
|
60
60
|
});
|
|
@@ -65,11 +65,11 @@ function handleUserPasswordResetForm(_req, res, _a) {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
exports.handleUserPasswordResetForm = handleUserPasswordResetForm;
|
|
68
|
-
function resetPasswordFormScript(
|
|
69
|
-
|
|
70
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
function resetPasswordFormScript(req_1, res_1, _a) {
|
|
69
|
+
return __awaiter(this, arguments, void 0, function (req, res, _b) {
|
|
71
70
|
var js;
|
|
72
|
-
|
|
71
|
+
var completeUrl = _b.completeUrl;
|
|
72
|
+
return __generator(this, function (_c) {
|
|
73
73
|
res.header("Content-Type", "application/javascript");
|
|
74
74
|
js = handlebars_1.default.compile(script)({ completeUrl: completeUrl });
|
|
75
75
|
res.send(js);
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -42,61 +42,59 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
|
|
43
43
|
var flink_1 = require("@flink-app/flink");
|
|
44
44
|
var handlebars_1 = __importDefault(require("handlebars"));
|
|
45
|
-
var postPasswordResetStartHandler = function (_a) {
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
});
|
|
45
|
+
var postPasswordResetStartHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
46
|
+
var pluginName, genericAuthPlugin, repo, _c, jwtSecret, numberOfDigits, lifeTime, resp, emailCtx, emailSettings, subject, html, email;
|
|
47
|
+
var _d;
|
|
48
|
+
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
49
|
+
return __generator(this, function (_e) {
|
|
50
|
+
switch (_e.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
pluginName = origin || "genericAuthPlugin";
|
|
53
|
+
genericAuthPlugin = ctx.plugins[pluginName];
|
|
54
|
+
repo = ctx.repos[genericAuthPlugin.repoName];
|
|
55
|
+
if (((_d = ctx.plugins.emailPlugin) === null || _d === void 0 ? void 0 : _d.client) == null) {
|
|
56
|
+
return [2 /*return*/, (0, flink_1.internalServerError)("Email plugin have to be initialized to use /password/reset")];
|
|
57
|
+
}
|
|
58
|
+
if (!genericAuthPlugin.passwordResetSettings) {
|
|
59
|
+
return [2 /*return*/, (0, flink_1.internalServerError)("Password reset settings is needed to use /password/reset")];
|
|
60
|
+
}
|
|
61
|
+
_c = genericAuthPlugin.passwordResetSettings.code, jwtSecret = _c.jwtSecret, numberOfDigits = _c.numberOfDigits, lifeTime = _c.lifeTime;
|
|
62
|
+
return [4 /*yield*/, genericAuthPlugin.passwordResetStart(repo, ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime, genericAuthPlugin.passwordResetSettings.passwordResetReusableTokens)];
|
|
63
|
+
case 1:
|
|
64
|
+
resp = _e.sent();
|
|
65
|
+
if (resp.status != "success") {
|
|
66
|
+
return [2 /*return*/, { data: { status: "success", passwordResetToken: resp.passwordResetToken } }];
|
|
67
|
+
}
|
|
68
|
+
emailCtx = {
|
|
69
|
+
code: resp.code,
|
|
70
|
+
passwordResetToken: resp.passwordResetToken,
|
|
71
|
+
username: req.body.username,
|
|
72
|
+
profile: resp.profile,
|
|
73
|
+
template: req.body.template,
|
|
74
|
+
additionalAuth: req.body.additionalAuth,
|
|
75
|
+
resetPasswordFormBaseUrl: genericAuthPlugin.passwordResetSettings.resetPasswordFormBaseUrl
|
|
76
|
+
};
|
|
77
|
+
emailSettings = genericAuthPlugin.passwordResetSettings.email;
|
|
78
|
+
if (typeof emailSettings == "function") {
|
|
79
|
+
emailSettings = emailSettings(emailCtx);
|
|
80
|
+
}
|
|
81
|
+
subject = handlebars_1.default.compile(emailSettings.subject)(emailCtx);
|
|
82
|
+
html = handlebars_1.default.compile(emailSettings.html)(emailCtx);
|
|
83
|
+
email = req.body.username;
|
|
84
|
+
return [4 /*yield*/, ctx.plugins.emailPlugin.client.send({
|
|
85
|
+
from: emailSettings.from_address,
|
|
86
|
+
to: [email],
|
|
87
|
+
subject: subject,
|
|
88
|
+
html: html,
|
|
89
|
+
})];
|
|
90
|
+
case 2:
|
|
91
|
+
_e.sent();
|
|
92
|
+
return [2 /*return*/, {
|
|
93
|
+
data: { status: "success", passwordResetToken: resp.passwordResetToken },
|
|
94
|
+
}];
|
|
95
|
+
}
|
|
98
96
|
});
|
|
99
|
-
};
|
|
97
|
+
}); };
|
|
100
98
|
exports.default = postPasswordResetStartHandler;
|
|
101
99
|
exports.__assumedHttpMethod = "", exports.__file = "UserPasswordResetStart.ts", exports.__query = [], exports.__params = [];
|
|
102
100
|
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "username": { "type": "string" }, "template": { "type": "string" }, "additionalAuth": { "type": "string" } }, "required": ["username"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "userNotFound"] }, "passwordResetToken": { "type": "string" }, "profile": { "type": "object" } }, "required": ["status"], "definitions": {} } };
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -38,29 +38,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
|
|
40
40
|
var flink_1 = require("@flink-app/flink");
|
|
41
|
-
var getProfileHandler = function (_a) {
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
});
|
|
41
|
+
var getProfileHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
42
|
+
var pluginName, repo, userId, user;
|
|
43
|
+
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
44
|
+
return __generator(this, function (_c) {
|
|
45
|
+
switch (_c.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
pluginName = origin || "genericAuthPlugin";
|
|
48
|
+
repo = ctx.repos[ctx.plugins[pluginName].repoName];
|
|
49
|
+
userId = req.user._id;
|
|
50
|
+
return [4 /*yield*/, repo.getById(userId)];
|
|
51
|
+
case 1:
|
|
52
|
+
user = _c.sent();
|
|
53
|
+
if (user == null) {
|
|
54
|
+
return [2 /*return*/, (0, flink_1.notFound)()];
|
|
55
|
+
}
|
|
56
|
+
return [2 /*return*/, {
|
|
57
|
+
data: user.profile,
|
|
58
|
+
}];
|
|
59
|
+
}
|
|
62
60
|
});
|
|
63
|
-
};
|
|
61
|
+
}); };
|
|
64
62
|
exports.default = getProfileHandler;
|
|
65
63
|
exports.__assumedHttpMethod = "", exports.__file = "UserProfileGet.ts", exports.__query = [], exports.__params = [];
|
|
66
64
|
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": {}, "definitions": {} }, resSchema: undefined };
|
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
29
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
|
@@ -49,36 +49,34 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
|
|
51
51
|
var flink_1 = require("@flink-app/flink");
|
|
52
|
-
var putUserProfileHandler = function (_a) {
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
});
|
|
52
|
+
var putUserProfileHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
53
|
+
var pluginName, repo, userId, user, updatedProfile;
|
|
54
|
+
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
55
|
+
return __generator(this, function (_c) {
|
|
56
|
+
switch (_c.label) {
|
|
57
|
+
case 0:
|
|
58
|
+
pluginName = origin || "genericAuthPlugin";
|
|
59
|
+
repo = ctx.repos[ctx.plugins[pluginName].repoName];
|
|
60
|
+
userId = req.user._id;
|
|
61
|
+
return [4 /*yield*/, repo.getById(userId)];
|
|
62
|
+
case 1:
|
|
63
|
+
user = _c.sent();
|
|
64
|
+
if (user == null) {
|
|
65
|
+
return [2 /*return*/, (0, flink_1.notFound)()];
|
|
66
|
+
}
|
|
67
|
+
updatedProfile = __assign(__assign({}, user.profile), req.body);
|
|
68
|
+
return [4 /*yield*/, repo.updateOne(userId, { profile: updatedProfile })];
|
|
69
|
+
case 2:
|
|
70
|
+
_c.sent();
|
|
71
|
+
return [4 /*yield*/, repo.getById(userId)];
|
|
72
|
+
case 3:
|
|
73
|
+
user = _c.sent();
|
|
74
|
+
return [2 /*return*/, {
|
|
75
|
+
data: user.profile,
|
|
76
|
+
}];
|
|
77
|
+
}
|
|
80
78
|
});
|
|
81
|
-
};
|
|
79
|
+
}); };
|
|
82
80
|
exports.default = putUserProfileHandler;
|
|
83
81
|
exports.__assumedHttpMethod = "", exports.__file = "UserProfilePut.ts", exports.__query = [], exports.__params = [];
|
|
84
82
|
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": {}, "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": {}, "definitions": {} } };
|
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
29
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
|
@@ -49,79 +49,77 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
|
|
51
51
|
var flink_1 = require("@flink-app/flink");
|
|
52
|
-
var postUserPushRegisterTokenHandler = function (_a) {
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
});
|
|
52
|
+
var postUserPushRegisterTokenHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
53
|
+
var pluginName, pluginOptions, repo, deregisterOtherDevices, allowMultipleDevices, user, exToken, otherRegistrations, _i, otherRegistrations_1, other, lengthBefore, e_1;
|
|
54
|
+
var _c;
|
|
55
|
+
var ctx = _b.ctx, req = _b.req, origin = _b.origin;
|
|
56
|
+
return __generator(this, function (_d) {
|
|
57
|
+
switch (_d.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
pluginName = origin || "genericAuthPlugin";
|
|
60
|
+
pluginOptions = ctx.plugins[pluginName];
|
|
61
|
+
repo = ctx.repos[pluginOptions.repoName];
|
|
62
|
+
deregisterOtherDevices = pluginOptions.deregisterOtherDevices || false;
|
|
63
|
+
allowMultipleDevices = (_c = pluginOptions.allowMultipleDevices) !== null && _c !== void 0 ? _c : true;
|
|
64
|
+
return [4 /*yield*/, repo.getById(req.user._id)];
|
|
65
|
+
case 1:
|
|
66
|
+
user = _d.sent();
|
|
67
|
+
if (user == null) {
|
|
68
|
+
return [2 /*return*/, (0, flink_1.notFound)("User not found")];
|
|
69
|
+
}
|
|
70
|
+
exToken = user.pushNotificationTokens.find(function (t) { return t.deviceId == req.body.deviceId; });
|
|
71
|
+
if (exToken != null) {
|
|
72
|
+
exToken.token = req.body.token;
|
|
73
|
+
exToken.type = req.body.type || "firebase";
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
user.pushNotificationTokens.push(__assign(__assign({}, req.body), { type: req.body.type || "firebase" }));
|
|
77
|
+
}
|
|
78
|
+
if (!allowMultipleDevices) {
|
|
79
|
+
// Filter out all other devices except the newly registered one
|
|
80
|
+
user.pushNotificationTokens = user.pushNotificationTokens.filter(function (t) { return t.deviceId === req.body.deviceId; });
|
|
81
|
+
}
|
|
82
|
+
return [4 /*yield*/, repo.updateOne(user._id, {
|
|
83
|
+
pushNotificationTokens: user.pushNotificationTokens,
|
|
84
|
+
})];
|
|
85
|
+
case 2:
|
|
86
|
+
_d.sent();
|
|
87
|
+
if (!deregisterOtherDevices) return [3 /*break*/, 9];
|
|
88
|
+
return [4 /*yield*/, repo.findAll({
|
|
89
|
+
$or: [{ "pushNotificationTokens.deviceId": req.body.deviceId }, { "pushNotificationTokens.token": req.body.token }],
|
|
90
|
+
_id: { $ne: user._id },
|
|
91
|
+
})];
|
|
92
|
+
case 3:
|
|
93
|
+
otherRegistrations = _d.sent();
|
|
94
|
+
flink_1.log.debug("Found ".concat(otherRegistrations.length, " other registrations for device ").concat(req.body.deviceId, " or token ").concat(req.body.token));
|
|
95
|
+
_i = 0, otherRegistrations_1 = otherRegistrations;
|
|
96
|
+
_d.label = 4;
|
|
97
|
+
case 4:
|
|
98
|
+
if (!(_i < otherRegistrations_1.length)) return [3 /*break*/, 9];
|
|
99
|
+
other = otherRegistrations_1[_i];
|
|
100
|
+
_d.label = 5;
|
|
101
|
+
case 5:
|
|
102
|
+
_d.trys.push([5, 7, , 8]);
|
|
103
|
+
lengthBefore = other.pushNotificationTokens.length;
|
|
104
|
+
other.pushNotificationTokens = other.pushNotificationTokens.filter(function (t) { return t.deviceId !== req.body.deviceId && t.token !== req.body.token; });
|
|
105
|
+
flink_1.log.debug("Deregistering ".concat(lengthBefore - other.pushNotificationTokens.length, " devices for user ").concat(other._id, " as other user ").concat(user._id, " claimed this device"));
|
|
106
|
+
return [4 /*yield*/, repo.updateOne(other._id, {
|
|
107
|
+
pushNotificationTokens: other.pushNotificationTokens,
|
|
108
|
+
})];
|
|
109
|
+
case 6:
|
|
110
|
+
_d.sent();
|
|
111
|
+
return [3 /*break*/, 8];
|
|
112
|
+
case 7:
|
|
113
|
+
e_1 = _d.sent();
|
|
114
|
+
console.error("Error deregistering other devices", e_1);
|
|
115
|
+
return [3 /*break*/, 8];
|
|
116
|
+
case 8:
|
|
117
|
+
_i++;
|
|
118
|
+
return [3 /*break*/, 4];
|
|
119
|
+
case 9: return [2 /*return*/, { data: { status: "success" } }];
|
|
120
|
+
}
|
|
123
121
|
});
|
|
124
|
-
};
|
|
122
|
+
}); };
|
|
125
123
|
exports.default = postUserPushRegisterTokenHandler;
|
|
126
124
|
exports.__assumedHttpMethod = "", exports.__file = "UserPushRegisterToken.ts", exports.__query = [], exports.__params = [];
|
|
127
|
-
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "deviceId": { "type": "string" }, "token": { "type": "string" }, "platform": { "type": "string", "enum": ["ios", "android", "web"] }, "type": { "type": "string", "enum": ["firebase", "apn-voip"]
|
|
125
|
+
exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "deviceId": { "type": "string" }, "token": { "type": "string" }, "platform": { "type": "string", "enum": ["ios", "android", "web"] }, "type": { "type": "string", "enum": ["firebase", "apn-voip"] } }, "required": ["deviceId", "token"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "failed"] } }, "required": ["status"], "definitions": {} } };
|