@webda/core 2.0.0-beta.2 → 2.0.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.
Files changed (279) hide show
  1. package/lib/application.d.ts +5 -21
  2. package/lib/application.js +71 -84
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +121 -140
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +44 -45
  7. package/lib/core.js +239 -320
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +326 -391
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/index.d.ts +49 -45
  12. package/lib/index.js +54 -67
  13. package/lib/index.js.map +1 -1
  14. package/lib/models/aclmodel.d.ts +2 -2
  15. package/lib/models/aclmodel.js +63 -90
  16. package/lib/models/aclmodel.js.map +1 -1
  17. package/lib/models/aclmodel.spec.js +128 -151
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +39 -17
  20. package/lib/models/coremodel.js +160 -117
  21. package/lib/models/coremodel.js.map +1 -1
  22. package/lib/models/coremodel.spec.js +143 -107
  23. package/lib/models/coremodel.spec.js.map +1 -1
  24. package/lib/models/deployment.js +1 -2
  25. package/lib/models/ident.d.ts +3 -3
  26. package/lib/models/ident.js +4 -9
  27. package/lib/models/ident.js.map +1 -1
  28. package/lib/models/ident.spec.js +9 -11
  29. package/lib/models/ident.spec.js.map +1 -1
  30. package/lib/models/ownermodel.d.ts +2 -2
  31. package/lib/models/ownermodel.js +39 -62
  32. package/lib/models/ownermodel.js.map +1 -1
  33. package/lib/models/ownermodel.spec.js +126 -166
  34. package/lib/models/ownermodel.spec.js.map +1 -1
  35. package/lib/models/rolemodel.d.ts +2 -2
  36. package/lib/models/rolemodel.js +24 -40
  37. package/lib/models/rolemodel.js.map +1 -1
  38. package/lib/models/rolemodel.spec.js +44 -61
  39. package/lib/models/rolemodel.spec.js.map +1 -1
  40. package/lib/models/user.d.ts +9 -9
  41. package/lib/models/user.js +3 -8
  42. package/lib/models/user.js.map +1 -1
  43. package/lib/models/user.spec.js +14 -16
  44. package/lib/models/user.spec.js.map +1 -1
  45. package/lib/queues/filequeue.d.ts +2 -2
  46. package/lib/queues/filequeue.js +72 -93
  47. package/lib/queues/filequeue.js.map +1 -1
  48. package/lib/queues/filequeue.spec.js +53 -70
  49. package/lib/queues/filequeue.spec.js.map +1 -1
  50. package/lib/queues/memoryqueue.d.ts +2 -2
  51. package/lib/queues/memoryqueue.js +37 -61
  52. package/lib/queues/memoryqueue.js.map +1 -1
  53. package/lib/queues/memoryqueue.spec.js +142 -165
  54. package/lib/queues/memoryqueue.spec.js.map +1 -1
  55. package/lib/queues/pubsubservice.d.ts +2 -2
  56. package/lib/queues/pubsubservice.js +3 -7
  57. package/lib/queues/pubsubservice.js.map +1 -1
  58. package/lib/queues/queue.spec.d.ts +1 -1
  59. package/lib/queues/queue.spec.js +42 -56
  60. package/lib/queues/queue.spec.js.map +1 -1
  61. package/lib/queues/queueservice.d.ts +4 -4
  62. package/lib/queues/queueservice.js +52 -67
  63. package/lib/queues/queueservice.js.map +1 -1
  64. package/lib/router.d.ts +3 -3
  65. package/lib/router.js +46 -47
  66. package/lib/router.js.map +1 -1
  67. package/lib/router.spec.js +64 -61
  68. package/lib/router.spec.js.map +1 -1
  69. package/lib/services/asyncevents.d.ts +2 -2
  70. package/lib/services/asyncevents.js +44 -64
  71. package/lib/services/asyncevents.js.map +1 -1
  72. package/lib/services/asyncevents.spec.js +81 -98
  73. package/lib/services/asyncevents.spec.js.map +1 -1
  74. package/lib/services/authentication.d.ts +28 -19
  75. package/lib/services/authentication.js +542 -574
  76. package/lib/services/authentication.js.map +1 -1
  77. package/lib/services/authentication.spec.js +411 -447
  78. package/lib/services/authentication.spec.js.map +1 -1
  79. package/lib/services/binary.d.ts +9 -7
  80. package/lib/services/binary.js +213 -245
  81. package/lib/services/binary.js.map +1 -1
  82. package/lib/services/binary.spec.d.ts +3 -3
  83. package/lib/services/binary.spec.js +390 -443
  84. package/lib/services/binary.spec.js.map +1 -1
  85. package/lib/services/cloudbinary.d.ts +3 -3
  86. package/lib/services/cloudbinary.js +45 -70
  87. package/lib/services/cloudbinary.js.map +1 -1
  88. package/lib/services/cloudbinary.spec.d.ts +3 -3
  89. package/lib/services/cloudbinary.spec.js +133 -162
  90. package/lib/services/cloudbinary.spec.js.map +1 -1
  91. package/lib/services/configuration.d.ts +6 -3
  92. package/lib/services/configuration.js +78 -103
  93. package/lib/services/configuration.js.map +1 -1
  94. package/lib/services/configuration.spec.js +63 -83
  95. package/lib/services/configuration.spec.js.map +1 -1
  96. package/lib/services/cron.d.ts +3 -2
  97. package/lib/services/cron.js +9 -13
  98. package/lib/services/cron.js.map +1 -1
  99. package/lib/services/cron.spec.js +18 -21
  100. package/lib/services/cron.spec.js.map +1 -1
  101. package/lib/services/cryptoservice.d.ts +258 -0
  102. package/lib/services/cryptoservice.js +312 -0
  103. package/lib/services/cryptoservice.js.map +1 -0
  104. package/lib/services/cryptoservice.spec.d.ts +1 -0
  105. package/lib/services/cryptoservice.spec.js +137 -0
  106. package/lib/services/cryptoservice.spec.js.map +1 -0
  107. package/lib/services/debugmailer.d.ts +1 -1
  108. package/lib/services/debugmailer.js +13 -34
  109. package/lib/services/debugmailer.js.map +1 -1
  110. package/lib/services/debugmailer.spec.js +16 -29
  111. package/lib/services/debugmailer.spec.js.map +1 -1
  112. package/lib/services/echo.d.ts +2 -2
  113. package/lib/services/echo.js +15 -31
  114. package/lib/services/echo.js.map +1 -1
  115. package/lib/services/echo.spec.js +27 -40
  116. package/lib/services/echo.spec.js.map +1 -1
  117. package/lib/services/filebinary.d.ts +10 -5
  118. package/lib/services/filebinary.js +171 -205
  119. package/lib/services/filebinary.js.map +1 -1
  120. package/lib/services/filebinary.spec.d.ts +2 -1
  121. package/lib/services/filebinary.spec.js +106 -117
  122. package/lib/services/filebinary.spec.js.map +1 -1
  123. package/lib/services/fileconfiguration.d.ts +2 -2
  124. package/lib/services/fileconfiguration.js +25 -43
  125. package/lib/services/fileconfiguration.js.map +1 -1
  126. package/lib/services/fileconfiguration.spec.js +79 -109
  127. package/lib/services/fileconfiguration.spec.js.map +1 -1
  128. package/lib/services/invitationservice.d.ts +10 -10
  129. package/lib/services/invitationservice.js +275 -313
  130. package/lib/services/invitationservice.js.map +1 -1
  131. package/lib/services/invitationservice.spec.js +443 -449
  132. package/lib/services/invitationservice.spec.js.map +1 -1
  133. package/lib/services/kubernetesconfiguration.d.ts +2 -2
  134. package/lib/services/kubernetesconfiguration.js +41 -59
  135. package/lib/services/kubernetesconfiguration.js.map +1 -1
  136. package/lib/services/kubernetesconfiguration.spec.js +80 -98
  137. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  138. package/lib/services/mailer.d.ts +4 -4
  139. package/lib/services/mailer.js +62 -86
  140. package/lib/services/mailer.js.map +1 -1
  141. package/lib/services/mailer.spec.js +86 -127
  142. package/lib/services/mailer.spec.js.map +1 -1
  143. package/lib/services/notificationservice.d.ts +4 -4
  144. package/lib/services/notificationservice.js +23 -42
  145. package/lib/services/notificationservice.js.map +1 -1
  146. package/lib/services/notificationservice.spec.js +47 -73
  147. package/lib/services/notificationservice.spec.js.map +1 -1
  148. package/lib/services/oauth.d.ts +32 -6
  149. package/lib/services/oauth.js +73 -78
  150. package/lib/services/oauth.js.map +1 -1
  151. package/lib/services/oauth.spec.js +128 -148
  152. package/lib/services/oauth.spec.js.map +1 -1
  153. package/lib/services/proxy.d.ts +74 -0
  154. package/lib/services/proxy.js +126 -0
  155. package/lib/services/proxy.js.map +1 -0
  156. package/lib/services/proxy.spec.d.ts +1 -0
  157. package/lib/services/proxy.spec.js +59 -0
  158. package/lib/services/proxy.spec.js.map +1 -0
  159. package/lib/services/resource.d.ts +2 -2
  160. package/lib/services/resource.js +12 -18
  161. package/lib/services/resource.js.map +1 -1
  162. package/lib/services/resource.spec.js +67 -99
  163. package/lib/services/resource.spec.js.map +1 -1
  164. package/lib/services/service.d.ts +29 -6
  165. package/lib/services/service.js +69 -39
  166. package/lib/services/service.js.map +1 -1
  167. package/lib/services/service.spec.js +62 -67
  168. package/lib/services/service.spec.js.map +1 -1
  169. package/lib/services/version.d.ts +1 -1
  170. package/lib/services/version.js +3 -8
  171. package/lib/services/version.js.map +1 -1
  172. package/lib/services/version.spec.js +11 -24
  173. package/lib/services/version.spec.js.map +1 -1
  174. package/lib/stores/aggregator.d.ts +3 -3
  175. package/lib/stores/aggregator.js +37 -57
  176. package/lib/stores/aggregator.js.map +1 -1
  177. package/lib/stores/file.d.ts +3 -3
  178. package/lib/stores/file.js +93 -131
  179. package/lib/stores/file.js.map +1 -1
  180. package/lib/stores/file.spec.d.ts +2 -2
  181. package/lib/stores/file.spec.js +262 -289
  182. package/lib/stores/file.spec.js.map +1 -1
  183. package/lib/stores/mapper.d.ts +4 -4
  184. package/lib/stores/mapper.js +111 -137
  185. package/lib/stores/mapper.js.map +1 -1
  186. package/lib/stores/mapper.spec.js +133 -150
  187. package/lib/stores/mapper.spec.js.map +1 -1
  188. package/lib/stores/memory.d.ts +67 -6
  189. package/lib/stores/memory.js +155 -117
  190. package/lib/stores/memory.js.map +1 -1
  191. package/lib/stores/memory.spec.d.ts +3 -2
  192. package/lib/stores/memory.spec.js +127 -105
  193. package/lib/stores/memory.spec.js.map +1 -1
  194. package/lib/stores/store.d.ts +40 -16
  195. package/lib/stores/store.js +847 -830
  196. package/lib/stores/store.js.map +1 -1
  197. package/lib/stores/store.spec.d.ts +6 -4
  198. package/lib/stores/store.spec.js +628 -647
  199. package/lib/stores/store.spec.js.map +1 -1
  200. package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
  201. package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
  202. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
  203. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
  204. package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
  205. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
  206. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
  207. package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
  208. package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
  209. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
  210. package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
  211. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
  212. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
  213. package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
  214. package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
  215. package/lib/stores/webdaql/query.d.ts +4 -5
  216. package/lib/stores/webdaql/query.js +16 -19
  217. package/lib/stores/webdaql/query.js.map +1 -1
  218. package/lib/stores/webdaql/query.spec.js +30 -32
  219. package/lib/stores/webdaql/query.spec.js.map +1 -1
  220. package/lib/test.d.ts +3 -3
  221. package/lib/test.js +74 -94
  222. package/lib/test.js.map +1 -1
  223. package/lib/unpackedapplication.d.ts +1 -1
  224. package/lib/unpackedapplication.js +44 -38
  225. package/lib/unpackedapplication.js.map +1 -1
  226. package/lib/utils/abstractdeployer.js +1 -5
  227. package/lib/utils/abstractdeployer.js.map +1 -1
  228. package/lib/utils/abstractdeployer.spec.js +6 -8
  229. package/lib/utils/abstractdeployer.spec.js.map +1 -1
  230. package/lib/utils/context.d.ts +61 -29
  231. package/lib/utils/context.js +133 -127
  232. package/lib/utils/context.js.map +1 -1
  233. package/lib/utils/context.spec.js +144 -153
  234. package/lib/utils/context.spec.js.map +1 -1
  235. package/lib/utils/cookie.d.ts +66 -45
  236. package/lib/utils/cookie.js +69 -158
  237. package/lib/utils/cookie.js.map +1 -1
  238. package/lib/utils/cookie.spec.js +220 -238
  239. package/lib/utils/cookie.spec.js.map +1 -1
  240. package/lib/utils/esm.d.ts +4 -0
  241. package/lib/utils/esm.js +10 -0
  242. package/lib/utils/esm.js.map +1 -0
  243. package/lib/utils/httpcontext.d.ts +3 -0
  244. package/lib/utils/httpcontext.js +48 -65
  245. package/lib/utils/httpcontext.js.map +1 -1
  246. package/lib/utils/httpcontext.spec.js +37 -56
  247. package/lib/utils/httpcontext.spec.js.map +1 -1
  248. package/lib/utils/logger.d.ts +2 -2
  249. package/lib/utils/logger.js +15 -28
  250. package/lib/utils/logger.js.map +1 -1
  251. package/lib/utils/logger.spec.js +9 -11
  252. package/lib/utils/logger.spec.js.map +1 -1
  253. package/lib/utils/serializers.js +17 -20
  254. package/lib/utils/serializers.js.map +1 -1
  255. package/lib/utils/serializers.spec.js +43 -44
  256. package/lib/utils/serializers.spec.js.map +1 -1
  257. package/lib/utils/session.d.ts +120 -0
  258. package/lib/utils/session.js +155 -0
  259. package/lib/utils/session.js.map +1 -0
  260. package/lib/utils/session.spec.d.ts +1 -0
  261. package/lib/utils/session.spec.js +66 -0
  262. package/lib/utils/session.spec.js.map +1 -0
  263. package/lib/utils/waiter.d.ts +1 -1
  264. package/lib/utils/waiter.js +32 -52
  265. package/lib/utils/waiter.js.map +1 -1
  266. package/lib/utils/waiter.spec.js +75 -92
  267. package/lib/utils/waiter.spec.js.map +1 -1
  268. package/package.json +22 -14
  269. package/test/config-invitation.json +1 -3
  270. package/test/config.json +3 -3
  271. package/test/config.old.json +1 -2
  272. package/test/moddas/annotatedservice.js +5 -5
  273. package/test/moddas/debugmailer.js +2 -3
  274. package/test/moddas/fakeservice.js +2 -3
  275. package/test/moddas/voidstore.js +6 -4
  276. package/test/models/ident.js +2 -6
  277. package/test/models/task.js +3 -7
  278. package/test/package.json +2 -1
  279. package/webda.module.json +895 -189
@@ -1,40 +1,27 @@
1
- "use strict";
2
1
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
6
  };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.InvitationParameters = void 0;
19
- const index_1 = require("../index");
20
- const service_1 = require("./service");
7
+ import { Ident } from "../index.js";
8
+ import { Inject, Service, ServiceParameters } from "./service.js";
21
9
  /**
22
10
  *
23
11
  */
24
- class InvitationParameters extends service_1.ServiceParameters {
12
+ export class InvitationParameters extends ServiceParameters {
25
13
  constructor(params) {
26
- var _a, _b, _c, _d;
27
14
  super(params);
28
- (_a = this.authenticationService) !== null && _a !== void 0 ? _a : (this.authenticationService = "Authentication");
15
+ this.authenticationService ?? (this.authenticationService = "Authentication");
29
16
  if (typeof this.mapFields === "string") {
30
17
  this.mapFields = this.mapFields.split(",");
31
18
  }
32
- (_b = this.mapFields) !== null && _b !== void 0 ? _b : (this.mapFields = []);
33
- (_c = this.multiple) !== null && _c !== void 0 ? _c : (this.multiple = true);
19
+ this.mapFields ?? (this.mapFields = []);
20
+ this.multiple ?? (this.multiple = true);
34
21
  if (!this.attribute.startsWith("_")) {
35
22
  throw new Error(`Attribute '${this.attribute}' needs to start with a _ to be only modified by server`);
36
23
  }
37
- (_d = this.pendingAttribute) !== null && _d !== void 0 ? _d : (this.pendingAttribute = `${this.attribute}Pending`);
24
+ this.pendingAttribute ?? (this.pendingAttribute = `${this.attribute}Pending`);
38
25
  if (!this.pendingAttribute.startsWith("_")) {
39
26
  throw new Error(`Attribute '${this.pendingAttribute}' needs to start with a _ to be only modified by server`);
40
27
  }
@@ -43,7 +30,6 @@ class InvitationParameters extends service_1.ServiceParameters {
43
30
  }
44
31
  }
45
32
  }
46
- exports.InvitationParameters = InvitationParameters;
47
33
  /**
48
34
  * Allow to use invitation on AclModel
49
35
  *
@@ -52,7 +38,7 @@ exports.InvitationParameters = InvitationParameters;
52
38
  *
53
39
  * @WebdaModda
54
40
  */
55
- class InvitationService extends service_1.Service {
41
+ export default class InvitationService extends Service {
56
42
  /**
57
43
  * @inheritdoc
58
44
  */
@@ -68,61 +54,56 @@ class InvitationService extends service_1.Service {
68
54
  this.authenticationService.on("Authentication.Register", (evt) => this.registrationListener(evt));
69
55
  const url = this.modelStore.getParameters().expose.url;
70
56
  this.addRoute(`${url}/{uuid}/invitations`, ["GET", "POST", "PUT", "DELETE"], this.invite);
57
+ return this;
71
58
  }
72
59
  /**
73
60
  * @inheritdoc
74
61
  */
75
- init() {
76
- const _super = Object.create(null, {
77
- init: { get: () => super.init }
78
- });
79
- return __awaiter(this, void 0, void 0, function* () {
80
- yield _super.init.call(this);
81
- if (this.parameters.notification &&
82
- !(yield this.notificationService.hasNotification(this.parameters.notification))) {
83
- throw new Error(`Email template should exist`);
84
- }
85
- });
62
+ async init() {
63
+ await super.init();
64
+ if (this.parameters.notification &&
65
+ !(await this.notificationService.hasNotification(this.parameters.notification))) {
66
+ throw new Error(`Email template should exist`);
67
+ }
68
+ return this;
86
69
  }
87
70
  /**
88
71
  * Accept or refuse for an invitation
89
72
  * @param ctx
90
73
  * @param model
91
74
  */
92
- answerInvitation(ctx, model) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- let body = yield ctx.getRequestBody();
95
- // Need to specify if you accept or not
96
- if (typeof body.accept !== "boolean") {
97
- throw 400;
98
- }
99
- // Invitation on the model is gone
100
- if (model === undefined) {
101
- yield this.removeInvitationFromUser(ctx.getCurrentUserId(), ctx.getParameters().uuid);
102
- throw 410;
103
- }
104
- const user = yield ctx.getCurrentUser();
105
- let metadata = undefined;
106
- user.getIdents().forEach(i => {
107
- if (model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`]) {
108
- metadata = model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`];
109
- delete model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`];
110
- }
111
- });
112
- if (model[this.parameters.pendingAttribute][`user_${user.getUuid()}`]) {
113
- metadata = model[this.parameters.pendingAttribute][`user_${user.getUuid()}`];
114
- delete model[this.parameters.pendingAttribute][`user_${user.getUuid()}`];
115
- }
116
- if (metadata && body.accept) {
117
- model[this.parameters.attribute][user.getUuid()] = metadata;
75
+ async answerInvitation(ctx, model) {
76
+ let body = await ctx.getRequestBody();
77
+ // Need to specify if you accept or not
78
+ if (typeof body.accept !== "boolean") {
79
+ throw 400;
80
+ }
81
+ // Invitation on the model is gone
82
+ if (model === undefined) {
83
+ await this.removeInvitationFromUser(ctx.getCurrentUserId(), ctx.getParameters().uuid);
84
+ throw 410;
85
+ }
86
+ const user = await ctx.getCurrentUser();
87
+ let metadata = undefined;
88
+ user.getIdents().forEach(i => {
89
+ if (model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`]) {
90
+ metadata = model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`];
91
+ delete model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`];
118
92
  }
119
- yield this.updateModel(model);
120
- this.emit("Invitation.Accepted", {
121
- metadata,
122
- model,
123
- context: ctx,
124
- accept: body.accept
125
- });
93
+ });
94
+ if (model[this.parameters.pendingAttribute][`user_${user.getUuid()}`]) {
95
+ metadata = model[this.parameters.pendingAttribute][`user_${user.getUuid()}`];
96
+ delete model[this.parameters.pendingAttribute][`user_${user.getUuid()}`];
97
+ }
98
+ if (metadata && body.accept) {
99
+ model[this.parameters.attribute][user.getUuid()] = metadata;
100
+ }
101
+ await this.updateModel(model);
102
+ this.emit("Invitation.Accepted", {
103
+ metadata,
104
+ model,
105
+ context: ctx,
106
+ accept: body.accept
126
107
  });
127
108
  }
128
109
  /**
@@ -130,12 +111,10 @@ class InvitationService extends service_1.Service {
130
111
  *
131
112
  * @param model
132
113
  */
133
- updateModel(model) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- yield model.update({
136
- [this.parameters.attribute]: model[this.parameters.attribute],
137
- [this.parameters.pendingAttribute]: model[this.parameters.pendingAttribute]
138
- });
114
+ async updateModel(model) {
115
+ await model.patch({
116
+ [this.parameters.attribute]: model[this.parameters.attribute],
117
+ [this.parameters.pendingAttribute]: model[this.parameters.pendingAttribute]
139
118
  });
140
119
  }
141
120
  /**
@@ -143,75 +122,70 @@ class InvitationService extends service_1.Service {
143
122
  * @param ctx
144
123
  * @param model
145
124
  */
146
- uninvite(ctx, model) {
147
- var _a, _b;
148
- return __awaiter(this, void 0, void 0, function* () {
149
- const body = yield ctx.getRequestBody();
150
- (_a = body.users) !== null && _a !== void 0 ? _a : (body.users = []);
151
- (_b = body.idents) !== null && _b !== void 0 ? _b : (body.idents = []);
152
- const promises = [];
153
- let invitedIdents = [];
154
- let invitedUsers = [];
155
- for (const ident of body.idents) {
156
- if (model[this.parameters.pendingAttribute][`ident_${ident}`]) {
157
- // Remove from pending on the object
158
- delete model[this.parameters.pendingAttribute][`ident_${ident}`];
159
- // Remove from pending from the invitation store
160
- promises.push(this.invitationStore.removeAttribute(`${ident}_${this.getName()}`, this.getInvitationAttribute(model.getUuid())));
161
- invitedIdents.push(ident);
162
- }
163
- else {
164
- // Remove user
165
- promises.push((() => __awaiter(this, void 0, void 0, function* () {
166
- const id = yield this.authenticationService.getIdentStore().get(ident);
167
- if (id && id.getUser()) {
168
- delete model[this.parameters.attribute][id.getUser()];
169
- yield this.removeInvitationFromUser(id.getUser(), model.getUuid());
170
- invitedUsers.push(id.getUser());
171
- }
172
- }))());
173
- }
125
+ async uninvite(ctx, model) {
126
+ const body = await ctx.getRequestBody();
127
+ body.users ?? (body.users = []);
128
+ body.idents ?? (body.idents = []);
129
+ const promises = [];
130
+ let invitedIdents = [];
131
+ let invitedUsers = [];
132
+ for (const ident of body.idents) {
133
+ if (model[this.parameters.pendingAttribute][`ident_${ident}`]) {
134
+ // Remove from pending on the object
135
+ delete model[this.parameters.pendingAttribute][`ident_${ident}`];
136
+ // Remove from pending from the invitation store
137
+ promises.push(this.invitationStore.removeAttribute(`${ident}_${this.getName()}`, this.getInvitationAttribute(model.getUuid())));
138
+ invitedIdents.push(ident);
174
139
  }
175
- for (const user of body.users) {
176
- if (model[this.parameters.pendingAttribute][`user_${user}`]) {
177
- delete model[this.parameters.pendingAttribute][`user_${user}`];
178
- }
179
- else if (model[this.parameters.attribute][user]) {
180
- delete model[this.parameters.attribute][user];
181
- }
182
- promises.push(this.removeInvitationFromUser(user, model.getUuid()));
183
- invitedUsers.push(user);
140
+ else {
141
+ // Remove user
142
+ promises.push((async () => {
143
+ const id = await this.authenticationService.getIdentStore().get(ident);
144
+ if (id && id.getUser()) {
145
+ delete model[this.parameters.attribute][id.getUser()];
146
+ await this.removeInvitationFromUser(id.getUser(), model.getUuid());
147
+ invitedUsers.push(id.getUser());
148
+ }
149
+ })());
184
150
  }
185
- yield Promise.all(promises);
186
- //
187
- yield this.updateModel(model);
188
- this.emit("Invitation.Removed", {
189
- metadata: body.metadata,
190
- users: invitedUsers,
191
- idents: invitedIdents,
192
- model,
193
- context: ctx
194
- });
151
+ }
152
+ for (const user of body.users) {
153
+ if (model[this.parameters.pendingAttribute][`user_${user}`]) {
154
+ delete model[this.parameters.pendingAttribute][`user_${user}`];
155
+ }
156
+ else if (model[this.parameters.attribute][user]) {
157
+ delete model[this.parameters.attribute][user];
158
+ }
159
+ promises.push(this.removeInvitationFromUser(user, model.getUuid()));
160
+ invitedUsers.push(user);
161
+ }
162
+ await Promise.all(promises);
163
+ //
164
+ await this.updateModel(model);
165
+ this.emit("Invitation.Removed", {
166
+ metadata: body.metadata,
167
+ users: invitedUsers,
168
+ idents: invitedIdents,
169
+ model,
170
+ context: ctx
195
171
  });
196
172
  }
197
173
  /**
198
174
  * Remove a model invitation from user
199
175
  * @param user
200
176
  */
201
- removeInvitationFromUser(user, model) {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- let userModel = yield this.authenticationService.getUserStore().get(user);
204
- let index = 0;
205
- for (let invit of userModel[this.parameters.mapAttribute] || []) {
206
- if (invit.model === model) {
207
- yield this.authenticationService
208
- .getUserStore()
209
- .deleteItemFromCollection(user, this.parameters.mapAttribute, index, model, "model");
210
- return;
211
- }
212
- index++;
177
+ async removeInvitationFromUser(user, model) {
178
+ let userModel = await this.authenticationService.getUserStore().get(user);
179
+ let index = 0;
180
+ for (let invit of userModel[this.parameters.mapAttribute] || []) {
181
+ if (invit.model === model) {
182
+ await this.authenticationService
183
+ .getUserStore()
184
+ .deleteItemFromCollection(user, this.parameters.mapAttribute, index, model, "model");
185
+ return;
213
186
  }
214
- });
187
+ index++;
188
+ }
215
189
  }
216
190
  /**
217
191
  * Handle invitations all methods
@@ -219,152 +193,143 @@ class InvitationService extends service_1.Service {
219
193
  * @param ctx
220
194
  * @returns
221
195
  */
222
- invite(ctx) {
223
- var _a, _b, _c, _d;
224
- var _e, _f, _g;
225
- return __awaiter(this, void 0, void 0, function* () {
226
- let model = yield this.modelStore.get(ctx.getParameters().uuid);
227
- if (ctx.getHttpContext().getMethod() === "PUT") {
228
- return this.answerInvitation(ctx, model);
229
- }
230
- let inviter = yield ctx.getCurrentUser();
231
- if (!model) {
232
- throw 404;
233
- }
234
- (_a = model[_e = this.parameters.attribute]) !== null && _a !== void 0 ? _a : (model[_e] = {});
235
- (_b = model[_f = this.parameters.pendingAttribute]) !== null && _b !== void 0 ? _b : (model[_f] = {});
236
- if (ctx.getHttpContext().getMethod() === "DELETE") {
237
- yield model.canAct(ctx, "uninvite");
238
- return this.uninvite(ctx, model);
239
- }
240
- yield model.canAct(ctx, "invite");
241
- // Retrieve invitation useful when invitation are hidden with a __
242
- if (ctx.getHttpContext().getMethod() === "GET") {
243
- ctx.write(model[this.parameters.pendingAttribute] || {});
244
- return;
245
- }
246
- const body = yield ctx.getRequestBody();
247
- // For each ident
248
- const identsStore = this.authenticationService.getIdentStore();
249
- // Load all idents with orignal
250
- const invitations = yield Promise.all((body.idents || []).map((i) => __awaiter(this, void 0, void 0, function* () {
251
- return ({
252
- ident: yield identsStore.get(i),
253
- invitation: i
254
- });
255
- })));
256
- let invitedIdents = [];
257
- let invitedUsers = [];
258
- let promises = [];
259
- const metadata = {};
260
- this.parameters.mapFields.forEach(f => (metadata[f] = model[f]));
261
- for (const invitation of invitations) {
262
- // User is known
263
- if (invitation.ident) {
264
- if (this.parameters.autoAccept) {
265
- model[this.parameters.attribute][invitation.ident.getUser()] = body.metadata;
266
- }
267
- else if (!model[this.parameters.attribute][invitation.ident.getUser()]) {
268
- // Add to the user
269
- model[this.parameters.pendingAttribute][`user_${invitation.ident.getUser()}`] = body.metadata;
270
- }
271
- promises.push((() => __awaiter(this, void 0, void 0, function* () {
272
- const user = yield this.authenticationService.getUserStore().get(invitation.ident.getUser());
273
- invitedUsers.push(user);
274
- yield this.addInvitationToUser(model, user, inviter, metadata, body.notification);
275
- }))());
276
- continue;
277
- }
278
- // User is unknown to the platform
279
- invitedIdents.push(invitation.invitation);
280
- let invitUuid = `${invitation.invitation}_${this.getName()}`;
281
- (_c = model[_g = this.parameters.pendingAttribute]) !== null && _c !== void 0 ? _c : (model[_g] = {});
282
- model[this.parameters.pendingAttribute][`ident_${invitation.invitation}`] = body.metadata;
283
- const invitInfo = {
284
- inviter: inviter.toPublicEntry(),
285
- metadata: body.metadata
286
- };
287
- if (yield this.invitationStore.exists(invitUuid)) {
288
- promises.push(this.invitationStore.setAttribute(invitUuid, this.getInvitationAttribute(model.getUuid()), invitInfo));
289
- }
290
- else {
291
- promises.push(this.invitationStore.save({
292
- uuid: invitUuid,
293
- [this.getInvitationAttribute(model.getUuid())]: invitInfo
294
- }));
295
- }
296
- // Notify ident
297
- let ident = invitation.invitation.split("_");
298
- yield this.sendNotification(index_1.Ident.init(ident.pop(), ident.join("_")), {
299
- model,
300
- metadata,
301
- notification: body.notification,
302
- inviter: inviter.toPublicEntry(),
303
- pending: !this.parameters.autoAccept,
304
- registered: true
305
- });
306
- }
307
- // Check user direct invite
308
- (_d = body.users) !== null && _d !== void 0 ? _d : (body.users = []);
309
- promises.push(...body.users.map((u) => __awaiter(this, void 0, void 0, function* () {
310
- let user = yield this.authenticationService.getUserStore().get(u);
311
- if (!user) {
312
- return;
313
- }
196
+ async invite(ctx) {
197
+ var _a, _b, _c;
198
+ let model = await this.modelStore.get(ctx.getParameters().uuid);
199
+ if (ctx.getHttpContext().getMethod() === "PUT") {
200
+ return this.answerInvitation(ctx, model);
201
+ }
202
+ let inviter = await ctx.getCurrentUser();
203
+ if (!model) {
204
+ throw 404;
205
+ }
206
+ model[_a = this.parameters.attribute] ?? (model[_a] = {});
207
+ model[_b = this.parameters.pendingAttribute] ?? (model[_b] = {});
208
+ if (ctx.getHttpContext().getMethod() === "DELETE") {
209
+ await model.canAct(ctx, "uninvite");
210
+ return this.uninvite(ctx, model);
211
+ }
212
+ await model.canAct(ctx, "invite");
213
+ // Retrieve invitation useful when invitation are hidden with a __
214
+ if (ctx.getHttpContext().getMethod() === "GET") {
215
+ ctx.write(model[this.parameters.pendingAttribute] || {});
216
+ return;
217
+ }
218
+ const body = await ctx.getRequestBody();
219
+ // For each ident
220
+ const identsStore = this.authenticationService.getIdentStore();
221
+ // Load all idents with orignal
222
+ const invitations = await Promise.all((body.idents || []).map(async (i) => ({
223
+ ident: await identsStore.get(i),
224
+ invitation: i
225
+ })));
226
+ let invitedIdents = [];
227
+ let invitedUsers = [];
228
+ let promises = [];
229
+ const metadata = {};
230
+ this.parameters.mapFields.forEach(f => (metadata[f] = model[f]));
231
+ for (const invitation of invitations) {
232
+ // User is known
233
+ if (invitation.ident) {
314
234
  if (this.parameters.autoAccept) {
315
- model[this.parameters.attribute][u] = body.metadata;
235
+ model[this.parameters.attribute][invitation.ident.getUser()] = body.metadata;
316
236
  }
317
- else if (!model[this.parameters.attribute][u]) {
318
- model[this.parameters.pendingAttribute][`user_${u}`] = body.metadata;
237
+ else if (!model[this.parameters.attribute][invitation.ident.getUser()]) {
238
+ // Add to the user
239
+ model[this.parameters.pendingAttribute][`user_${invitation.ident.getUser()}`] = body.metadata;
319
240
  }
320
- invitedUsers.push(user);
321
- yield this.addInvitationToUser(model, user, inviter, metadata, body.notification);
322
- })));
323
- yield Promise.all(promises);
324
- // Update model now
325
- yield this.updateModel(model);
326
- this.emit("Invitation.Sent", {
327
- metadata: body.metadata,
328
- notification: body.notification,
329
- users: invitedUsers,
330
- idents: invitedIdents,
331
- model,
332
- context: ctx
333
- });
334
- });
335
- }
336
- addInvitationToUser(model, user, inviter, metadata, notification = {}) {
337
- return __awaiter(this, void 0, void 0, function* () {
338
- if ((user[this.parameters.mapAttribute] || []).filter(p => p.model === model.getUuid()).length) {
339
- return;
241
+ promises.push((async () => {
242
+ const user = await this.authenticationService.getUserStore().get(invitation.ident.getUser());
243
+ invitedUsers.push(user);
244
+ await this.addInvitationToUser(model, user, inviter, metadata, body.notification);
245
+ })());
246
+ continue;
340
247
  }
341
- yield this.authenticationService
342
- .getUserStore()
343
- .upsertItemToCollection(user.getUuid(), this.parameters.mapAttribute, {
344
- model: model.getUuid(),
345
- metadata,
248
+ // User is unknown to the platform
249
+ invitedIdents.push(invitation.invitation);
250
+ let invitUuid = `${invitation.invitation}_${this.getName()}`;
251
+ model[_c = this.parameters.pendingAttribute] ?? (model[_c] = {});
252
+ model[this.parameters.pendingAttribute][`ident_${invitation.invitation}`] = body.metadata;
253
+ const invitInfo = {
346
254
  inviter: inviter.toPublicEntry(),
347
- pending: !this.parameters.autoAccept
348
- });
349
- // Notify user
350
- yield this.sendNotification(user, {
255
+ metadata: body.metadata
256
+ };
257
+ if (await this.invitationStore.exists(invitUuid)) {
258
+ promises.push(this.invitationStore.setAttribute(invitUuid, this.getInvitationAttribute(model.getUuid()), invitInfo));
259
+ }
260
+ else {
261
+ promises.push(this.invitationStore.save({
262
+ uuid: invitUuid,
263
+ [this.getInvitationAttribute(model.getUuid())]: invitInfo
264
+ }));
265
+ }
266
+ // Notify ident
267
+ let ident = invitation.invitation.split("_");
268
+ await this.sendNotification(Ident.init(ident.pop(), ident.join("_")), {
351
269
  model,
352
270
  metadata,
353
- notification,
271
+ notification: body.notification,
354
272
  inviter: inviter.toPublicEntry(),
355
273
  pending: !this.parameters.autoAccept,
356
274
  registered: true
357
275
  });
358
- });
359
- }
360
- sendNotification(user, replacements) {
361
- return __awaiter(this, void 0, void 0, function* () {
362
- if (!this.parameters.notification) {
276
+ }
277
+ // Check user direct invite
278
+ body.users ?? (body.users = []);
279
+ promises.push(...body.users.map(async (u) => {
280
+ let user = await this.authenticationService.getUserStore().get(u);
281
+ if (!user) {
363
282
  return;
364
283
  }
365
- yield this.notificationService.sendNotification(user, this.parameters.notification, replacements);
284
+ if (this.parameters.autoAccept) {
285
+ model[this.parameters.attribute][u] = body.metadata;
286
+ }
287
+ else if (!model[this.parameters.attribute][u]) {
288
+ model[this.parameters.pendingAttribute][`user_${u}`] = body.metadata;
289
+ }
290
+ invitedUsers.push(user);
291
+ await this.addInvitationToUser(model, user, inviter, metadata, body.notification);
292
+ }));
293
+ await Promise.all(promises);
294
+ // Update model now
295
+ await this.updateModel(model);
296
+ this.emit("Invitation.Sent", {
297
+ metadata: body.metadata,
298
+ notification: body.notification,
299
+ users: invitedUsers,
300
+ idents: invitedIdents,
301
+ model,
302
+ context: ctx
366
303
  });
367
304
  }
305
+ async addInvitationToUser(model, user, inviter, metadata, notification = {}) {
306
+ if ((user[this.parameters.mapAttribute] || []).filter(p => p.model === model.getUuid()).length) {
307
+ return;
308
+ }
309
+ await this.authenticationService
310
+ .getUserStore()
311
+ .upsertItemToCollection(user.getUuid(), this.parameters.mapAttribute, {
312
+ model: model.getUuid(),
313
+ metadata,
314
+ inviter: inviter.toPublicEntry(),
315
+ pending: !this.parameters.autoAccept
316
+ });
317
+ // Notify user
318
+ await this.sendNotification(user, {
319
+ model,
320
+ metadata,
321
+ notification,
322
+ inviter: inviter.toPublicEntry(),
323
+ pending: !this.parameters.autoAccept,
324
+ registered: true
325
+ });
326
+ }
327
+ async sendNotification(user, replacements) {
328
+ if (!this.parameters.notification) {
329
+ return;
330
+ }
331
+ await this.notificationService.sendNotification(user, this.parameters.notification, replacements);
332
+ }
368
333
  /**
369
334
  * Return which attribute would be used to store the invitation on ident invitation object
370
335
  * @param uuid
@@ -379,66 +344,63 @@ class InvitationService extends service_1.Service {
379
344
  * @param evt
380
345
  * @returns
381
346
  */
382
- registrationListener(evt) {
383
- var _a;
384
- var _b, _c;
385
- return __awaiter(this, void 0, void 0, function* () {
386
- let uuid = `${evt.identId}_${this.getName()}`;
387
- const invitations = yield this.invitationStore.get(uuid);
388
- if (!invitations) {
389
- return;
390
- }
391
- this.log("DEBUG", `Resolving invitation for ident ${evt.identId}`);
392
- // Load all models invited too
393
- const infos = yield Promise.all(Object.keys(invitations)
394
- .filter(k => k.startsWith("invit_"))
395
- .map((k) => __awaiter(this, void 0, void 0, function* () {
396
- return (Object.assign(Object.assign({}, invitations[k]), { model: yield this.modelStore.get(k.substring(6)) }));
397
- })));
398
- // autoAccept is on so move to __acls
399
- const promises = [];
400
- // If autoAccept is false, just copy the pending invitation in the user
401
- (_a = (_b = evt.user)[_c = this.parameters.mapAttribute]) !== null && _a !== void 0 ? _a : (_b[_c] = []);
402
- evt.user[this.parameters.mapAttribute].push(...infos
403
- .filter(m => m.model !== undefined)
404
- .map(m => {
405
- const metadata = {};
406
- this.parameters.mapFields.forEach(f => (metadata[f] = m.model[f]));
407
- return {
408
- model: m.model.getUuid(),
409
- metadata,
410
- inviter: m.inviter,
411
- pending: !this.parameters.autoAccept
412
- };
413
- }));
414
- if (this.parameters.autoAccept) {
415
- for (const info of infos) {
416
- if (!info.model) {
417
- continue;
418
- }
419
- // Set the metadata
420
- info.model[this.parameters.attribute][evt.user.getUuid()] = info.metadata;
421
- // Remove pending
422
- delete info.model[this.parameters.pendingAttribute][`ident_${evt.identId}`];
423
- promises.push(this.updateModel(info.model));
347
+ async registrationListener(evt) {
348
+ var _a, _b;
349
+ let uuid = `${evt.identId}_${this.getName()}`;
350
+ const invitations = await this.invitationStore.get(uuid);
351
+ if (!invitations) {
352
+ return;
353
+ }
354
+ this.log("DEBUG", `Resolving invitation for ident ${evt.identId}`);
355
+ // Load all models invited too
356
+ const infos = await Promise.all(Object.keys(invitations)
357
+ .filter(k => k.startsWith("invit_"))
358
+ .map(async (k) => ({
359
+ ...invitations[k],
360
+ model: await this.modelStore.get(k.substring(6))
361
+ })));
362
+ // autoAccept is on so move to __acls
363
+ const promises = [];
364
+ // If autoAccept is false, just copy the pending invitation in the user
365
+ (_a = evt.user)[_b = this.parameters.mapAttribute] ?? (_a[_b] = []);
366
+ evt.user[this.parameters.mapAttribute].push(...infos
367
+ .filter(m => m.model !== undefined)
368
+ .map(m => {
369
+ const metadata = {};
370
+ this.parameters.mapFields.forEach(f => (metadata[f] = m.model[f]));
371
+ return {
372
+ model: m.model.getUuid(),
373
+ metadata,
374
+ inviter: m.inviter,
375
+ pending: !this.parameters.autoAccept
376
+ };
377
+ }));
378
+ if (this.parameters.autoAccept) {
379
+ for (const info of infos) {
380
+ if (!info.model) {
381
+ continue;
424
382
  }
383
+ // Set the metadata
384
+ info.model[this.parameters.attribute][evt.user.getUuid()] = info.metadata;
385
+ // Remove pending
386
+ delete info.model[this.parameters.pendingAttribute][`ident_${evt.identId}`];
387
+ promises.push(this.updateModel(info.model));
425
388
  }
426
- promises.push(invitations.delete());
427
- yield Promise.all(promises);
428
- });
389
+ }
390
+ promises.push(invitations.delete());
391
+ await Promise.all(promises);
429
392
  }
430
393
  }
431
394
  __decorate([
432
- (0, service_1.Inject)("params:authenticationService")
395
+ Inject("params:authenticationService")
433
396
  ], InvitationService.prototype, "authenticationService", void 0);
434
397
  __decorate([
435
- (0, service_1.Inject)("params:notificationService", true)
398
+ Inject("params:notificationService", true)
436
399
  ], InvitationService.prototype, "notificationService", void 0);
437
400
  __decorate([
438
- (0, service_1.Inject)("params:invitationStore")
401
+ Inject("params:invitationStore")
439
402
  ], InvitationService.prototype, "invitationStore", void 0);
440
403
  __decorate([
441
- (0, service_1.Inject)("params:modelStore")
404
+ Inject("params:modelStore")
442
405
  ], InvitationService.prototype, "modelStore", void 0);
443
- exports.default = InvitationService;
444
406
  //# sourceMappingURL=invitationservice.js.map