@flink-app/generic-auth-plugin 0.11.9 → 0.11.10

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.
@@ -1,4 +1,4 @@
1
- // Generated Wed Feb 05 2025 22:45:07 GMT+0100 (Central European Standard Time)
1
+ // Generated Wed Feb 05 2025 23:31:38 GMT+0100 (Central European Standard Time)
2
2
  import { autoRegisteredHandlers, HttpMethod } from "@flink-app/flink";
3
3
  import * as UserCreate_0 from "../src/handlers/UserCreate";
4
4
  import * as UserLogin_0 from "../src/handlers/UserLogin";
@@ -1,4 +1,4 @@
1
- // Generated Wed Feb 05 2025 22:45:08 GMT+0100 (Central European Standard Time)
1
+ // Generated Wed Feb 05 2025 23:31:38 GMT+0100 (Central European Standard Time)
2
2
  import { autoRegisteredJobs } from "@flink-app/flink";
3
3
  export const jobs = [];
4
4
  autoRegisteredJobs.push(...jobs);
@@ -1,4 +1,4 @@
1
- // Generated Wed Feb 05 2025 22:45:07 GMT+0100 (Central European Standard Time)
1
+ // Generated Wed Feb 05 2025 23:31:38 GMT+0100 (Central European Standard Time)
2
2
  import { autoRegisteredRepos } from "@flink-app/flink";
3
3
  export const repos = [];
4
4
  autoRegisteredRepos.push(...repos);
@@ -29,7 +29,7 @@ import { PutManagementUserRolesByUseridRes } from "../../src/schemas/Management/
29
29
  import { PutManagementUserUsernameByUseridReq } from "../../src/schemas/Management/PutUserUsernameByUseridReq";
30
30
  import { PutManagementUserUsernameByUseridRes } from "../../src/schemas/Management/PutUserUsernameByUseridRes";
31
31
 
32
- // Generated Wed Feb 05 2025 22:45:09 GMT+0100 (Central European Standard Time)
32
+ // Generated Wed Feb 05 2025 23:31:39 GMT+0100 (Central European Standard Time)
33
33
  export interface UserCreate_7_ReqSchema extends UserCreateReq {}
34
34
 
35
35
  export interface UserCreate_7_ResSchema extends UserCreateRes {}
package/.flink/start.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Generated Wed Feb 05 2025 22:45:08 GMT+0100 (Central European Standard Time)
1
+ // Generated Wed Feb 05 2025 23:31:38 GMT+0100 (Central European Standard Time)
2
2
  import "./generatedHandlers";
3
3
  import "./generatedRepos";
4
4
  import "./generatedJobs";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlers = void 0;
4
- // Generated Wed Feb 05 2025 22:45:07 GMT+0100 (Central European Standard Time)
4
+ // Generated Wed Feb 05 2025 23:31:38 GMT+0100 (Central European Standard Time)
5
5
  var flink_1 = require("@flink-app/flink");
6
6
  exports.handlers = [];
7
7
  flink_1.autoRegisteredHandlers.push.apply(flink_1.autoRegisteredHandlers, exports.handlers);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jobs = void 0;
4
- // Generated Wed Feb 05 2025 22:45:08 GMT+0100 (Central European Standard Time)
4
+ // Generated Wed Feb 05 2025 23:31:38 GMT+0100 (Central European Standard Time)
5
5
  var flink_1 = require("@flink-app/flink");
6
6
  exports.jobs = [];
7
7
  flink_1.autoRegisteredJobs.push.apply(flink_1.autoRegisteredJobs, exports.jobs);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.repos = void 0;
4
- // Generated Wed Feb 05 2025 22:45:07 GMT+0100 (Central European Standard Time)
4
+ // Generated Wed Feb 05 2025 23:31:38 GMT+0100 (Central European Standard Time)
5
5
  var flink_1 = require("@flink-app/flink");
6
6
  exports.repos = [];
7
7
  flink_1.autoRegisteredRepos.push.apply(flink_1.autoRegisteredRepos, exports.repos);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Generated Wed Feb 05 2025 22:45:08 GMT+0100 (Central European Standard Time)
3
+ // Generated Wed Feb 05 2025 23:31:38 GMT+0100 (Central European Standard Time)
4
4
  require("./generatedHandlers");
5
5
  require("./generatedRepos");
6
6
  require("./generatedJobs");
@@ -41,7 +41,7 @@ var flink_1 = require("@flink-app/flink");
41
41
  var postUserPushRegisterTokenHandler = function (_a) {
42
42
  var ctx = _a.ctx, req = _a.req, origin = _a.origin;
43
43
  return __awaiter(void 0, void 0, void 0, function () {
44
- var pluginName, pluginOptions, repo, deregisterOtherDevices, allowMultipleDevices, user, exToken, otherRegistrations, _i, otherRegistrations_1, other, e_1;
44
+ var pluginName, pluginOptions, repo, deregisterOtherDevices, allowMultipleDevices, user, exToken, otherRegistrations, _i, otherRegistrations_1, other, lengthBefore, e_1;
45
45
  var _b;
46
46
  return __generator(this, function (_c) {
47
47
  switch (_c.label) {
@@ -80,6 +80,7 @@ var postUserPushRegisterTokenHandler = function (_a) {
80
80
  })];
81
81
  case 3:
82
82
  otherRegistrations = _c.sent();
83
+ flink_1.log.debug("Found " + otherRegistrations.length + " other registrations for device " + req.body.deviceId + " or token " + req.body.token);
83
84
  _i = 0, otherRegistrations_1 = otherRegistrations;
84
85
  _c.label = 4;
85
86
  case 4:
@@ -88,7 +89,9 @@ var postUserPushRegisterTokenHandler = function (_a) {
88
89
  _c.label = 5;
89
90
  case 5:
90
91
  _c.trys.push([5, 7, , 8]);
92
+ lengthBefore = other.pushNotificationTokens.length;
91
93
  other.pushNotificationTokens = other.pushNotificationTokens.filter(function (t) { return t.deviceId !== req.body.deviceId && t.token !== req.body.token; });
94
+ flink_1.log.debug("Deregistering " + (lengthBefore - other.pushNotificationTokens.length) + " devices for user " + other._id + " as other user " + user._id + " claimed this device");
92
95
  return [4 /*yield*/, repo.updateOne(other._id, {
93
96
  pushNotificationTokens: other.pushNotificationTokens,
94
97
  })];
package/dist/src/index.js CHANGED
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
@@ -9,6 +20,17 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
9
20
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
21
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
22
  };
23
+ var __rest = (this && this.__rest) || function (s, e) {
24
+ var t = {};
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
26
+ t[p] = s[p];
27
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
28
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
29
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
30
+ t[p[i]] = s[p[i]];
31
+ }
32
+ return t;
33
+ };
12
34
  Object.defineProperty(exports, "__esModule", { value: true });
13
35
  exports.genericAuthPlugin = void 0;
14
36
  var coreFunctions_1 = require("./coreFunctions");
@@ -21,24 +43,16 @@ __exportStar(require("./management"), exports);
21
43
  var genericAuthPlugin = function (options) {
22
44
  if (options.pluginId == null)
23
45
  options.pluginId = "genericAuthPlugin";
46
+ var sms = options.sms, usernameFormat = options.usernameFormat, restOptions = __rest(options, ["sms", "usernameFormat"]);
24
47
  return {
25
48
  id: options.pluginId,
26
49
  init: function (app) { return init_1.init(app, options); },
27
- ctx: {
28
- loginUser: coreFunctions_1.loginUser,
50
+ ctx: __assign(__assign({}, restOptions), { loginUser: coreFunctions_1.loginUser,
29
51
  loginByToken: coreFunctions_1.loginByToken,
30
52
  createUser: coreFunctions_1.createUser,
31
53
  changePassword: coreFunctions_1.changePassword,
32
54
  passwordResetStart: coreFunctions_1.passwordResetStart,
33
- passwordResetComplete: coreFunctions_1.passwordResetComplete,
34
- repoName: options.repoName,
35
- passwordResetSettings: options.passwordResetSettings,
36
- createPasswordHashAndSaltMethod: options.createPasswordHashAndSaltMethod,
37
- validatePasswordMethod: options.validatePasswordMethod,
38
- usernameFormat: options.usernameFormat || /.{1,}$/,
39
- onSuccessfulLogin: options.onSuccessfulLogin,
40
- smsOptions: options.sms
41
- },
55
+ passwordResetComplete: coreFunctions_1.passwordResetComplete, usernameFormat: usernameFormat || /.{1,}$/, smsOptions: sms }),
42
56
  };
43
57
  };
44
58
  exports.genericAuthPlugin = genericAuthPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/generic-auth-plugin",
3
- "version": "0.11.9",
3
+ "version": "0.11.10",
4
4
  "description": "Flink plugin that provides a generic user authentification solution.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\"",
@@ -30,5 +30,5 @@
30
30
  "ts-node": "^9.1.1",
31
31
  "typescript": "^4.2.4"
32
32
  },
33
- "gitHead": "cc04e10ae82ed022031ef8bcfaafa9beb1d6564f"
33
+ "gitHead": "bda7469d8216f4f2efcec25ec2b2a25b2c235180"
34
34
  }
@@ -1,4 +1,4 @@
1
- import { FlinkContext, Handler, notFound } from "@flink-app/flink";
1
+ import { FlinkContext, Handler, log, notFound } from "@flink-app/flink";
2
2
  import { genericAuthContext } from "../genericAuthContext";
3
3
  import { PushNotificationToken } from "../schemas/PushNotificationToken";
4
4
  import { PushNotificatioNTokenRes } from "../schemas/PushNotificationTokenRes";
@@ -45,9 +45,20 @@ const postUserPushRegisterTokenHandler: Handler<FlinkContext<genericAuthContext>
45
45
  _id: { $ne: user._id },
46
46
  });
47
47
 
48
+ log.debug(`Found ${otherRegistrations.length} other registrations for device ${req.body.deviceId} or token ${req.body.token}`);
49
+
48
50
  for (let other of otherRegistrations) {
49
51
  try {
52
+ let lengthBefore = other.pushNotificationTokens.length;
53
+
50
54
  other.pushNotificationTokens = other.pushNotificationTokens.filter((t) => t.deviceId !== req.body.deviceId && t.token !== req.body.token);
55
+
56
+ log.debug(
57
+ `Deregistering ${lengthBefore - other.pushNotificationTokens.length} devices for user ${other._id} as other user ${
58
+ user._id
59
+ } claimed this device`
60
+ );
61
+
51
62
  await repo.updateOne(other._id, {
52
63
  pushNotificationTokens: other.pushNotificationTokens,
53
64
  });
package/src/index.ts CHANGED
@@ -1,12 +1,5 @@
1
1
  import { FlinkPlugin } from "@flink-app/flink";
2
- import {
3
- loginUser,
4
- createUser,
5
- changePassword,
6
- passwordResetComplete,
7
- passwordResetStart,
8
- loginByToken
9
- } from "./coreFunctions";
2
+ import { loginUser, createUser, changePassword, passwordResetComplete, passwordResetStart, loginByToken } from "./coreFunctions";
10
3
  import { init } from "./init";
11
4
  import { GenericAuthPluginOptions } from "./genericAuthPluginOptions";
12
5
 
@@ -16,27 +9,24 @@ export * from "./schemas/User";
16
9
  export * from "./genericAuthPluginOptions";
17
10
  export * from "./management";
18
11
 
19
- export const genericAuthPlugin = (
20
- options: GenericAuthPluginOptions
21
- ): FlinkPlugin => {
22
- if (options.pluginId == null) options.pluginId = "genericAuthPlugin";
23
- return {
24
- id: options.pluginId,
25
- init: (app) => init(app, options),
26
- ctx: {
27
- loginUser,
28
- loginByToken,
29
- createUser,
30
- changePassword,
31
- passwordResetStart,
32
- passwordResetComplete,
33
- repoName: options.repoName,
34
- passwordResetSettings: options.passwordResetSettings,
35
- createPasswordHashAndSaltMethod: options.createPasswordHashAndSaltMethod,
36
- validatePasswordMethod: options.validatePasswordMethod,
37
- usernameFormat: options.usernameFormat || /.{1,}$/,
38
- onSuccessfulLogin: options.onSuccessfulLogin,
39
- smsOptions : options.sms
40
- },
41
- };
12
+ export const genericAuthPlugin = (options: GenericAuthPluginOptions): FlinkPlugin => {
13
+ if (options.pluginId == null) options.pluginId = "genericAuthPlugin";
14
+
15
+ const { sms, usernameFormat, ...restOptions } = options;
16
+
17
+ return {
18
+ id: options.pluginId,
19
+ init: (app) => init(app, options),
20
+ ctx: {
21
+ ...restOptions,
22
+ loginUser,
23
+ loginByToken,
24
+ createUser,
25
+ changePassword,
26
+ passwordResetStart,
27
+ passwordResetComplete,
28
+ usernameFormat: usernameFormat || /.{1,}$/,
29
+ smsOptions: sms,
30
+ },
31
+ };
42
32
  };