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

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 Tue Feb 04 2025 11:59:42 GMT+0100 (Central European Standard Time)
1
+ // Generated Wed Feb 05 2025 22:45:07 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 Tue Feb 04 2025 11:59:43 GMT+0100 (Central European Standard Time)
1
+ // Generated Wed Feb 05 2025 22:45:08 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 Tue Feb 04 2025 11:59:42 GMT+0100 (Central European Standard Time)
1
+ // Generated Wed Feb 05 2025 22:45:07 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 Tue Feb 04 2025 11:59:43 GMT+0100 (Central European Standard Time)
32
+ // Generated Wed Feb 05 2025 22:45:09 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 Tue Feb 04 2025 11:59:43 GMT+0100 (Central European Standard Time)
1
+ // Generated Wed Feb 05 2025 22:45:08 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 Tue Feb 04 2025 11:59:42 GMT+0100 (Central European Standard Time)
4
+ // Generated Wed Feb 05 2025 22:45:07 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 Tue Feb 04 2025 11:59:43 GMT+0100 (Central European Standard Time)
4
+ // Generated Wed Feb 05 2025 22:45:08 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 Tue Feb 04 2025 11:59:42 GMT+0100 (Central European Standard Time)
4
+ // Generated Wed Feb 05 2025 22:45:07 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 Tue Feb 04 2025 11:59:43 GMT+0100 (Central European Standard Time)
3
+ // Generated Wed Feb 05 2025 22:45:08 GMT+0100 (Central European Standard Time)
4
4
  require("./generatedHandlers");
5
5
  require("./generatedRepos");
6
6
  require("./generatedJobs");
@@ -35,6 +35,11 @@ export interface GenericAuthPluginOptions {
35
35
  * deregistered.
36
36
  */
37
37
  deregisterOtherDevices?: boolean;
38
+ /**
39
+ * If true, multiple devices can be registered with the same `deviceId`.
40
+ * Default is `true`.
41
+ */
42
+ allowMultipleDevices?: boolean;
38
43
  }
39
44
  export interface GenericAuthsmsOptions {
40
45
  smsClient: smsClient;
@@ -41,17 +41,19 @@ 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, user, exToken, otherRegistrations, _i, otherRegistrations_1, other, e_1;
45
- return __generator(this, function (_b) {
46
- switch (_b.label) {
44
+ var pluginName, pluginOptions, repo, deregisterOtherDevices, allowMultipleDevices, user, exToken, otherRegistrations, _i, otherRegistrations_1, other, e_1;
45
+ var _b;
46
+ return __generator(this, function (_c) {
47
+ switch (_c.label) {
47
48
  case 0:
48
49
  pluginName = origin || "genericAuthPlugin";
49
50
  pluginOptions = ctx.plugins[pluginName];
50
51
  repo = ctx.repos[pluginOptions.repoName];
51
52
  deregisterOtherDevices = pluginOptions.deregisterOtherDevices || false;
53
+ allowMultipleDevices = (_b = pluginOptions.allowMultipleDevices) !== null && _b !== void 0 ? _b : true;
52
54
  return [4 /*yield*/, repo.getById(req.user._id)];
53
55
  case 1:
54
- user = _b.sent();
56
+ user = _c.sent();
55
57
  if (user == null) {
56
58
  return [2 /*return*/, flink_1.notFound("User not found")];
57
59
  }
@@ -62,35 +64,39 @@ var postUserPushRegisterTokenHandler = function (_a) {
62
64
  else {
63
65
  user.pushNotificationTokens.push(req.body);
64
66
  }
67
+ if (!allowMultipleDevices) {
68
+ // Filter out all other devices except the newly registered one
69
+ user.pushNotificationTokens = user.pushNotificationTokens.filter(function (t) { return t.deviceId === req.body.deviceId; });
70
+ }
65
71
  return [4 /*yield*/, repo.updateOne(user._id, {
66
72
  pushNotificationTokens: user.pushNotificationTokens,
67
73
  })];
68
74
  case 2:
69
- _b.sent();
75
+ _c.sent();
70
76
  if (!deregisterOtherDevices) return [3 /*break*/, 9];
71
77
  return [4 /*yield*/, repo.findAll({
72
78
  $or: [{ "pushNotificationTokens.deviceId": req.body.deviceId }, { "pushNotificationTokens.token": req.body.token }],
73
79
  _id: { $ne: user._id },
74
80
  })];
75
81
  case 3:
76
- otherRegistrations = _b.sent();
82
+ otherRegistrations = _c.sent();
77
83
  _i = 0, otherRegistrations_1 = otherRegistrations;
78
- _b.label = 4;
84
+ _c.label = 4;
79
85
  case 4:
80
86
  if (!(_i < otherRegistrations_1.length)) return [3 /*break*/, 9];
81
87
  other = otherRegistrations_1[_i];
82
- _b.label = 5;
88
+ _c.label = 5;
83
89
  case 5:
84
- _b.trys.push([5, 7, , 8]);
90
+ _c.trys.push([5, 7, , 8]);
85
91
  other.pushNotificationTokens = other.pushNotificationTokens.filter(function (t) { return t.deviceId !== req.body.deviceId && t.token !== req.body.token; });
86
92
  return [4 /*yield*/, repo.updateOne(other._id, {
87
93
  pushNotificationTokens: other.pushNotificationTokens,
88
94
  })];
89
95
  case 6:
90
- _b.sent();
96
+ _c.sent();
91
97
  return [3 /*break*/, 8];
92
98
  case 7:
93
- e_1 = _b.sent();
99
+ e_1 = _c.sent();
94
100
  console.error("Error deregistering other devices", e_1);
95
101
  return [3 /*break*/, 8];
96
102
  case 8:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/generic-auth-plugin",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
4
4
  "description": "Flink plugin that provides a generic user authentification solution.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\"",
@@ -16,19 +16,19 @@
16
16
  "types": "dist/src/index.d.ts",
17
17
  "main": "dist/src/index.js",
18
18
  "dependencies": {
19
- "@flink-app/email-plugin": "^0.11.5",
20
- "@flink-app/jwt-auth-plugin": "^0.11.5",
21
- "@flink-app/management-api-plugin": "^0.11.5",
22
- "@flink-app/sms-plugin": "^0.11.5",
19
+ "@flink-app/email-plugin": "^0.11.9",
20
+ "@flink-app/jwt-auth-plugin": "^0.11.9",
21
+ "@flink-app/management-api-plugin": "^0.11.9",
22
+ "@flink-app/sms-plugin": "^0.11.9",
23
23
  "handlebars": "^4.7.7",
24
24
  "jsonwebtoken": "^8.5.1"
25
25
  },
26
26
  "devDependencies": {
27
- "@flink-app/flink": "^0.11.5",
27
+ "@flink-app/flink": "^0.11.9",
28
28
  "@types/jsonwebtoken": "^8.5.2",
29
29
  "@types/node": "^15.6.2",
30
30
  "ts-node": "^9.1.1",
31
31
  "typescript": "^4.2.4"
32
32
  },
33
- "gitHead": "8df87dd973d5d16d21967ac8269c952a0577446e"
33
+ "gitHead": "cc04e10ae82ed022031ef8bcfaafa9beb1d6564f"
34
34
  }
@@ -32,6 +32,12 @@ export interface GenericAuthPluginOptions {
32
32
  * deregistered.
33
33
  */
34
34
  deregisterOtherDevices?: boolean;
35
+
36
+ /**
37
+ * If true, multiple devices can be registered with the same `deviceId`.
38
+ * Default is `true`.
39
+ */
40
+ allowMultipleDevices?: boolean;
35
41
  }
36
42
 
37
43
  export interface GenericAuthsmsOptions {
@@ -14,6 +14,7 @@ const postUserPushRegisterTokenHandler: Handler<FlinkContext<genericAuthContext>
14
14
  const pluginOptions: GenericAuthPluginOptions = (ctx.plugins as any)[pluginName];
15
15
  const repo = ctx.repos[pluginOptions.repoName];
16
16
  const deregisterOtherDevices = pluginOptions.deregisterOtherDevices || false;
17
+ const allowMultipleDevices = pluginOptions.allowMultipleDevices ?? true;
17
18
 
18
19
  const user = <User>await repo.getById(req.user._id);
19
20
 
@@ -29,6 +30,11 @@ const postUserPushRegisterTokenHandler: Handler<FlinkContext<genericAuthContext>
29
30
  user.pushNotificationTokens.push(req.body);
30
31
  }
31
32
 
33
+ if (!allowMultipleDevices) {
34
+ // Filter out all other devices except the newly registered one
35
+ user.pushNotificationTokens = user.pushNotificationTokens.filter((t) => t.deviceId === req.body.deviceId);
36
+ }
37
+
32
38
  await repo.updateOne(user._id, {
33
39
  pushNotificationTokens: user.pushNotificationTokens,
34
40
  });